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
|
untyped
global function ToolgunTools_Init
global function AddCallback_OnToolgunToolsInit
global function RegisterTool
global function CallToolOnEquipped
global function CallToolOnUnequipped
global function CallToolOnFired
global function CallToolOnAds
global function CallToolOnUnAds
#if SERVER
global function SetToolgunAmmoCount
global function SetToolgunProscreen
#endif // #if SERVER
global struct ToolgunTool
{
string toolName = ""
string toolDescription = ""
void functionref( entity, entity ) onEquipped
void functionref( entity, entity ) onUnequipped
void functionref( entity, entity, WeaponPrimaryAttackParams ) onFired
void functionref( entity, entity ) onAds
void functionref( entity, entity ) onUnAds
}
struct ToolgunPlayerSettings
{
int selectedToolIndex
int ammoCount
int proscreenNumber
}
// doing preprocessor defs inside the struct seemed to cause compiler errors so we define them separately
#if CLIENT
struct {
array<void functionref()> onToolgunToolsInitCallbacks
array<ToolgunTool> tools
ToolgunPlayerSettings clientPlayerSettings
} file
#endif // #if CLIENT
#if SERVER
struct {
array<void functionref()> onToolgunToolsInitCallbacks
array<ToolgunTool> tools
// serverside playersettings
table<int, ToolgunPlayerSettings> playerSettings
} file
#endif // #if SERVER
void function AddCallback_OnToolgunToolsInit( void functionref() callback )
{
file.onToolgunToolsInitCallbacks.append( callback )
}
void function ToolgunTools_Init()
{
//#if SERVER
//AddCallback_OnClientConnecting( InitialiseToolgunSettings )
//AddCallback_OnClientDisconnected( DestroyToolgunSettings )
//#endif // #if SERVER
//
//// need this threaded so we can wait a frame
//thread ToolgunTools_InitThreaded()
}
void function ToolgunTools_InitThreaded()
{
// wait a frame for tools to all init and add their callbacks
WaitFrame()
// call callbacks
foreach ( void functionref() callback in file.onToolgunToolsInitCallbacks )
callback()
}
void function RegisterTool( ToolgunTool toolStruct )
{
file.tools.append( toolStruct )
}
void function CallToolOnEquipped( entity player, entity weapon )
{
#if CLIENT
if ( file.tools[ file.clientPlayerSettings.selectedToolIndex ].onEquipped != null )
file.tools[ file.clientPlayerSettings.selectedToolIndex ].onEquipped( player, weapon )
#endif // #if CLIENT
#if SERVER
// set ammo and proscreen numbers when equipped
weapon.SetProScreenIntValForIndex( PRO_SCREEN_INT_LIFETIME_KILLS, file.playerSettings[ player.GetPlayerIndex() ].proscreenNumber )
weapon.SetWeaponPrimaryClipCount( file.playerSettings[ player.GetPlayerIndex() ].ammoCount )
if ( file.tools[ file.playerSettings[ player.GetPlayerIndex() ].selectedToolIndex ].onEquipped != null )
file.tools[ file.playerSettings[ player.GetPlayerIndex() ].selectedToolIndex ].onEquipped( player, weapon )
#endif // #if SERVER
}
void function CallToolOnUnequipped( entity player, entity weapon )
{
#if CLIENT
if ( file.tools[ file.clientPlayerSettings.selectedToolIndex ].onUnequipped != null )
file.tools[ file.clientPlayerSettings.selectedToolIndex ].onUnequipped( player, weapon )
#endif // #if CLIENT
#if SERVER
if ( file.tools[ file.playerSettings[ player.GetPlayerIndex() ].selectedToolIndex ].onUnequipped != null )
file.tools[ file.playerSettings[ player.GetPlayerIndex() ].selectedToolIndex ].onUnequipped( player, weapon )
#endif // #if SERVER
}
void function CallToolOnFired( entity player, entity weapon, WeaponPrimaryAttackParams attackParams )
{
#if CLIENT
if ( file.tools[ file.clientPlayerSettings.selectedToolIndex ].onFired != null )
file.tools[ file.clientPlayerSettings.selectedToolIndex ].onFired( player, weapon, attackParams )
#endif // #if CLIENT
#if SERVER
// ammocount needs to be +1 because we lose 1 ammo immediately after this function is run
weapon.SetWeaponPrimaryClipCount( file.playerSettings[ player.GetPlayerIndex() ].ammoCount + 1 )
if ( file.tools[ file.playerSettings[ player.GetPlayerIndex() ].selectedToolIndex ].onFired != null )
file.tools[ file.playerSettings[ player.GetPlayerIndex() ].selectedToolIndex ].onFired( player, weapon, attackParams )
#endif // #if SERVER
}
void function CallToolOnAds( entity player, entity weapon )
{
#if CLIENT
if ( file.tools[ file.clientPlayerSettings.selectedToolIndex ].onAds != null )
file.tools[ file.clientPlayerSettings.selectedToolIndex ].onAds( player, weapon )
#endif // #if CLIENT
#if SERVER
if ( file.tools[ file.playerSettings[ player.GetPlayerIndex() ].selectedToolIndex ].onUnequipped != null )
file.tools[ file.playerSettings[ player.GetPlayerIndex() ].selectedToolIndex ].onUnequipped( player, weapon )
#endif // #if SERVER
}
void function CallToolOnUnAds( entity player, entity weapon )
{
#if CLIENT
if ( file.tools[ file.clientPlayerSettings.selectedToolIndex ].onUnAds != null )
file.tools[ file.clientPlayerSettings.selectedToolIndex ].onUnAds( player, weapon )
#endif // #if CLIENT
#if SERVER
if ( file.tools[ file.playerSettings[ player.GetPlayerIndex() ].selectedToolIndex ].onUnequipped != null )
file.tools[ file.playerSettings[ player.GetPlayerIndex() ].selectedToolIndex ].onUnequipped( player, weapon )
#endif // #if SERVER
}
#if SERVER
void function InitialiseToolgunSettings( entity player )
{
print( "initialising toolgun settings for player " + player )
ToolgunPlayerSettings playerSettings
playerSettings.selectedToolIndex = 0
file.playerSettings[ player.GetPlayerIndex() ] <- playerSettings
}
void function DestroyToolgunSettings( entity player )
{
delete file.playerSettings[ player.GetPlayerIndex() ]
}
void function SetToolgunAmmoCount( entity player, int ammoCount )
{
entity currentWeapon = player.GetActiveWeapon()
if ( ammoCount > currentWeapon.GetWeaponPrimaryClipCountMax() ) // setting clipcount to over max clipcount crashes so we need to prevent that
return
ToolgunPlayerSettings playerSettings = file.playerSettings[ player.GetPlayerIndex() ]
playerSettings.ammoCount = ammoCount
if ( currentWeapon.GetWeaponClassName() == "mp_weapon_toolgun" ) // set ammocount immediately if we've got toolgun equipped already
currentWeapon.SetWeaponPrimaryClipCount( ammoCount )
}
void function SetToolgunProscreen( entity player, int proscreenNumber )
{
ToolgunPlayerSettings playerSettings = file.playerSettings[ player.GetPlayerIndex() ]
playerSettings.proscreenNumber = proscreenNumber
if ( player.GetActiveWeapon().GetWeaponClassName() == "mp_weapon_toolgun" ) // set proscreen number immediately if we've got toolgun equipped already
player.GetActiveWeapon().SetProScreenIntValForIndex( PRO_SCREEN_INT_LIFETIME_KILLS, proscreenNumber )
}
#endif // #if SERVER
|