aboutsummaryrefslogtreecommitdiff
path: root/Northstar.Custom/mod/scripts/vscripts/gamemodes/_gamemode_sns.gnut
blob: 812c21ee62c3695dd9cb3bdd2c1f64300fdce229 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
global function SNS_Init

struct {
	string score_leader_highlight = "enemy_boss_bounty" // highlight effect applied to person in 1st place
	string offhand_weapon = "mp_weapon_thermite_grenade" // offhand weapon

	bool reset_pulse_blade_cooldown_on_pulse_blade_kill
	bool softball_enabled

	int wme_kill_value
	int softball_kill_value
	int offhand_kill_value
	int reset_kill_value
	int melee_kill_value
} file


void function SNS_Init()
{
	SetSpawnpointGamemodeOverride( FFA )
	SetShouldUseRoundWinningKillReplay( true )
	ClassicMP_ForceDisableEpilogue( true )
	SetLoadoutGracePeriodEnabled( false ) // prevent modifying loadouts with grace period
	SetWeaponDropsEnabled( false )
	Riff_ForceTitanAvailability( eTitanAvailability.Never )
	Riff_ForceBoostAvailability( eBoostAvailability.Disabled )

	AddCallback_OnPlayerKilled( OnPlayerKilled )
	AddCallback_OnPlayerRespawned( OnPlayerRespawned )
	AddCallback_OnClientDisconnected(OnPlayerDisconnected)
	AddCallback_GameStateEnter( eGameState.WinnerDetermined, OnWinnerDetermined )

	file.reset_pulse_blade_cooldown_on_pulse_blade_kill = GetCurrentPlaylistVarInt( "sns_reset_pulse_blade_cooldown_on_pulse_blade_kill", 1 ) == 1
	file.softball_enabled = GetCurrentPlaylistVarInt( "sns_softball_enabled", 0 ) == 1
	file.wme_kill_value = GetCurrentPlaylistVarInt( "sns_wme_kill_value", 10 )
	file.softball_kill_value = GetCurrentPlaylistVarInt( "sns_softball_kill_value", 10 )
	file.offhand_kill_value = GetCurrentPlaylistVarInt( "sns_offhand_kill_value", 10 )
	file.reset_kill_value = GetCurrentPlaylistVarInt( "sns_reset_kill_value", 5 )
	file.melee_kill_value = GetCurrentPlaylistVarInt( "sns_melee_kill_value", 5 )
}

void function OnPlayerDisconnected(entity player)
{
	if (GetWinningPlayer() == player)
		thread CheckNewHighlight(player)
}

void function CheckNewHighlight(entity player) 
{
	while (IsValid(player)) //wait till disconnected player not exist
		wait 0.25
	
	entity winner = GetWinningPlayer()
	if (IsValid(winner))
		SetHighlight(winner)
}

void function OnPlayerKilled( entity victim, entity attacker, var damageInfo )
{
	if ( victim != attacker && victim.IsPlayer() && attacker.IsPlayer() && GetGameState() == eGameState.Playing )
	{
		SetRoundWinningKillReplayAttacker(attacker)
		if ( DamageInfo_GetDamageSourceIdentifier( damageInfo ) == eDamageSourceId.mp_weapon_grenade_sonar || DamageInfo_GetDamageSourceIdentifier( damageInfo ) == eDamageSourceId.human_execution)
		{
			if (victim == GetWinningPlayer()) 
			{
				foreach ( entity otherPlayer in GetPlayerArray() ) 
				{
					if (otherPlayer == victim)
						continue
					Remote_CallFunction_NonReplay( otherPlayer, "ServerCallback_AnnounceKillLeaderBankrupt", victim.GetEncodedEHandle(), attacker.GetEncodedEHandle() )
				}
			}
			if (file.reset_pulse_blade_cooldown_on_pulse_blade_kill) 
			{
				attacker.TakeWeaponNow( "mp_weapon_grenade_sonar" ) // resets cooldown if you kill with it
				attacker.GiveOffhandWeapon( "mp_weapon_grenade_sonar", OFFHAND_LEFT )
			}
			
			EmitSoundOnEntityOnlyToPlayer( attacker, attacker, "UI_CTF_3P_TeamGrabFlag" )
			bankrupt(victim, attacker)

			AddTeamScore( attacker.GetTeam(), file.reset_kill_value )
			attacker.AddToPlayerGameStat( PGS_ASSAULT_SCORE, file.reset_kill_value )
			attacker.AddToPlayerGameStat( PGS_TITAN_KILLS, 1 )
		} 
		else if ( DamageInfo_GetDamageSourceIdentifier( damageInfo ) == eDamageSourceId.melee_pilot_emptyhanded ) 
		{
			AddTeamScore( attacker.GetTeam(), file.melee_kill_value )
			attacker.AddToPlayerGameStat( PGS_ASSAULT_SCORE, file.melee_kill_value )
		} 
		else if ( DamageInfo_GetDamageSourceIdentifier( damageInfo ) == eDamageSourceId.mp_weapon_wingman_n ) 
		{
			AddTeamScore( attacker.GetTeam(), file.wme_kill_value )
			attacker.AddToPlayerGameStat( PGS_ASSAULT_SCORE, file.wme_kill_value )
		}
		else if ( DamageInfo_GetDamageSourceIdentifier( damageInfo ) == eDamageSourceId.mp_weapon_softball ) 
		{
			AddTeamScore( attacker.GetTeam(), file.softball_kill_value )
			attacker.AddToPlayerGameStat( PGS_ASSAULT_SCORE, file.softball_kill_value )
		}
		else 
		{
			AddTeamScore( attacker.GetTeam(), file.offhand_kill_value )
			attacker.AddToPlayerGameStat( PGS_ASSAULT_SCORE, file.offhand_kill_value )
		}

		if (attacker == GetWinningPlayer())
			SetHighlight( attacker )
	}
}

void function bankrupt(entity player, entity attacker) {
	while (GameRules_GetTeamScore(player.GetTeam()) > 0) {
		AddTeamScore( player.GetTeam(), -1 )
	}
	player.SetPlayerGameStat( PGS_ASSAULT_SCORE, 0)

	Remote_CallFunction_NonReplay( player , "ServerCallback_AnnounceBankrupt", attacker.GetEncodedEHandle() )
	EmitSoundOnEntityOnlyToPlayer( player, player, "UI_InGame_MarkedForDeath_PlayerMarked" )
}

void function OnWinnerDetermined()
{
	SetRespawnsEnabled( false )
	SetKillcamsEnabled( false )
}

void function OnPlayerRespawned( entity player )
{
	foreach ( entity weapon in player.GetMainWeapons() )
		player.TakeWeaponNow( weapon.GetWeaponClassName() )
	
	foreach ( entity weapon in player.GetOffhandWeapons() )
		player.TakeWeaponNow( weapon.GetWeaponClassName() )
	
	array<string> mods = ["sns", "pas_fast_ads", "tactical_cdr_on_kill", "pas_run_and_gun", "pas_fast_swap"]
	player.GiveWeapon( "mp_weapon_wingman_n", mods)
	if (file.softball_enabled) {
		mods.append("jump_kit") // the funny
		player.GiveWeapon( "mp_weapon_softball", mods)
	}
	player.GiveOffhandWeapon( "melee_pilot_emptyhanded", OFFHAND_MELEE )
	player.GiveOffhandWeapon( file.offhand_weapon, OFFHAND_RIGHT )
	player.GiveOffhandWeapon( "mp_weapon_grenade_sonar", OFFHAND_LEFT )

	if (player == GetWinningPlayer())
		SetHighlight( player )

	thread OnPlayerRespawned_Threaded( player )
}

void function OnPlayerRespawned_Threaded( entity player )
{
	// bit of a hack, need to rework earnmeter code to have better support for completely disabling it
	// rn though this just waits for earnmeter code to set the mode before we set it back
	WaitFrame()
	if ( IsValid( player ) )
		PlayerEarnMeter_SetMode( player, eEarnMeterMode.DISABLED )
}

entity function GetWinningPlayer() 
{
	entity bestplayer

	foreach ( entity player in GetPlayerArray() ) {
		if (bestplayer == null)
			bestplayer = player
		
		if (GameRules_GetTeamScore(player.GetTeam()) > GameRules_GetTeamScore(bestplayer.GetTeam()))
			bestplayer = player
	}

	return bestplayer
}

void function SetHighlight(entity player) {
	foreach ( entity player in GetPlayerArray() )
		Highlight_ClearEnemyHighlight(player)
	Highlight_SetEnemyHighlight( player, file.score_leader_highlight )
}