plugins/include/tf2_stocks.inc
author Fyren <fyrenmoo@gmail.com>
Sun Mar 01 16:48:55 2009 -0500 (2009-03-01)
changeset 2639 021fbd7a8cf6
parent 2566 33656d9247c4
child 2943 1bbdb33fee53
permissions -rw-r--r--
Improved docs of TIMER_HNDL_CLOSE (bug 3641, r=dvander).
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
     5  * =============================================================================
     6  *
     7  * This file is part of the SourceMod/SourcePawn SDK.
     8  *
     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.
    12  * 
    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
    16  * details.
    17  *
    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/>.
    20  *
    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>.
    29  *
    30  * Version: $Id$
    31  */
    32 
    33 #if defined _tf2_stocks_included
    34  #endinput
    35 #endif
    36 #define _tf2_stocks_included
    37 
    38 #include <tf2>
    39 #include <sdktools>
    40 
    41 enum TFResourceType
    42 {
    43 	TFResource_Ping,
    44 	TFResource_Score,
    45 	TFResource_Deaths,
    46 	TFResource_TotalScore, 
    47 	TFResource_Captures,
    48 	TFResource_Defenses,
    49 	TFResource_Dominations,
    50 	TFResource_Revenge,
    51 	TFResource_BuildingsDestroyed, 
    52 	TFResource_Headshots,
    53 	TFResource_Backstabs,
    54 	TFResource_HealPoints,
    55 	TFResource_Invulns,
    56 	TFResource_Teleports,
    57 	TFResource_ResupplyPoints,
    58 	TFResource_KillAssists,
    59 	TFResource_MaxHealth,
    60 	TFResource_PlayerClass
    61 };
    62 
    63 static const String:TFResourceNames[TFResourceType][] =
    64 {
    65 	"m_iPing",
    66 	"m_iScore",
    67 	"m_iDeaths",
    68 	"m_iTotalScore",
    69 	"m_iCaptures",
    70 	"m_iDefenses",
    71 	"m_iDominations",
    72 	"m_iRevenge",
    73 	"m_iBuildingsDestroyed",
    74 	"m_iHeadshots",
    75 	"m_iBackstabs",
    76 	"m_iHealPoints",
    77 	"m_iInvulns",
    78 	"m_iTeleports",
    79 	"m_iResupplyPoints",
    80 	"m_iKillAssists",
    81 	"m_iMaxHealth",
    82 	"m_iPlayerClass"
    83 };
    84 
    85 /**
    86  * Get's a Clients current class.
    87  *
    88  * @param client		Player's index.
    89  * @return				Current TFClassType of player.
    90  * @error				Invalid client index.
    91  */
    92 stock TFClassType:TF2_GetPlayerClass(client)
    93 {
    94 	return TFClassType:GetEntProp(client, Prop_Send, "m_iClass");
    95 }
    96 
    97 /**
    98  * Set's a Clients class.
    99  *
   100  * Note: If setting player class in a player spawn hook weapons should be set to false.
   101  *
   102  * @param client		Player's index.
   103  * @param class			TFClassType class symbol.
   104  * @param weapons		This paramater is ignored.
   105  * @param persistant	If true changes the players desired class so the change stays after death.
   106  * @noreturn
   107  * @error				Invalid client index.
   108  */
   109 stock TF2_SetPlayerClass(client, TFClassType:class, bool:weapons=true, bool:persistant=true)
   110 {
   111 	SetEntProp(client, Prop_Send, "m_iClass", _:class);
   112 	
   113 	if (persistant)
   114 	{
   115 		SetEntProp(client, Prop_Send, "m_iDesiredPlayerClass", _:class);
   116 	}
   117 }
   118 
   119 /**
   120  * Retrieves client data from the resource entity
   121  *
   122  * @param client		Player's index.
   123  * @param type			ResourceType constant
   124  * @return				Value or -1 on failure.
   125  * @error				Invalid client index, client not in game or failed to find resource entity.
   126  */
   127 stock TF2_GetPlayerResourceData(client, TFResourceType:type)
   128 {
   129 	if (!IsClientConnected(client))
   130 	{
   131 		return -1;	
   132 	}
   133 	
   134 	new offset = FindSendPropInfo("CTFPlayerResource", TFResourceNames[type]);
   135 		
   136 	if (offset < 1)
   137 	{
   138 		return -1;	
   139 	}
   140 				
   141 	new entity = TF2_GetResourceEntity();
   142 	
   143 	if (entity == -1)
   144 	{
   145 		return -1;
   146 	}
   147 	
   148 	return GetEntData(entity, offset + (client*4));
   149 }
   150 
   151 /**
   152  * Sets client data in the resource entity
   153  *
   154  * Note: The game overwrites these values every frame, so changing them will have very little effect.
   155  *
   156  * @param client		Player's index.
   157  * @param type			ResourceType constant
   158  * @param value			Value to set.
   159  * @return				Value or -1 on failure.
   160  * @error				Invalid client index, client not in game or failed to find resource entity.
   161  */
   162 stock bool:TF2_SetPlayerResourceData(client, TFResourceType:type, any:value)
   163 {
   164 	if (!IsClientConnected(client))
   165 	{
   166 		return false;	
   167 	}
   168 	
   169 	new offset = FindSendPropInfo("CTFPlayerResource", TFResourceNames[type]);
   170 						
   171 	if (offset < 1)
   172 	{
   173 		return false;	
   174 	}
   175 				
   176 	new entity = TF2_GetResourceEntity();
   177 	
   178 	if (entity == -1)
   179 	{
   180 		return false;	
   181 	}
   182 	
   183 	SetEntData(entity, offset + (client*4), value);
   184 	
   185 	return true;	
   186 }
   187 
   188 /**
   189  * Removes all weapons from a client's weapon slot
   190  *
   191  * @param client		Player's index.
   192  * @param slot			Slot index (0-5)
   193  * @noreturn
   194  * @error				Invalid client, invalid slot or lack of mod support
   195  */
   196 stock TF2_RemoveWeaponSlot(client, slot)
   197 {
   198 	new weaponIndex;
   199 	while ((weaponIndex = GetPlayerWeaponSlot(client, slot)) != -1)
   200 	{
   201 		RemovePlayerItem(client, weaponIndex);
   202 		RemoveEdict(weaponIndex);
   203 	}
   204 }
   205 
   206 /**
   207  * Removes all weapons from a client
   208  *
   209  * @param client		Player's index.
   210  * @noreturn
   211  */
   212 stock TF2_RemoveAllWeapons(client)
   213 {
   214 	for (new i = 0; i <= 5; i++)
   215 	{
   216 		TF2_RemoveWeaponSlot(client, i);
   217 	}
   218 }
   219