1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/plugins/include/tf2_stocks.inc Fri Apr 04 22:37:14 2008 +0000
1.3 @@ -0,0 +1,301 @@
1.4 +#if defined _tf2_stocks_included
1.5 + #endinput
1.6 +#endif
1.7 +#define _tf2_stocks_included
1.8 +
1.9 +#include <tf2>
1.10 +#include <sdktools>
1.11 +
1.12 +enum TFResourceType
1.13 +{
1.14 + TFResource_Ping,
1.15 + TFResource_Score,
1.16 + TFResource_Deaths,
1.17 + TFResource_TotalScore,
1.18 + TFResource_Captures,
1.19 + TFResource_Defenses,
1.20 + TFResource_Dominations,
1.21 + TFResource_Revenge,
1.22 + TFResource_BuildingsDestroyed,
1.23 + TFResource_Headshots,
1.24 + TFResource_Backstabs,
1.25 + TFResource_HealPoints,
1.26 + TFResource_Invulns,
1.27 + TFResource_Teleports,
1.28 + TFResource_ResupplyPoints,
1.29 + TFResource_KillAssists,
1.30 + TFResource_MaxHealth,
1.31 + TFResource_PlayerClass
1.32 +};
1.33 +
1.34 +static const String:TFResourceNames[TFResourceType][] =
1.35 +{
1.36 + "m_iPing",
1.37 + "m_iScore",
1.38 + "m_iDeaths",
1.39 + "m_iTotalScore",
1.40 + "m_iCaptures",
1.41 + "m_iDefenses",
1.42 + "m_iDominations",
1.43 + "m_iRevenge",
1.44 + "m_iBuildingsDestroyed",
1.45 + "m_iHeadshots",
1.46 + "m_iBackstabs",
1.47 + "m_iHealPoints",
1.48 + "m_iInvulns",
1.49 + "m_iTeleports",
1.50 + "m_iResupplyPoints",
1.51 + "m_iKillAssists",
1.52 + "m_iMaxHealth",
1.53 + "m_iPlayerClass"
1.54 +};
1.55 +
1.56 +/**
1.57 + * Get's a Clients current class.
1.58 + *
1.59 + * @param client Player's index.
1.60 + * @param class TFClassType to change to.
1.61 + * @noreturn
1.62 + * @error Invalid client index.
1.63 + */
1.64 +stock TFClassType:TF2_GetPlayerClass(client)
1.65 +{
1.66 + return TFClassType:GetEntProp(client, Prop_Send, "m_iClass");
1.67 +}
1.68 +
1.69 +/**
1.70 + * Set's a Clients class.
1.71 + *
1.72 + * @param client Player's index.
1.73 + * @param class TFClassType class symbol.
1.74 + * @param weapons If true, changes the players weapon set to that of the new class.
1.75 + * @noreturn
1.76 + * @error Invalid client index.
1.77 + */
1.78 +stock TF2_SetPlayerClass(client, TFClassType:class, bool:weapons=true)
1.79 +{
1.80 + SetEntProp(client, Prop_Send, "m_iClass", _:class);
1.81 + SetEntProp(client, Prop_Send, "m_iDesiredPlayerClass", _:class);
1.82 + TF2_SetPlayerResourceData(client, TFResource_PlayerClass, class);
1.83 +
1.84 + if (weapons)
1.85 + {
1.86 + TF2_RemoveAllWeapons(client);
1.87 + TF2_EquipPlayerClassWeapons(client, class)
1.88 + }
1.89 +}
1.90 +
1.91 +/**
1.92 + * Retrieves client data from the resource entity
1.93 + *
1.94 + * @param client Player's index.
1.95 + * @param type ResourceType constant
1.96 + * @return Value or -1 on failure.
1.97 + * @error Invalid client index, client not in game or failed to find resource entity.
1.98 + */
1.99 +stock TF2_GetPlayerResourceData(client, TFResourceType:type)
1.100 +{
1.101 + if (!IsClientConnected(client))
1.102 + {
1.103 + return -1;
1.104 + }
1.105 +
1.106 + static offset;
1.107 + static set = false;
1.108 +
1.109 + if (!set)
1.110 + {
1.111 + offset = FindSendPropInfo("CTFPlayerResource", TFResourceNames[type]);
1.112 + set = true;
1.113 + }
1.114 +
1.115 + if (offset < 1)
1.116 + {
1.117 + return -1;
1.118 + }
1.119 +
1.120 + new entity = TF2_GetResourceEntity();
1.121 +
1.122 + if (entity == -1)
1.123 + {
1.124 + return -1;
1.125 + }
1.126 +
1.127 + return GetEntData(entity, offset + (client*4));
1.128 +}
1.129 +
1.130 +/**
1.131 + * Sets client data in the resource entity
1.132 + *
1.133 + * @param client Player's index.
1.134 + * @param type ResourceType constant
1.135 + * @param value Value to set.
1.136 + * @return Value or -1 on failure.
1.137 + * @error Invalid client index, client not in game or failed to find resource entity.
1.138 + */
1.139 +stock bool:TF2_SetPlayerResourceData(client, TFResourceType:type, any:value)
1.140 +{
1.141 + if (!IsClientConnected(client))
1.142 + {
1.143 + return false;
1.144 + }
1.145 +
1.146 + static offset;
1.147 + static set = false;
1.148 +
1.149 + if (!set)
1.150 + {
1.151 + offset = FindSendPropInfo("CTFPlayerResource", TFResourceNames[type]);
1.152 + set = true;
1.153 + }
1.154 +
1.155 + if (offset < 1)
1.156 + {
1.157 + return false;
1.158 + }
1.159 +
1.160 + new entity = TF2_GetResourceEntity();
1.161 +
1.162 + if (entity == -1)
1.163 + {
1.164 + return false;
1.165 + }
1.166 +
1.167 + SetEntData(entity, offset + (client*4), value)
1.168 +
1.169 + return true;
1.170 +}
1.171 +
1.172 +/**
1.173 + * Removes all weapons from a client's weapon slot
1.174 + *
1.175 + * @param client Player's index.
1.176 + * @param slot Slot index (0-5)
1.177 + * @noreturn
1.178 + * @error Invalid client, invalid slot or lack of mod support
1.179 + */
1.180 +stock TF2_RemoveWeaponSlot(client, slot)
1.181 +{
1.182 + new weaponIndex;
1.183 + while ((weaponIndex = GetPlayerWeaponSlot(client, slot)) != -1)
1.184 + {
1.185 + RemovePlayerItem(client, weaponIndex);
1.186 + RemoveEdict(weaponIndex);
1.187 + }
1.188 +}
1.189 +
1.190 +/**
1.191 + * Removes all weapons from a client
1.192 + *
1.193 + * @param client Player's index.
1.194 + * @noreturn
1.195 + */
1.196 +stock TF2_RemoveAllWeapons(client)
1.197 +{
1.198 + for (new i = 0; i <= 5; i++)
1.199 + {
1.200 + TF2_RemoveWeaponSlot(client, i);
1.201 + }
1.202 +}
1.203 +
1.204 +/**
1.205 + * Gives a named weapon to a client
1.206 + *
1.207 + * @param client Player's index.
1.208 + * @param weapon Weapon name
1.209 + * @return False if weapon could not be created, true on success
1.210 + * @error Invalid client index or lack of mod support
1.211 + */
1.212 +stock bool:TF2_GivePlayerWeapon(client, const String:weapon[])
1.213 +{
1.214 + new weaponIndex = GivePlayerItem(client, weapon);
1.215 + if (weaponIndex == -1)
1.216 + {
1.217 + return false;
1.218 + }
1.219 +
1.220 + EquipPlayerWeapon(client, weaponIndex);
1.221 +
1.222 + return true;
1.223 +}
1.224 +
1.225 +/**
1.226 + * Equips a client with a class's weapons. This does not remove existing weapons.
1.227 + *
1.228 + * Note: Some class specific items such tf_weapon_pda_engineer_build are only given
1.229 + * if the client is the correct class.
1.230 + *
1.231 + * @param client Player's index.
1.232 + * @param class TFClasssType class symbol.
1.233 + * @noreturn
1.234 + */
1.235 +stock TF2_EquipPlayerClassWeapons(client, TFClassType:class)
1.236 +{
1.237 + switch(class)
1.238 + {
1.239 + case TFClass_Scout:
1.240 + {
1.241 + TF2_GivePlayerWeapon(client, "tf_weapon_scattergun");
1.242 + TF2_GivePlayerWeapon(client, "tf_weapon_pistol_scout");
1.243 + TF2_GivePlayerWeapon(client, "tf_weapon_bat");
1.244 + }
1.245 + case TFClass_Sniper:
1.246 + {
1.247 + TF2_GivePlayerWeapon(client, "tf_weapon_sniperrifle");
1.248 + TF2_GivePlayerWeapon(client, "tf_weapon_smg");
1.249 + TF2_GivePlayerWeapon(client, "tf_weapon_club");
1.250 + }
1.251 + case TFClass_Soldier:
1.252 + {
1.253 + TF2_GivePlayerWeapon(client, "tf_weapon_rocketlauncher");
1.254 + TF2_GivePlayerWeapon(client, "tf_weapon_shotgun_soldier");
1.255 + TF2_GivePlayerWeapon(client, "tf_weapon_shovel");
1.256 + }
1.257 + case TFClass_DemoMan:
1.258 + {
1.259 + TF2_GivePlayerWeapon(client, "tf_weapon_pipebomblauncher");
1.260 + TF2_GivePlayerWeapon(client, "tf_weapon_grenadelauncher");
1.261 + TF2_GivePlayerWeapon(client, "tf_weapon_bottle");
1.262 + }
1.263 + case TFClass_Medic:
1.264 + {
1.265 + TF2_GivePlayerWeapon(client, "tf_weapon_syringegun_medic");
1.266 + TF2_GivePlayerWeapon(client, "tf_weapon_medigun");
1.267 + TF2_GivePlayerWeapon(client, "tf_weapon_bonesaw");
1.268 + }
1.269 + case TFClass_Heavy:
1.270 + {
1.271 + TF2_GivePlayerWeapon(client, "tf_weapon_minigun");
1.272 + TF2_GivePlayerWeapon(client, "tf_weapon_shotgun_hwg");
1.273 + TF2_GivePlayerWeapon(client, "tf_weapon_fists");
1.274 + }
1.275 + case TFClass_Pyro:
1.276 + {
1.277 + TF2_GivePlayerWeapon(client, "tf_weapon_flamethrower");
1.278 + TF2_GivePlayerWeapon(client, "tf_weapon_shotgun_pyro");
1.279 + TF2_GivePlayerWeapon(client, "tf_weapon_fireaxe");
1.280 + }
1.281 + case TFClass_Spy:
1.282 + {
1.283 + TF2_GivePlayerWeapon(client, "tf_weapon_revolver");
1.284 + TF2_GivePlayerWeapon(client, "tf_weapon_knife");
1.285 +
1.286 + if (TF2_GetPlayerClass(client) != TFClass_Spy)
1.287 + return;
1.288 +
1.289 + TF2_GivePlayerWeapon(client, "tf_weapon_pda_spy");
1.290 + }
1.291 + case TFClass_Engineer:
1.292 + {
1.293 + TF2_GivePlayerWeapon(client, "tf_weapon_shotgun_primary");
1.294 + TF2_GivePlayerWeapon(client, "tf_weapon_pistol");
1.295 + TF2_GivePlayerWeapon(client, "tf_weapon_wrench");
1.296 +
1.297 + if (TF2_GetPlayerClass(client) != TFClass_Engineer)
1.298 + return;
1.299 +
1.300 + TF2_GivePlayerWeapon(client, "tf_weapon_pda_engineer_build");
1.301 + TF2_GivePlayerWeapon(client, "tf_weapon_pda_engineer_destroy");
1.302 + }
1.303 + }
1.304 +}
1.305 \ No newline at end of file