aboutsummaryrefslogtreecommitdiff
path: root/Northstar.Custom/mod/scripts/vscripts/_disallowed_weapons.gnut
blob: 8dc0300f7c2be005e2b154f33e8f83f8047961f3 (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
global function DisallowedWeapons_Init

struct {
	array<string> disallowedWeapons
	string disallowedWeaponsStringLastVal
	string disallowedWeaponReplacement
} file

void function DisallowedWeapons_Init()
{
	UpdateDisallowedWeaponList()
	AddCallback_OnPlayerRespawned( ReplacePlayerWeaponsForSpawn )
}

void function UpdateDisallowedWeaponList()
{
	string cvar = GetConVarString( "ns_disallowed_weapons" )
	if ( file.disallowedWeaponsStringLastVal == cvar )
		return
	
	file.disallowedWeapons = split( cvar, "," )
	foreach ( string weapon in file.disallowedWeapons )
		StringReplace( weapon, " ", "" )
	
	file.disallowedWeaponReplacement = GetConVarString( "ns_disallowed_weapon_primary_replacement" )
}

void function ReplacePlayerWeaponsForSpawn( entity player )
{
	UpdateDisallowedWeaponList()
	if ( file.disallowedWeapons.len() == 0 )
		return
	
	bool hadDisallowedWeapon = false

	foreach ( entity weapon in player.GetMainWeapons() )
	{
		if ( file.disallowedWeapons.contains( weapon.GetWeaponClassName() ) )
		{
			player.TakeWeaponNow( weapon.GetWeaponClassName() )
			player.GiveWeapon( file.disallowedWeaponReplacement )
			hadDisallowedWeapon = true
		}
	}
	
	if ( hadDisallowedWeapon )
		SendHudMessage( player, "Restricted weapons were removed", -1, 0.4, 255, 255, 255, 255, 0.15, 3.0, 0.5 )
}