3 * =============================================================================
4 * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
5 * =============================================================================
7 * This file is part of the SourceMod/SourcePawn SDK.
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, version 3.0, as published by the
11 * Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License along with
19 * this program. If not, see <http://www.gnu.org/licenses/>.
21 * As a special exception, AlliedModders LLC gives you permission to link the
22 * code of this program (as well as its derivative works) to "Half-Life 2," the
23 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
24 * by the Valve Corporation. You must obey the GNU General Public License in
25 * all respects for all other code used. Additionally, AlliedModders LLC grants
26 * this exception to all derivative works. AlliedModders LLC defines further
27 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
28 * or <http://www.sourcemod.net/license.php>.
33 #if defined _tf2_stocks_included
36 #define _tf2_stocks_included
46 TFResource_TotalScore,
49 TFResource_Dominations,
51 TFResource_BuildingsDestroyed,
54 TFResource_HealPoints,
57 TFResource_ResupplyPoints,
58 TFResource_KillAssists,
60 TFResource_PlayerClass
63 static const String:TFResourceNames[TFResourceType][] =
73 "m_iBuildingsDestroyed",
86 * Get's a Clients current class.
88 * @param client Player's index.
89 * @param class TFClassType to change to.
91 * @error Invalid client index.
93 stock TFClassType:TF2_GetPlayerClass(client)
95 return TFClassType:GetEntProp(client, Prop_Send, "m_iClass");
99 * Set's a Clients class.
101 * Note: If setting player class in a player spawn hook weapons should be set to false.
103 * @param client Player's index.
104 * @param class TFClassType class symbol.
105 * @param weapons If true, changes the players weapon set to that of the new class.
106 * @param persistant If true changes the players desired class so the change stays after death.
108 * @error Invalid client index.
110 stock TF2_SetPlayerClass(client, TFClassType:class, bool:weapons=true, bool:persistant=true)
112 SetEntProp(client, Prop_Send, "m_iClass", _:class);
113 TF2_SetPlayerResourceData(client, TFResource_PlayerClass, class);
117 SetEntProp(client, Prop_Send, "m_iDesiredPlayerClass", _:class);
120 if (weapons && IsPlayerAlive(client))
122 TF2_RemoveAllWeapons(client);
123 TF2_EquipPlayerClassWeapons(client, class);
128 * Retrieves client data from the resource entity
130 * @param client Player's index.
131 * @param type ResourceType constant
132 * @return Value or -1 on failure.
133 * @error Invalid client index, client not in game or failed to find resource entity.
135 stock TF2_GetPlayerResourceData(client, TFResourceType:type)
137 if (!IsClientConnected(client))
147 offset = FindSendPropInfo("CTFPlayerResource", TFResourceNames[type]);
156 new entity = TF2_GetResourceEntity();
163 return GetEntData(entity, offset + (client*4));
167 * Sets client data in the resource entity
169 * @param client Player's index.
170 * @param type ResourceType constant
171 * @param value Value to set.
172 * @return Value or -1 on failure.
173 * @error Invalid client index, client not in game or failed to find resource entity.
175 stock bool:TF2_SetPlayerResourceData(client, TFResourceType:type, any:value)
177 if (!IsClientConnected(client))
187 offset = FindSendPropInfo("CTFPlayerResource", TFResourceNames[type]);
196 new entity = TF2_GetResourceEntity();
203 SetEntData(entity, offset + (client*4), value);
209 * Removes all weapons from a client's weapon slot
211 * @param client Player's index.
212 * @param slot Slot index (0-5)
214 * @error Invalid client, invalid slot or lack of mod support
216 stock TF2_RemoveWeaponSlot(client, slot)
219 while ((weaponIndex = GetPlayerWeaponSlot(client, slot)) != -1)
221 RemovePlayerItem(client, weaponIndex);
222 RemoveEdict(weaponIndex);
227 * Removes all weapons from a client
229 * @param client Player's index.
232 stock TF2_RemoveAllWeapons(client)
234 for (new i = 0; i <= 5; i++)
236 TF2_RemoveWeaponSlot(client, i);
241 * Gives a named weapon to a client
243 * @param client Player's index.
244 * @param weapon Weapon name
245 * @return False if weapon could not be created, true on success
246 * @error Invalid client index or lack of mod support
248 stock bool:TF2_GivePlayerWeapon(client, const String:weapon[])
250 new weaponIndex = GivePlayerItem(client, weapon);
251 if (weaponIndex == -1)
256 EquipPlayerWeapon(client, weaponIndex);
262 * Equips a client with a class's weapons. This does not remove existing weapons.
264 * Note: Some class specific items such tf_weapon_pda_engineer_build are only given
265 * if the client is the correct class.
267 * @param client Player's index.
268 * @param class TFClasssType class symbol.
271 stock TF2_EquipPlayerClassWeapons(client, TFClassType:class)
277 TF2_GivePlayerWeapon(client, "tf_weapon_scattergun");
278 TF2_GivePlayerWeapon(client, "tf_weapon_pistol_scout");
279 TF2_GivePlayerWeapon(client, "tf_weapon_bat");
283 TF2_GivePlayerWeapon(client, "tf_weapon_sniperrifle");
284 TF2_GivePlayerWeapon(client, "tf_weapon_smg");
285 TF2_GivePlayerWeapon(client, "tf_weapon_club");
287 case TFClass_Soldier:
289 TF2_GivePlayerWeapon(client, "tf_weapon_rocketlauncher");
290 TF2_GivePlayerWeapon(client, "tf_weapon_shotgun_soldier");
291 TF2_GivePlayerWeapon(client, "tf_weapon_shovel");
293 case TFClass_DemoMan:
295 TF2_GivePlayerWeapon(client, "tf_weapon_pipebomblauncher");
296 TF2_GivePlayerWeapon(client, "tf_weapon_grenadelauncher");
297 TF2_GivePlayerWeapon(client, "tf_weapon_bottle");
301 TF2_GivePlayerWeapon(client, "tf_weapon_syringegun_medic");
302 TF2_GivePlayerWeapon(client, "tf_weapon_medigun");
303 TF2_GivePlayerWeapon(client, "tf_weapon_bonesaw");
307 TF2_GivePlayerWeapon(client, "tf_weapon_minigun");
308 TF2_GivePlayerWeapon(client, "tf_weapon_shotgun_hwg");
309 TF2_GivePlayerWeapon(client, "tf_weapon_fists");
313 TF2_GivePlayerWeapon(client, "tf_weapon_flamethrower");
314 TF2_GivePlayerWeapon(client, "tf_weapon_shotgun_pyro");
315 TF2_GivePlayerWeapon(client, "tf_weapon_fireaxe");
319 TF2_GivePlayerWeapon(client, "tf_weapon_revolver");
320 TF2_GivePlayerWeapon(client, "tf_weapon_knife");
322 if (TF2_GetPlayerClass(client) != TFClass_Spy)
325 TF2_GivePlayerWeapon(client, "tf_weapon_pda_spy");
327 case TFClass_Engineer:
329 TF2_GivePlayerWeapon(client, "tf_weapon_shotgun_primary");
330 TF2_GivePlayerWeapon(client, "tf_weapon_pistol");
331 TF2_GivePlayerWeapon(client, "tf_weapon_wrench");
333 if (TF2_GetPlayerClass(client) != TFClass_Engineer)
336 TF2_GivePlayerWeapon(client, "tf_weapon_pda_engineer_build");
337 TF2_GivePlayerWeapon(client, "tf_weapon_pda_engineer_destroy");