aboutsummaryrefslogtreecommitdiff
path: root/Northstar.Custom/mod/scripts/vscripts/gamemodes/_gamemode_gg.gnut
blob: 608fd869e770e13d272988d8e862596f8713e7e9 (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
global function GamemodeGG_Init

void function GamemodeGG_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_OnPlayerRespawned( OnPlayerRespawned )
	AddCallback_OnPlayerKilled( OnPlayerKilled )
	
	AddCallback_GameStateEnter( eGameState.WinnerDetermined, OnWinnerDetermined )
	
	// set scorelimit if it's wrong, sort of a jank way to do it but best i've got rn
	try
	{
		if ( GetCurrentPlaylistVarInt( "scorelimit", GetGunGameWeapons().len() ) != GetGunGameWeapons().len() )
			SetPlaylistVarOverride( "scorelimit", GetGunGameWeapons().len().tostring() )
	}
	catch ( ex ) {}
}

void function OnPlayerRespawned( entity player )
{
	UpdateLoadout( 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 )
}

void function OnPlayerKilled( entity victim, entity attacker, var damageInfo )
{
	if ( !victim.IsPlayer() || !attacker.IsPlayer() || GetGameState() != eGameState.Playing )
		return
		
	if ( attacker == victim ) // suicide
	{
		string message = victim.GetPlayerName() + " committed suicide."
		foreach ( entity player in GetPlayerArray() )
			SendHudMessage( player, message, -1, 0.4, 255, 0, 0, 0, 0, 3, 0.15 )
			
		if ( GameRules_GetTeamScore( victim.GetTeam() ) != 0 )
		{
			AddTeamScore( victim.GetTeam(), -1 ) // get absolutely fucking destroyed lol
			victim.AddToPlayerGameStat( PGS_ASSAULT_SCORE, -1 )
		}
	}
	else 
	{
		if ( DamageInfo_GetDamageSourceIdentifier( damageInfo ) != eDamageSourceId.melee_pilot_emptyhanded )
		{
			AddTeamScore( attacker.GetTeam(), 1 )
			attacker.AddToPlayerGameStat( PGS_ASSAULT_SCORE, 1 )
			UpdateLoadout( attacker )
		}
		
		if ( DamageInfo_GetDamageSourceIdentifier( damageInfo ) == eDamageSourceId.human_execution )
		{
			string message = victim.GetPlayerName() + " got executed."
			foreach ( entity player in GetPlayerArray() )
				SendHudMessage( player, message, -1, 0.4, 255, 0, 0, 0, 0, 3, 0.15 )
		
			if ( GameRules_GetTeamScore( victim.GetTeam() ) != 0 )
			{
				AddTeamScore( victim.GetTeam(), -1 ) // get absolutely fucking destroyed lol
				victim.AddToPlayerGameStat( PGS_ASSAULT_SCORE, -1 )
			}
		}
	}
}

void function UpdateLoadout( entity player )
{
	// todo: honestly, this should be reworked to use PilotLoadoutDefs instead of directly modifying weapons and shit
	
	int currentWeaponIndex = GameRules_GetTeamScore( player.GetTeam() )
	array<GunGameWeapon> weapons = GetGunGameWeapons()
	
	if ( currentWeaponIndex >= weapons.len() )
		currentWeaponIndex = weapons.len() - 1
		
	if ( currentWeaponIndex > 18 ) // play end of game music for special weapons
		PlayMusicToAll( eMusicPieceID.LEVEL_LAST_MINUTE ) // this *shouldn't* overlap if done multiple times
	
	GunGameWeapon weapon = weapons[ currentWeaponIndex ]
	
	foreach ( entity weapon in player.GetMainWeapons() )
		player.TakeWeaponNow( weapon.GetWeaponClassName() )
	
	foreach ( entity weapon in player.GetOffhandWeapons() )
		player.TakeWeaponNow( weapon.GetWeaponClassName() )
	
	if ( weapon.offhandSlot != -1 )
	{
		// TEMP: give archer so player so player has a weapon which lets them use offhands
		// need to replace this with a custom empty weapon at some point
		player.GiveWeapon( "mp_weapon_rocket_launcher" )
		
		player.GiveOffhandWeapon( weapon.weapon, weapon.offhandSlot, weapon.mods )
	}
	else
		player.GiveWeapon( weapon.weapon, weapon.mods )
		
	player.GiveOffhandWeapon( "melee_pilot_emptyhanded", OFFHAND_MELEE )
}

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