aboutsummaryrefslogtreecommitdiff
path: root/Northstar.Custom/mod/scripts/vscripts/gamemodes/_gamemode_hidden.nut
blob: c3bdd48498c73df69f26170793a2fc98fcd89788 (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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
global function GamemodeHidden_Init

struct {
	bool isVisible = false
	array<entity> hiddens
} file

void function GamemodeHidden_Init()
{
	SetShouldUseRoundWinningKillReplay( true )
	SetLoadoutGracePeriodEnabled( false ) // prevent modifying loadouts with grace period
	SetWeaponDropsEnabled( false )
	SetRespawnsEnabled( false )
	SetGamemodeAllowsTeamSwitch( false )
	Riff_ForceTitanAvailability( eTitanAvailability.Never )
	Riff_ForceBoostAvailability( eBoostAvailability.Disabled )
	Riff_ForceSetEliminationMode( eEliminationMode.Pilots )

	ClassicMP_SetCustomIntro( ClassicMP_DefaultNoIntro_Setup, ClassicMP_DefaultNoIntro_GetLength() )
	ClassicMP_ForceDisableEpilogue( true )

	AddCallback_OnClientConnected( HiddenInitPlayer )
	AddCallback_OnPlayerKilled( HiddenOnPlayerKilled )
	AddCallback_GameStateEnter( eGameState.Playing, SelectFirstHidden )
	AddCallback_GameStateEnter( eGameState.Postmatch, RemoveHidden )
	SetTimeoutWinnerDecisionFunc( TimeoutCheckSurvivors )

	RegisterSignal( "VisibleNotification" )
}

void function HiddenInitPlayer( entity player )
{
	SetTeam( player, TEAM_MILITIA )
}

void function SelectFirstHidden()
{
	thread SelectFirstHiddenDelayed()
}

void function SelectFirstHiddenDelayed()
{
	wait 10.0 + RandomFloat( 5.0 )

	array<entity> players = GetPlayerArray()
	entity hidden = players[ RandomInt( players.len() ) ]

	if (hidden != null || IsAlive(hidden))
		MakePlayerHidden( hidden ) // randomly selected player becomes hidden

	foreach ( entity otherPlayer in GetPlayerArray() )
			if ( hidden != otherPlayer )
				Remote_CallFunction_NonReplay( otherPlayer, "ServerCallback_AnnounceHidden", hidden.GetEncodedEHandle() )

	PlayMusicToAll( eMusicPieceID.GAMEMODE_1 )

	thread UpdateSurvivorsLoadout()
}

void function UpdateSurvivorsLoadout()
{
	foreach (entity player in GetPlayerArray())
	{
		if (player.GetTeam() != TEAM_MILITIA || !IsAlive(player) || player == null)
			continue;

		foreach ( entity weapon in player.GetOffhandWeapons() )
			player.TakeWeaponNow( weapon.GetWeaponClassName() )

		try {
			player.GiveOffhandWeapon("mp_ability_cloak", OFFHAND_SPECIAL )
			player.GiveOffhandWeapon("mp_weapon_grenade_emp", OFFHAND_ORDNANCE )
			player.GiveOffhandWeapon( "melee_pilot_emptyhanded", OFFHAND_MELEE )
		} catch (ex) {}
	}
}

void function MakePlayerHidden(entity player)
{
	if (player == null)
		return;

	SetTeam( player, TEAM_IMC )
	player.SetPlayerGameStat( PGS_ASSAULT_SCORE, 0 ) // reset kills
	file.hiddens.append( player )
	RespawnHidden( player )
	thread PredatorMain( player )
	thread VisibleNotification( player )
	Remote_CallFunction_NonReplay( player, "ServerCallback_YouAreHidden" )
}

void function RespawnHidden(entity player)
{
	if (player.GetTeam() != TEAM_IMC )
		return

	// scale health of the hidden, with 50 as base health
	player.SetMaxHealth( 80 + ( (GetPlayerArrayOfTeam( TEAM_MILITIA ).len() + 1 ) * 20) )
	player.SetHealth( 80 + ( (GetPlayerArrayOfTeam( TEAM_MILITIA ).len() + 1 ) * 20) )

	if ( !player.IsMechanical() )
		player.SetBodygroup( player.FindBodyGroup( "head" ), 1 )

	// set loadout
	foreach ( entity weapon in player.GetMainWeapons() )
		player.TakeWeaponNow( weapon.GetWeaponClassName() )

	foreach ( entity weapon in player.GetOffhandWeapons() )
		player.TakeWeaponNow( weapon.GetWeaponClassName() )

	player.GiveWeapon("mp_weapon_wingman_n")
	player.GiveOffhandWeapon( "melee_pilot_emptyhanded", OFFHAND_MELEE )
	player.GiveOffhandWeapon( "mp_weapon_grenade_sonar", OFFHAND_SPECIAL );
	thread UpdateLoadout(player)
	thread GiveArcGrenade(player)
}

void function GiveArcGrenade(entity player)
{
	wait 45.0
	if (IsAlive(player) || player != null)
		player.GiveOffhandWeapon( "mp_weapon_grenade_emp", OFFHAND_ORDNANCE );
}

void function HiddenOnPlayerKilled( entity victim, entity attacker, var damageInfo )
{
	if ( !victim.IsPlayer() || GetGameState() != eGameState.Playing )
		return

	if ( attacker.IsPlayer() )
	{
		// increase kills by 1
		attacker.SetPlayerGameStat( PGS_ASSAULT_SCORE, attacker.GetPlayerGameStat( PGS_ASSAULT_SCORE ) + 1 )
	}

}

void function UpdateLoadout( entity player )
{
	string p2016 = "mp_weapon_wingman_n"
	foreach ( entity weapon in player.GetMainWeapons() )
	{
		if (weapon.GetWeaponClassName() == p2016)
		{
        	weapon.SetWeaponPrimaryAmmoCount(0)
        	weapon.SetWeaponPrimaryClipCount(weapon.GetWeaponPrimaryClipCountMax())
		}
	}
	WaitFrame()
	if ( IsValid( player ) )
		PlayerEarnMeter_SetMode( player, eEarnMeterMode.DISABLED )
}

void function RemoveHidden()
{
	foreach (entity player in GetPlayerArray())
	{
		if (player.GetTeam() == TEAM_IMC && player != null)
			player.kv.VisibilityFlags = ENTITY_VISIBLE_TO_EVERYONE
	}
}

void function PredatorMain( entity player )
{
        player.EndSignal( "OnDeath" )
        player.EndSignal( "OnDestroy" )
	float playerVel

	while (true) 
	{
		WaitFrame()
		if(!IsLobby())
		{
			if ( !IsValid( player ) || !IsAlive( player ) || player.GetTeam() != TEAM_IMC )
				continue

			vector playerVelV = player.GetVelocity()
			playerVel = sqrt( playerVelV.x * playerVelV.x + playerVelV.y * playerVelV.y + playerVelV.z * playerVelV.z )

			if ( playerVel/300 < 1.3 )
			{
				player.SetCloakFlicker( 0, 0 )
				player.kv.VisibilityFlags = 0
				wait 0.5
				if ( file.isVisible )
				{
					file.isVisible = false
					player.Signal( "VisibleNotification" )
				}
			}
			else
			{
				player.SetCloakFlicker( 0.2 , 1 )
				player.kv.VisibilityFlags = 0
				float waittime = RandomFloat( 0.5 )
				wait waittime
				player.kv.VisibilityFlags = ENTITY_VISIBLE_TO_EVERYONE
				file.isVisible = true
			}
		}
	}
}

void function VisibleNotification( entity player )
{
        player.EndSignal( "OnDeath" )
        player.EndSignal( "OnDestroy" )
	while (IsAlive(player))
	{
		WaitFrame()
		if (!file.isVisible)
		{
			NSDeleteStatusMessageOnPlayer( player, "visibleTitle" )
			NSDeleteStatusMessageOnPlayer( player, "visibleDesc" )
			continue
		}
		else
		{
			NSCreateStatusMessageOnPlayer( player, "You are visible!", "", "visibleTitle" )
			NSCreateStatusMessageOnPlayer( player, "Note:", "Slow down to remain invisible!", "visibleDesc" )
			player.WaitSignal( "VisibleNotification" )
			continue
		}
	}
}

int function TimeoutCheckSurvivors()
{
	if ( GetPlayerArrayOfTeam( TEAM_MILITIA ).len() > 0 )
		return TEAM_IMC

	return TEAM_MILITIA
}