aboutsummaryrefslogtreecommitdiff
path: root/Northstar.Custom/mod/scripts/vscripts/gamemodes/_gamemode_kr.gnut
blob: 67ace6954546123d59ed3f7c2ea8784fa09dbc1f (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
global function GamemodeKR_Init

struct {
	float currentHighestKillraceAmount
	int currentKillraceScore
	entity currentRacer
	array<vector> flagSpawnPoints
} file

void function GamemodeKR_Init()
{
	PrecacheModel( CTF_FLAG_MODEL )

	SetSpawnpointGamemodeOverride( FFA )
	
	ClassicMP_ForceDisableEpilogue( true )
	Riff_ForceTitanAvailability( eTitanAvailability.Never )
	Riff_ForceBoostAvailability( eBoostAvailability.Disabled )
	ScoreEvent_SetupEarnMeterValuesForMixedModes()
	
	AddSpawnCallback( "info_hardpoint", AddFlagSpawnPoint )
	
	AddCallback_OnPlayerKilled( OnPlayerKilled )
	AddCallback_OnTouchHealthKit( "item_flag", StartPlayerKillrace )
	
	AddCallback_GameStateEnter( eGameState.Playing, StartKillraceSpawnThink )
}

void function AddFlagSpawnPoint( entity hardpoint )
{
	if ( hardpoint.HasKey( "hardpointGroup" ) && ( hardpoint.kv.hardpointGroup == "A" || hardpoint.kv.hardpointGroup == "B" || hardpoint.kv.hardpointGroup == "C" ) )
		file.flagSpawnPoints.append( hardpoint.GetOrigin() )
}

void function OnPlayerKilled( entity victim, entity attacker, var damageInfo )
{
	if ( !victim.IsPlayer() || !attacker.IsPlayer() || attacker == victim )	
		return
	
	float killRaceTime = attacker.GetPlayerNetTime( "killRaceTime" ) + 5.0
	attacker.SetPlayerNetTime( "killRaceTime", killRaceTime )
	if ( killRaceTime > file.currentHighestKillraceAmount )
		file.currentHighestKillraceAmount = killRaceTime
	if ( file.currentRacer != null && attacker == file.currentRacer )
		file.currentKillraceScore++
}

bool function StartPlayerKillrace( entity player, entity flag )
{
	float killRaceTime = player.GetPlayerNetTime( "killRaceTime" )
	if ( killRaceTime > 0.0 )
	{
		thread PlayerKillrace( player, killRaceTime )
		return true // delete the flag entity
	}
	
	return false // keep it alive
}

void function PlayerKillrace( entity player, float raceTime )
{
	file.currentKillraceScore = 0
	file.currentRacer = player
	int oldMaxHealth = player.GetMaxHealth()

	player.SetMaxHealth( oldMaxHealth * 10 )
	player.SetHealth( player.GetMaxHealth() )
	
	foreach ( entity weapon in player.GetMainWeapons() )
		foreach ( string mod in GetWeaponBurnMods( weapon.GetWeaponClassName() ) )
			weapon.AddMod( mod )
	
	foreach ( entity otherPlayer in GetPlayerArray() )
		Remote_CallFunction_NonReplay( otherPlayer, "ServerCallback_NewKillRacer", player.GetEncodedEHandle(), Time() + raceTime )
	
	float raceEnd = Time() + raceTime
	while ( raceEnd > Time() && IsAlive( player ) )
		WaitFrame()
		
	player.SetPlayerNetTime( "killRaceTime", 0.0 )
	player.SetMaxHealth( oldMaxHealth )
	
	foreach ( entity weapon in player.GetMainWeapons() )
		foreach ( string mod in GetWeaponBurnMods( weapon.GetWeaponClassName() ) )
			weapon.RemoveMod( mod )
	
	foreach ( entity otherPlayer in GetPlayerArray() )
		Remote_CallFunction_NonReplay( otherPlayer, "ServerCallback_EndKillrace", player.GetEncodedEHandle(), file.currentKillraceScore )
	
	if ( GameRules_GetTeamScore( player.GetTeam() ) < file.currentKillraceScore ) 
	{
		GameRules_SetTeamScore( player.GetTeam(), file.currentKillraceScore )
		player.SetPlayerGameStat( PGS_ASSAULT_SCORE, file.currentKillraceScore )
	}
	
	thread KillraceSpawnThink() // go to spawn next flag
}

void function StartKillraceSpawnThink()
{
	thread KillraceSpawnThink()
}

void function KillraceSpawnThink()
{
	file.currentHighestKillraceAmount = 0
	file.currentRacer = null
	file.currentKillraceScore = 0
	float time = Time()
	while ( time + 20.0 > Time() && file.currentHighestKillraceAmount < 25 )
		WaitFrame()
	
	vector spawnpos = file.flagSpawnPoints[ RandomInt( file.flagSpawnPoints.len() ) ]
	foreach ( entity player in GetPlayerArray() )
		Remote_CallFunction_NonReplay( player, "ServerCallback_FlagSpawnIncoming", spawnpos.x, spawnpos.y, spawnpos.z, Time() + 15 )
		
	wait 15.0
	
	// create a flag
	entity flag = CreateEntity( "item_flag" )
	flag.SetValueForModelKey( CTF_FLAG_MODEL )
	SetTargetName( flag, "krflag" )
	DispatchSpawn( flag )
	flag.SetModel( CTF_FLAG_MODEL )
	flag.SetOrigin( spawnpos + < 0, 0, flag.GetBoundingMaxs().z / 2 > ) // get it out of the ground
	flag.SetVelocity( < 0, 0, 1 > ) // make it do gravity again	
}