|
pred@1964
|
1 |
/** |
|
pred@1964
|
2 |
* vim: set ts=4 : |
|
pred@1964
|
3 |
* ============================================================================= |
|
pred@1964
|
4 |
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved. |
|
pred@1964
|
5 |
* ============================================================================= |
|
pred@1964
|
6 |
* |
|
pred@1964
|
7 |
* This file is part of the SourceMod/SourcePawn SDK. |
|
pred@1964
|
8 |
* |
|
pred@1964
|
9 |
* This program is free software; you can redistribute it and/or modify it under |
|
pred@1964
|
10 |
* the terms of the GNU General Public License, version 3.0, as published by the |
|
pred@1964
|
11 |
* Free Software Foundation. |
|
pred@1964
|
12 |
* |
|
pred@1964
|
13 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
pred@1964
|
14 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
pred@1964
|
15 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
pred@1964
|
16 |
* details. |
|
pred@1964
|
17 |
* |
|
pred@1964
|
18 |
* You should have received a copy of the GNU General Public License along with |
|
pred@1964
|
19 |
* this program. If not, see <http://www.gnu.org/licenses/>. |
|
pred@1964
|
20 |
* |
|
pred@1964
|
21 |
* As a special exception, AlliedModders LLC gives you permission to link the |
|
pred@1964
|
22 |
* code of this program (as well as its derivative works) to "Half-Life 2," the |
|
pred@1964
|
23 |
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software |
|
pred@1964
|
24 |
* by the Valve Corporation. You must obey the GNU General Public License in |
|
pred@1964
|
25 |
* all respects for all other code used. Additionally, AlliedModders LLC grants |
|
pred@1964
|
26 |
* this exception to all derivative works. AlliedModders LLC defines further |
|
pred@1964
|
27 |
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), |
|
pred@1964
|
28 |
* or <http://www.sourcemod.net/license.php>. |
|
pred@1964
|
29 |
* |
|
ds@1987
|
30 |
* Version: $Id$ |
|
pred@1964
|
31 |
*/ |
|
pred@1964
|
32 |
|
|
pred@1963
|
33 |
#if defined _tf2_stocks_included |
|
pred@1963
|
34 |
#endinput |
|
pred@1963
|
35 |
#endif |
|
pred@1963
|
36 |
#define _tf2_stocks_included |
|
pred@1963
|
37 |
|
|
pred@1963
|
38 |
#include <tf2> |
|
pred@1963
|
39 |
#include <sdktools> |
|
pred@1963
|
40 |
|
|
pred@1963
|
41 |
enum TFResourceType |
|
pred@1963
|
42 |
{ |
|
pred@1963
|
43 |
TFResource_Ping, |
|
pred@1963
|
44 |
TFResource_Score, |
|
pred@1963
|
45 |
TFResource_Deaths, |
|
pred@1963
|
46 |
TFResource_TotalScore, |
|
pred@1963
|
47 |
TFResource_Captures, |
|
pred@1963
|
48 |
TFResource_Defenses, |
|
pred@1963
|
49 |
TFResource_Dominations, |
|
pred@1963
|
50 |
TFResource_Revenge, |
|
pred@1963
|
51 |
TFResource_BuildingsDestroyed, |
|
pred@1963
|
52 |
TFResource_Headshots, |
|
pred@1963
|
53 |
TFResource_Backstabs, |
|
pred@1963
|
54 |
TFResource_HealPoints, |
|
pred@1963
|
55 |
TFResource_Invulns, |
|
pred@1963
|
56 |
TFResource_Teleports, |
|
pred@1963
|
57 |
TFResource_ResupplyPoints, |
|
pred@1963
|
58 |
TFResource_KillAssists, |
|
pred@1963
|
59 |
TFResource_MaxHealth, |
|
pred@1963
|
60 |
TFResource_PlayerClass |
|
pred@1963
|
61 |
}; |
|
pred@1963
|
62 |
|
|
pred@1963
|
63 |
static const String:TFResourceNames[TFResourceType][] = |
|
pred@1963
|
64 |
{ |
|
pred@1963
|
65 |
"m_iPing", |
|
pred@1963
|
66 |
"m_iScore", |
|
pred@1963
|
67 |
"m_iDeaths", |
|
pred@1963
|
68 |
"m_iTotalScore", |
|
pred@1963
|
69 |
"m_iCaptures", |
|
pred@1963
|
70 |
"m_iDefenses", |
|
pred@1963
|
71 |
"m_iDominations", |
|
pred@1963
|
72 |
"m_iRevenge", |
|
pred@1963
|
73 |
"m_iBuildingsDestroyed", |
|
pred@1963
|
74 |
"m_iHeadshots", |
|
pred@1963
|
75 |
"m_iBackstabs", |
|
pred@1963
|
76 |
"m_iHealPoints", |
|
pred@1963
|
77 |
"m_iInvulns", |
|
pred@1963
|
78 |
"m_iTeleports", |
|
pred@1963
|
79 |
"m_iResupplyPoints", |
|
pred@1963
|
80 |
"m_iKillAssists", |
|
pred@1963
|
81 |
"m_iMaxHealth", |
|
pred@1963
|
82 |
"m_iPlayerClass" |
|
pred@1963
|
83 |
}; |
|
pred@1963
|
84 |
|
|
pred@1963
|
85 |
/** |
|
pred@1963
|
86 |
* Get's a Clients current class. |
|
pred@1963
|
87 |
* |
|
pred@1963
|
88 |
* @param client Player's index. |
|
pred@1963
|
89 |
* @param class TFClassType to change to. |
|
pred@1963
|
90 |
* @noreturn |
|
pred@1963
|
91 |
* @error Invalid client index. |
|
pred@1963
|
92 |
*/ |
|
pred@1963
|
93 |
stock TFClassType:TF2_GetPlayerClass(client) |
|
pred@1963
|
94 |
{ |
|
pred@1963
|
95 |
return TFClassType:GetEntProp(client, Prop_Send, "m_iClass"); |
|
pred@1963
|
96 |
} |
|
pred@1963
|
97 |
|
|
pred@1963
|
98 |
/** |
|
pred@1963
|
99 |
* Set's a Clients class. |
|
pred@1963
|
100 |
* |
|
pred@1988
|
101 |
* Note: If setting player class in a player spawn hook weapons should be set to false. |
|
pred@1988
|
102 |
* |
|
pred@1963
|
103 |
* @param client Player's index. |
|
pred@1963
|
104 |
* @param class TFClassType class symbol. |
|
pred@1963
|
105 |
* @param weapons If true, changes the players weapon set to that of the new class. |
|
pred@1963
|
106 |
* @noreturn |
|
pred@1963
|
107 |
* @error Invalid client index. |
|
pred@1963
|
108 |
*/ |
|
pred@1963
|
109 |
stock TF2_SetPlayerClass(client, TFClassType:class, bool:weapons=true) |
|
pred@1963
|
110 |
{ |
|
pred@1963
|
111 |
SetEntProp(client, Prop_Send, "m_iClass", _:class); |
|
pred@1963
|
112 |
SetEntProp(client, Prop_Send, "m_iDesiredPlayerClass", _:class); |
|
pred@1963
|
113 |
TF2_SetPlayerResourceData(client, TFResource_PlayerClass, class); |
|
pred@1963
|
114 |
|
|
pred@1988
|
115 |
if (weapons && IsPlayerAlive(client)) |
|
pred@1963
|
116 |
{ |
|
pred@1963
|
117 |
TF2_RemoveAllWeapons(client); |
|
dvander@1975
|
118 |
TF2_EquipPlayerClassWeapons(client, class); |
|
pred@1963
|
119 |
} |
|
pred@1963
|
120 |
} |
|
pred@1963
|
121 |
|
|
pred@1963
|
122 |
/** |
|
pred@1963
|
123 |
* Retrieves client data from the resource entity |
|
pred@1963
|
124 |
* |
|
pred@1963
|
125 |
* @param client Player's index. |
|
pred@1963
|
126 |
* @param type ResourceType constant |
|
pred@1963
|
127 |
* @return Value or -1 on failure. |
|
pred@1963
|
128 |
* @error Invalid client index, client not in game or failed to find resource entity. |
|
pred@1963
|
129 |
*/ |
|
pred@1963
|
130 |
stock TF2_GetPlayerResourceData(client, TFResourceType:type) |
|
pred@1963
|
131 |
{ |
|
pred@1963
|
132 |
if (!IsClientConnected(client)) |
|
pred@1963
|
133 |
{ |
|
pred@1963
|
134 |
return -1; |
|
pred@1963
|
135 |
} |
|
pred@1963
|
136 |
|
|
pred@1963
|
137 |
static offset; |
|
pred@1963
|
138 |
static set = false; |
|
pred@1963
|
139 |
|
|
pred@1963
|
140 |
if (!set) |
|
pred@1963
|
141 |
{ |
|
pred@1963
|
142 |
offset = FindSendPropInfo("CTFPlayerResource", TFResourceNames[type]); |
|
pred@1963
|
143 |
set = true; |
|
pred@1963
|
144 |
} |
|
pred@1963
|
145 |
|
|
pred@1963
|
146 |
if (offset < 1) |
|
pred@1963
|
147 |
{ |
|
pred@1963
|
148 |
return -1; |
|
pred@1963
|
149 |
} |
|
pred@1963
|
150 |
|
|
pred@1963
|
151 |
new entity = TF2_GetResourceEntity(); |
|
pred@1963
|
152 |
|
|
pred@1963
|
153 |
if (entity == -1) |
|
pred@1963
|
154 |
{ |
|
pred@1963
|
155 |
return -1; |
|
pred@1963
|
156 |
} |
|
pred@1963
|
157 |
|
|
pred@1963
|
158 |
return GetEntData(entity, offset + (client*4)); |
|
pred@1963
|
159 |
} |
|
pred@1963
|
160 |
|
|
pred@1963
|
161 |
/** |
|
pred@1963
|
162 |
* Sets client data in the resource entity |
|
pred@1963
|
163 |
* |
|
pred@1963
|
164 |
* @param client Player's index. |
|
pred@1963
|
165 |
* @param type ResourceType constant |
|
pred@1963
|
166 |
* @param value Value to set. |
|
pred@1963
|
167 |
* @return Value or -1 on failure. |
|
pred@1963
|
168 |
* @error Invalid client index, client not in game or failed to find resource entity. |
|
pred@1963
|
169 |
*/ |
|
pred@1963
|
170 |
stock bool:TF2_SetPlayerResourceData(client, TFResourceType:type, any:value) |
|
pred@1963
|
171 |
{ |
|
pred@1963
|
172 |
if (!IsClientConnected(client)) |
|
pred@1963
|
173 |
{ |
|
pred@1963
|
174 |
return false; |
|
pred@1963
|
175 |
} |
|
pred@1963
|
176 |
|
|
pred@1963
|
177 |
static offset; |
|
pred@1963
|
178 |
static set = false; |
|
pred@1963
|
179 |
|
|
pred@1963
|
180 |
if (!set) |
|
pred@1963
|
181 |
{ |
|
pred@1963
|
182 |
offset = FindSendPropInfo("CTFPlayerResource", TFResourceNames[type]); |
|
pred@1963
|
183 |
set = true; |
|
pred@1963
|
184 |
} |
|
pred@1963
|
185 |
|
|
pred@1963
|
186 |
if (offset < 1) |
|
pred@1963
|
187 |
{ |
|
pred@1963
|
188 |
return false; |
|
pred@1963
|
189 |
} |
|
pred@1963
|
190 |
|
|
pred@1963
|
191 |
new entity = TF2_GetResourceEntity(); |
|
pred@1963
|
192 |
|
|
pred@1963
|
193 |
if (entity == -1) |
|
pred@1963
|
194 |
{ |
|
pred@1963
|
195 |
return false; |
|
pred@1963
|
196 |
} |
|
pred@1963
|
197 |
|
|
dvander@1975
|
198 |
SetEntData(entity, offset + (client*4), value); |
|
pred@1963
|
199 |
|
|
pred@1963
|
200 |
return true; |
|
pred@1963
|
201 |
} |
|
pred@1963
|
202 |
|
|
pred@1963
|
203 |
/** |
|
pred@1963
|
204 |
* Removes all weapons from a client's weapon slot |
|
pred@1963
|
205 |
* |
|
pred@1963
|
206 |
* @param client Player's index. |
|
pred@1963
|
207 |
* @param slot Slot index (0-5) |
|
pred@1963
|
208 |
* @noreturn |
|
pred@1963
|
209 |
* @error Invalid client, invalid slot or lack of mod support |
|
pred@1963
|
210 |
*/ |
|
pred@1963
|
211 |
stock TF2_RemoveWeaponSlot(client, slot) |
|
pred@1963
|
212 |
{ |
|
pred@1963
|
213 |
new weaponIndex; |
|
pred@1963
|
214 |
while ((weaponIndex = GetPlayerWeaponSlot(client, slot)) != -1) |
|
pred@1963
|
215 |
{ |
|
pred@1963
|
216 |
RemovePlayerItem(client, weaponIndex); |
|
pred@1963
|
217 |
RemoveEdict(weaponIndex); |
|
pred@1963
|
218 |
} |
|
pred@1963
|
219 |
} |
|
pred@1963
|
220 |
|
|
pred@1963
|
221 |
/** |
|
pred@1963
|
222 |
* Removes all weapons from a client |
|
pred@1963
|
223 |
* |
|
pred@1963
|
224 |
* @param client Player's index. |
|
pred@1963
|
225 |
* @noreturn |
|
pred@1963
|
226 |
*/ |
|
pred@1963
|
227 |
stock TF2_RemoveAllWeapons(client) |
|
pred@1963
|
228 |
{ |
|
pred@1963
|
229 |
for (new i = 0; i <= 5; i++) |
|
pred@1963
|
230 |
{ |
|
pred@1963
|
231 |
TF2_RemoveWeaponSlot(client, i); |
|
pred@1963
|
232 |
} |
|
pred@1963
|
233 |
} |
|
pred@1963
|
234 |
|
|
pred@1963
|
235 |
/** |
|
pred@1963
|
236 |
* Gives a named weapon to a client |
|
pred@1963
|
237 |
* |
|
pred@1963
|
238 |
* @param client Player's index. |
|
pred@1963
|
239 |
* @param weapon Weapon name |
|
pred@1963
|
240 |
* @return False if weapon could not be created, true on success |
|
pred@1963
|
241 |
* @error Invalid client index or lack of mod support |
|
pred@1963
|
242 |
*/ |
|
pred@1963
|
243 |
stock bool:TF2_GivePlayerWeapon(client, const String:weapon[]) |
|
pred@1963
|
244 |
{ |
|
pred@1963
|
245 |
new weaponIndex = GivePlayerItem(client, weapon); |
|
pred@1963
|
246 |
if (weaponIndex == -1) |
|
pred@1963
|
247 |
{ |
|
pred@1963
|
248 |
return false; |
|
pred@1963
|
249 |
} |
|
pred@1963
|
250 |
|
|
pred@1963
|
251 |
EquipPlayerWeapon(client, weaponIndex); |
|
pred@1963
|
252 |
|
|
pred@1963
|
253 |
return true; |
|
pred@1963
|
254 |
} |
|
pred@1963
|
255 |
|
|
pred@1963
|
256 |
/** |
|
pred@1963
|
257 |
* Equips a client with a class's weapons. This does not remove existing weapons. |
|
pred@1963
|
258 |
* |
|
pred@1963
|
259 |
* Note: Some class specific items such tf_weapon_pda_engineer_build are only given |
|
pred@1963
|
260 |
* if the client is the correct class. |
|
pred@1963
|
261 |
* |
|
pred@1963
|
262 |
* @param client Player's index. |
|
pred@1963
|
263 |
* @param class TFClasssType class symbol. |
|
pred@1963
|
264 |
* @noreturn |
|
pred@1963
|
265 |
*/ |
|
pred@1963
|
266 |
stock TF2_EquipPlayerClassWeapons(client, TFClassType:class) |
|
pred@1963
|
267 |
{ |
|
pred@1963
|
268 |
switch(class) |
|
pred@1963
|
269 |
{ |
|
pred@1963
|
270 |
case TFClass_Scout: |
|
pred@1963
|
271 |
{ |
|
pred@1963
|
272 |
TF2_GivePlayerWeapon(client, "tf_weapon_scattergun"); |
|
pred@1963
|
273 |
TF2_GivePlayerWeapon(client, "tf_weapon_pistol_scout"); |
|
pred@1963
|
274 |
TF2_GivePlayerWeapon(client, "tf_weapon_bat"); |
|
pred@1963
|
275 |
} |
|
pred@1963
|
276 |
case TFClass_Sniper: |
|
pred@1963
|
277 |
{ |
|
pred@1963
|
278 |
TF2_GivePlayerWeapon(client, "tf_weapon_sniperrifle"); |
|
pred@1963
|
279 |
TF2_GivePlayerWeapon(client, "tf_weapon_smg"); |
|
pred@1963
|
280 |
TF2_GivePlayerWeapon(client, "tf_weapon_club"); |
|
pred@1963
|
281 |
} |
|
pred@1963
|
282 |
case TFClass_Soldier: |
|
pred@1963
|
283 |
{ |
|
pred@1963
|
284 |
TF2_GivePlayerWeapon(client, "tf_weapon_rocketlauncher"); |
|
pred@1963
|
285 |
TF2_GivePlayerWeapon(client, "tf_weapon_shotgun_soldier"); |
|
pred@1963
|
286 |
TF2_GivePlayerWeapon(client, "tf_weapon_shovel"); |
|
pred@1963
|
287 |
} |
|
pred@1963
|
288 |
case TFClass_DemoMan: |
|
pred@1963
|
289 |
{ |
|
pred@1963
|
290 |
TF2_GivePlayerWeapon(client, "tf_weapon_pipebomblauncher"); |
|
pred@1963
|
291 |
TF2_GivePlayerWeapon(client, "tf_weapon_grenadelauncher"); |
|
pred@1963
|
292 |
TF2_GivePlayerWeapon(client, "tf_weapon_bottle"); |
|
pred@1963
|
293 |
} |
|
pred@1963
|
294 |
case TFClass_Medic: |
|
pred@1963
|
295 |
{ |
|
pred@1963
|
296 |
TF2_GivePlayerWeapon(client, "tf_weapon_syringegun_medic"); |
|
pred@1963
|
297 |
TF2_GivePlayerWeapon(client, "tf_weapon_medigun"); |
|
pred@1963
|
298 |
TF2_GivePlayerWeapon(client, "tf_weapon_bonesaw"); |
|
pred@1963
|
299 |
} |
|
pred@1963
|
300 |
case TFClass_Heavy: |
|
pred@1963
|
301 |
{ |
|
pred@1963
|
302 |
TF2_GivePlayerWeapon(client, "tf_weapon_minigun"); |
|
pred@1963
|
303 |
TF2_GivePlayerWeapon(client, "tf_weapon_shotgun_hwg"); |
|
pred@1963
|
304 |
TF2_GivePlayerWeapon(client, "tf_weapon_fists"); |
|
pred@1963
|
305 |
} |
|
pred@1963
|
306 |
case TFClass_Pyro: |
|
pred@1963
|
307 |
{ |
|
pred@1963
|
308 |
TF2_GivePlayerWeapon(client, "tf_weapon_flamethrower"); |
|
pred@1963
|
309 |
TF2_GivePlayerWeapon(client, "tf_weapon_shotgun_pyro"); |
|
pred@1963
|
310 |
TF2_GivePlayerWeapon(client, "tf_weapon_fireaxe"); |
|
pred@1963
|
311 |
} |
|
pred@1963
|
312 |
case TFClass_Spy: |
|
pred@1963
|
313 |
{ |
|
pred@1963
|
314 |
TF2_GivePlayerWeapon(client, "tf_weapon_revolver"); |
|
pred@1963
|
315 |
TF2_GivePlayerWeapon(client, "tf_weapon_knife"); |
|
pred@1963
|
316 |
|
|
pred@1963
|
317 |
if (TF2_GetPlayerClass(client) != TFClass_Spy) |
|
pred@1963
|
318 |
return; |
|
pred@1963
|
319 |
|
|
pred@1963
|
320 |
TF2_GivePlayerWeapon(client, "tf_weapon_pda_spy"); |
|
pred@1963
|
321 |
} |
|
pred@1963
|
322 |
case TFClass_Engineer: |
|
pred@1963
|
323 |
{ |
|
pred@1963
|
324 |
TF2_GivePlayerWeapon(client, "tf_weapon_shotgun_primary"); |
|
pred@1963
|
325 |
TF2_GivePlayerWeapon(client, "tf_weapon_pistol"); |
|
pred@1963
|
326 |
TF2_GivePlayerWeapon(client, "tf_weapon_wrench"); |
|
pred@1963
|
327 |
|
|
pred@1963
|
328 |
if (TF2_GetPlayerClass(client) != TFClass_Engineer) |
|
pred@1963
|
329 |
return; |
|
pred@1963
|
330 |
|
|
pred@1963
|
331 |
TF2_GivePlayerWeapon(client, "tf_weapon_pda_engineer_build"); |
|
pred@1963
|
332 |
TF2_GivePlayerWeapon(client, "tf_weapon_pda_engineer_destroy"); |
|
pred@1963
|
333 |
} |
|
pred@1963
|
334 |
} |
|
pred@1963
|
335 |
} |