aboutsummaryrefslogtreecommitdiff
path: root/Northstar.Custom/mod/scripts/vscripts/gamemodes/gg_earn_meter/_gg_earn_meter.gnut
blob: 1d4e73b73666113d61bd0b9cefa12d6d4694c590 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
global function Sv_GGEarnMeter_SetWeaponIcon
global function Sv_GGEarnMeter_SetFinalIcon
global function Sv_GGEarnMeter_SetPercentage
global function Sv_GGEarnMeter_AddPercentage
global function AddCallback_GGEarnMeterFull

struct
{
	array< bool functionref( entity ) > onGGEarnMeterFullCallbacks
} file

void function Sv_GGEarnMeter_SetWeaponIcon( entity player, string weaponReference )
{
	Remote_CallFunction_Replay( player, "ServerCallback_GGEarnMeter_SetWeaponIcon", eDamageSourceId[weaponReference] )
}

void function Sv_GGEarnMeter_SetFinalIcon( entity player )
{
	Remote_CallFunction_Replay( player, "ServerCallback_GGEarnMeter_SetWeaponIcon", -1 )
}

void function Sv_GGEarnMeter_SetPercentage( entity player, float percentage )
{
	player.SetPlayerNetFloat( "gunGameLevelPercentage", clamp(percentage, 0.0, 1.0) )

	thread CheckPercentage( player )
}

void function Sv_GGEarnMeter_AddPercentage( entity player, float percentage )
{
	Sv_GGEarnMeter_SetPercentage(player, player.GetPlayerNetFloat( "gunGameLevelPercentage") + percentage)
}

void function AddCallback_GGEarnMeterFull( bool functionref( entity ) callbackFunc )
{
	Assert( !file.onGGEarnMeterFullCallbacks.contains( callbackFunc ), "Already added " + FunctionToString( callbackFunc ) + " with AddCallback_GGEarnMeterFull" )

	file.onGGEarnMeterFullCallbacks.append( callbackFunc )
}

void function CheckPercentage( entity player )
{
	float percentage = player.GetPlayerNetFloat( "gunGameLevelPercentage")

	if ( percentage < 1.0 )
		return

	wait 0.2

	bool lastWeapon = false
	foreach ( callbackFunc in file.onGGEarnMeterFullCallbacks )
		lastWeapon = callbackFunc( player )

	if ( !lastWeapon )
		Sv_GGEarnMeter_SetPercentage(player, 0.0)
}