1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/plugins/include/tf2_stocks.inc Sun Jul 06 04:49:55 2008 +0000
1.3 @@ -0,0 +1,219 @@
1.4 +/**
1.5 + * vim: set ts=4 :
1.6 + * =============================================================================
1.7 + * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
1.8 + * =============================================================================
1.9 + *
1.10 + * This file is part of the SourceMod/SourcePawn SDK.
1.11 + *
1.12 + * This program is free software; you can redistribute it and/or modify it under
1.13 + * the terms of the GNU General Public License, version 3.0, as published by the
1.14 + * Free Software Foundation.
1.15 + *
1.16 + * This program is distributed in the hope that it will be useful, but WITHOUT
1.17 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.18 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.19 + * details.
1.20 + *
1.21 + * You should have received a copy of the GNU General Public License along with
1.22 + * this program. If not, see <http://www.gnu.org/licenses/>.
1.23 + *
1.24 + * As a special exception, AlliedModders LLC gives you permission to link the
1.25 + * code of this program (as well as its derivative works) to "Half-Life 2," the
1.26 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
1.27 + * by the Valve Corporation. You must obey the GNU General Public License in
1.28 + * all respects for all other code used. Additionally, AlliedModders LLC grants
1.29 + * this exception to all derivative works. AlliedModders LLC defines further
1.30 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
1.31 + * or <http://www.sourcemod.net/license.php>.
1.32 + *
1.33 + * Version: $Id$
1.34 + */
1.35 +
1.36 +#if defined _tf2_stocks_included
1.37 + #endinput
1.38 +#endif
1.39 +#define _tf2_stocks_included
1.40 +
1.41 +#include <tf2>
1.42 +#include <sdktools>
1.43 +
1.44 +enum TFResourceType
1.45 +{
1.46 + TFResource_Ping,
1.47 + TFResource_Score,
1.48 + TFResource_Deaths,
1.49 + TFResource_TotalScore,
1.50 + TFResource_Captures,
1.51 + TFResource_Defenses,
1.52 + TFResource_Dominations,
1.53 + TFResource_Revenge,
1.54 + TFResource_BuildingsDestroyed,
1.55 + TFResource_Headshots,
1.56 + TFResource_Backstabs,
1.57 + TFResource_HealPoints,
1.58 + TFResource_Invulns,
1.59 + TFResource_Teleports,
1.60 + TFResource_ResupplyPoints,
1.61 + TFResource_KillAssists,
1.62 + TFResource_MaxHealth,
1.63 + TFResource_PlayerClass
1.64 +};
1.65 +
1.66 +static const String:TFResourceNames[TFResourceType][] =
1.67 +{
1.68 + "m_iPing",
1.69 + "m_iScore",
1.70 + "m_iDeaths",
1.71 + "m_iTotalScore",
1.72 + "m_iCaptures",
1.73 + "m_iDefenses",
1.74 + "m_iDominations",
1.75 + "m_iRevenge",
1.76 + "m_iBuildingsDestroyed",
1.77 + "m_iHeadshots",
1.78 + "m_iBackstabs",
1.79 + "m_iHealPoints",
1.80 + "m_iInvulns",
1.81 + "m_iTeleports",
1.82 + "m_iResupplyPoints",
1.83 + "m_iKillAssists",
1.84 + "m_iMaxHealth",
1.85 + "m_iPlayerClass"
1.86 +};
1.87 +
1.88 +/**
1.89 + * Get's a Clients current class.
1.90 + *
1.91 + * @param client Player's index.
1.92 + * @param class TFClassType to change to.
1.93 + * @noreturn
1.94 + * @error Invalid client index.
1.95 + */
1.96 +stock TFClassType:TF2_GetPlayerClass(client)
1.97 +{
1.98 + return TFClassType:GetEntProp(client, Prop_Send, "m_iClass");
1.99 +}
1.100 +
1.101 +/**
1.102 + * Set's a Clients class.
1.103 + *
1.104 + * Note: If setting player class in a player spawn hook weapons should be set to false.
1.105 + *
1.106 + * @param client Player's index.
1.107 + * @param class TFClassType class symbol.
1.108 + * @param weapons This paramater is ignored.
1.109 + * @param persistant If true changes the players desired class so the change stays after death.
1.110 + * @noreturn
1.111 + * @error Invalid client index.
1.112 + */
1.113 +stock TF2_SetPlayerClass(client, TFClassType:class, bool:weapons=true, bool:persistant=true)
1.114 +{
1.115 + SetEntProp(client, Prop_Send, "m_iClass", _:class);
1.116 +
1.117 + if (persistant)
1.118 + {
1.119 + SetEntProp(client, Prop_Send, "m_iDesiredPlayerClass", _:class);
1.120 + }
1.121 +}
1.122 +
1.123 +/**
1.124 + * Retrieves client data from the resource entity
1.125 + *
1.126 + * @param client Player's index.
1.127 + * @param type ResourceType constant
1.128 + * @return Value or -1 on failure.
1.129 + * @error Invalid client index, client not in game or failed to find resource entity.
1.130 + */
1.131 +stock TF2_GetPlayerResourceData(client, TFResourceType:type)
1.132 +{
1.133 + if (!IsClientConnected(client))
1.134 + {
1.135 + return -1;
1.136 + }
1.137 +
1.138 + new offset = FindSendPropInfo("CTFPlayerResource", TFResourceNames[type]);
1.139 +
1.140 + if (offset < 1)
1.141 + {
1.142 + return -1;
1.143 + }
1.144 +
1.145 + new entity = TF2_GetResourceEntity();
1.146 +
1.147 + if (entity == -1)
1.148 + {
1.149 + return -1;
1.150 + }
1.151 +
1.152 + return GetEntData(entity, offset + (client*4));
1.153 +}
1.154 +
1.155 +/**
1.156 + * Sets client data in the resource entity
1.157 + *
1.158 + * Note: The game overwrites these values every frame, so changing them will have very little effect.
1.159 + *
1.160 + * @param client Player's index.
1.161 + * @param type ResourceType constant
1.162 + * @param value Value to set.
1.163 + * @return Value or -1 on failure.
1.164 + * @error Invalid client index, client not in game or failed to find resource entity.
1.165 + */
1.166 +stock bool:TF2_SetPlayerResourceData(client, TFResourceType:type, any:value)
1.167 +{
1.168 + if (!IsClientConnected(client))
1.169 + {
1.170 + return false;
1.171 + }
1.172 +
1.173 + new offset = FindSendPropInfo("CTFPlayerResource", TFResourceNames[type]);
1.174 +
1.175 + if (offset < 1)
1.176 + {
1.177 + return false;
1.178 + }
1.179 +
1.180 + new entity = TF2_GetResourceEntity();
1.181 +
1.182 + if (entity == -1)
1.183 + {
1.184 + return false;
1.185 + }
1.186 +
1.187 + SetEntData(entity, offset + (client*4), value);
1.188 +
1.189 + return true;
1.190 +}
1.191 +
1.192 +/**
1.193 + * Removes all weapons from a client's weapon slot
1.194 + *
1.195 + * @param client Player's index.
1.196 + * @param slot Slot index (0-5)
1.197 + * @noreturn
1.198 + * @error Invalid client, invalid slot or lack of mod support
1.199 + */
1.200 +stock TF2_RemoveWeaponSlot(client, slot)
1.201 +{
1.202 + new weaponIndex;
1.203 + while ((weaponIndex = GetPlayerWeaponSlot(client, slot)) != -1)
1.204 + {
1.205 + RemovePlayerItem(client, weaponIndex);
1.206 + RemoveEdict(weaponIndex);
1.207 + }
1.208 +}
1.209 +
1.210 +/**
1.211 + * Removes all weapons from a client
1.212 + *
1.213 + * @param client Player's index.
1.214 + * @noreturn
1.215 + */
1.216 +stock TF2_RemoveAllWeapons(client)
1.217 +{
1.218 + for (new i = 0; i <= 5; i++)
1.219 + {
1.220 + TF2_RemoveWeaponSlot(client, i);
1.221 + }
1.222 +}