plugins/include/tf2_stocks.inc
author Erik Minekus <erik@interwavestudios.com>
Fri Jul 23 21:23:35 2010 -0400 (2010-07-23)
changeset 3093 0d28a05141b3
parent 3087 56cf2014655f
child 3125 5788be8f69bd
permissions -rw-r--r--
Added TF2 object stocks (bug 4536, r=psychonic).
milo@2566
     1
/**
milo@2566
     2
 * vim: set ts=4 :
milo@2566
     3
 * =============================================================================
milo@2566
     4
 * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
milo@2566
     5
 * =============================================================================
milo@2566
     6
 *
milo@2566
     7
 * This file is part of the SourceMod/SourcePawn SDK.
milo@2566
     8
 *
milo@2566
     9
 * This program is free software; you can redistribute it and/or modify it under
milo@2566
    10
 * the terms of the GNU General Public License, version 3.0, as published by the
milo@2566
    11
 * Free Software Foundation.
milo@2566
    12
 * 
milo@2566
    13
 * This program is distributed in the hope that it will be useful, but WITHOUT
milo@2566
    14
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
milo@2566
    15
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
milo@2566
    16
 * details.
milo@2566
    17
 *
milo@2566
    18
 * You should have received a copy of the GNU General Public License along with
milo@2566
    19
 * this program.  If not, see <http://www.gnu.org/licenses/>.
milo@2566
    20
 *
milo@2566
    21
 * As a special exception, AlliedModders LLC gives you permission to link the
milo@2566
    22
 * code of this program (as well as its derivative works) to "Half-Life 2," the
milo@2566
    23
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
milo@2566
    24
 * by the Valve Corporation.  You must obey the GNU General Public License in
milo@2566
    25
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
milo@2566
    26
 * this exception to all derivative works.  AlliedModders LLC defines further
milo@2566
    27
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
milo@2566
    28
 * or <http://www.sourcemod.net/license.php>.
milo@2566
    29
 *
milo@2566
    30
 * Version: $Id$
milo@2566
    31
 */
milo@2566
    32
milo@2566
    33
#if defined _tf2_stocks_included
milo@2566
    34
 #endinput
milo@2566
    35
#endif
milo@2566
    36
#define _tf2_stocks_included
milo@2566
    37
milo@2566
    38
#include <tf2>
milo@2566
    39
#include <sdktools>
milo@2566
    40
skamonkey@2943
    41
#define TF_CONDFLAG_NONE            0
skamonkey@2943
    42
#define TF_CONDFLAG_SLOWED          (1 << 0)
skamonkey@2943
    43
#define TF_CONDFLAG_ZOOMED          (1 << 1)
skamonkey@2943
    44
#define TF_CONDFLAG_DISGUISING      (1 << 2)
skamonkey@2943
    45
#define TF_CONDFLAG_DISGUISED       (1 << 3)
skamonkey@2943
    46
#define TF_CONDFLAG_CLOAKED         (1 << 4)
skamonkey@2943
    47
#define TF_CONDFLAG_UBERCHARGED     (1 << 5)
skamonkey@2943
    48
#define TF_CONDFLAG_TELEPORTGLOW    (1 << 6)
skamonkey@2943
    49
#define TF_CONDFLAG_TAUNTING        (1 << 7)
skamonkey@2943
    50
#define TF_CONDFLAG_UBERCHARGEFADE  (1 << 8)
skamonkey@2943
    51
#define TF_CONDFLAG_TELEPORTING     (1 << 10)
skamonkey@2943
    52
#define TF_CONDFLAG_KRITZKRIEGED    (1 << 11)
skamonkey@2943
    53
#define TF_CONDFLAG_DEADRINGERED    (1 << 13)
skamonkey@2943
    54
#define TF_CONDFLAG_BONKED          (1 << 14)
skamonkey@2943
    55
#define TF_CONDFLAG_DAZED           (1 << 15)
skamonkey@2943
    56
#define TF_CONDFLAG_BUFFED          (1 << 16)
skamonkey@2943
    57
#define TF_CONDFLAG_CHARGING        (1 << 17)
skamonkey@2943
    58
#define TF_CONDFLAG_DEMOBUFF        (1 << 18)
skamonkey@3044
    59
#define TF_CONDFLAG_CRITCOLA        (1 << 19)
skamonkey@3044
    60
#define TF_CONDFLAG_HEALING         (1 << 20)
skamonkey@3087
    61
#define TF_CONDFLAG_ONFIRE          (1 << 22)
skamonkey@3087
    62
#define TF_CONDFLAG_OVERHEALED      (1 << 23)
skamonkey@3087
    63
#define TF_CONDFLAG_JARATED         (1 << 24)
skamonkey@3087
    64
#define TF_CONDFLAG_BLEEDING        (1 << 25)
skamonkey@2943
    65
skamonkey@2943
    66
#define TF_DEATHFLAG_KILLERDOMINATION   (1 << 0)
skamonkey@2943
    67
#define TF_DEATHFLAG_ASSISTERDOMINATION (1 << 1)
skamonkey@2943
    68
#define TF_DEATHFLAG_KILLERREVENGE      (1 << 2)
skamonkey@2943
    69
#define TF_DEATHFLAG_ASSISTERREVENGE    (1 << 3)
skamonkey@2943
    70
#define TF_DEATHFLAG_FIRSTBLOOD         (1 << 4)
skamonkey@2943
    71
#define TF_DEATHFLAG_DEADRINGER         (1 << 5)
skamonkey@2943
    72
milo@2566
    73
enum TFResourceType
milo@2566
    74
{
milo@2566
    75
	TFResource_Ping,
milo@2566
    76
	TFResource_Score,
milo@2566
    77
	TFResource_Deaths,
milo@2566
    78
	TFResource_TotalScore, 
milo@2566
    79
	TFResource_Captures,
milo@2566
    80
	TFResource_Defenses,
milo@2566
    81
	TFResource_Dominations,
milo@2566
    82
	TFResource_Revenge,
milo@2566
    83
	TFResource_BuildingsDestroyed, 
milo@2566
    84
	TFResource_Headshots,
milo@2566
    85
	TFResource_Backstabs,
milo@2566
    86
	TFResource_HealPoints,
milo@2566
    87
	TFResource_Invulns,
milo@2566
    88
	TFResource_Teleports,
milo@2566
    89
	TFResource_ResupplyPoints,
milo@2566
    90
	TFResource_KillAssists,
milo@2566
    91
	TFResource_MaxHealth,
milo@2566
    92
	TFResource_PlayerClass
milo@2566
    93
};
milo@2566
    94
milo@2566
    95
static const String:TFResourceNames[TFResourceType][] =
milo@2566
    96
{
milo@2566
    97
	"m_iPing",
milo@2566
    98
	"m_iScore",
milo@2566
    99
	"m_iDeaths",
milo@2566
   100
	"m_iTotalScore",
milo@2566
   101
	"m_iCaptures",
milo@2566
   102
	"m_iDefenses",
milo@2566
   103
	"m_iDominations",
milo@2566
   104
	"m_iRevenge",
milo@2566
   105
	"m_iBuildingsDestroyed",
milo@2566
   106
	"m_iHeadshots",
milo@2566
   107
	"m_iBackstabs",
milo@2566
   108
	"m_iHealPoints",
milo@2566
   109
	"m_iInvulns",
milo@2566
   110
	"m_iTeleports",
milo@2566
   111
	"m_iResupplyPoints",
milo@2566
   112
	"m_iKillAssists",
milo@2566
   113
	"m_iMaxHealth",
milo@2566
   114
	"m_iPlayerClass"
milo@2566
   115
};
milo@2566
   116
milo@2566
   117
/**
milo@2566
   118
 * Get's a Clients current class.
milo@2566
   119
 *
milo@2566
   120
 * @param client		Player's index.
milo@2566
   121
 * @return				Current TFClassType of player.
milo@2566
   122
 * @error				Invalid client index.
milo@2566
   123
 */
milo@2566
   124
stock TFClassType:TF2_GetPlayerClass(client)
milo@2566
   125
{
milo@2566
   126
	return TFClassType:GetEntProp(client, Prop_Send, "m_iClass");
milo@2566
   127
}
milo@2566
   128
milo@2566
   129
/**
milo@2566
   130
 * Set's a Clients class.
milo@2566
   131
 *
milo@2566
   132
 * Note: If setting player class in a player spawn hook weapons should be set to false.
milo@2566
   133
 *
milo@2566
   134
 * @param client		Player's index.
milo@2566
   135
 * @param class			TFClassType class symbol.
milo@2566
   136
 * @param weapons		This paramater is ignored.
milo@2566
   137
 * @param persistant	If true changes the players desired class so the change stays after death.
milo@2566
   138
 * @noreturn
milo@2566
   139
 * @error				Invalid client index.
milo@2566
   140
 */
milo@2566
   141
stock TF2_SetPlayerClass(client, TFClassType:class, bool:weapons=true, bool:persistant=true)
milo@2566
   142
{
milo@2566
   143
	SetEntProp(client, Prop_Send, "m_iClass", _:class);
milo@2566
   144
	
milo@2566
   145
	if (persistant)
milo@2566
   146
	{
milo@2566
   147
		SetEntProp(client, Prop_Send, "m_iDesiredPlayerClass", _:class);
milo@2566
   148
	}
milo@2566
   149
}
milo@2566
   150
milo@2566
   151
/**
milo@2566
   152
 * Retrieves client data from the resource entity
milo@2566
   153
 *
milo@2566
   154
 * @param client		Player's index.
milo@2566
   155
 * @param type			ResourceType constant
milo@2566
   156
 * @return				Value or -1 on failure.
milo@2566
   157
 * @error				Invalid client index, client not in game or failed to find resource entity.
milo@2566
   158
 */
milo@2566
   159
stock TF2_GetPlayerResourceData(client, TFResourceType:type)
milo@2566
   160
{
milo@2566
   161
	if (!IsClientConnected(client))
milo@2566
   162
	{
milo@2566
   163
		return -1;	
milo@2566
   164
	}
milo@2566
   165
	
milo@2566
   166
	new offset = FindSendPropInfo("CTFPlayerResource", TFResourceNames[type]);
milo@2566
   167
		
milo@2566
   168
	if (offset < 1)
milo@2566
   169
	{
milo@2566
   170
		return -1;	
milo@2566
   171
	}
milo@2566
   172
				
milo@2566
   173
	new entity = TF2_GetResourceEntity();
milo@2566
   174
	
milo@2566
   175
	if (entity == -1)
milo@2566
   176
	{
milo@2566
   177
		return -1;
milo@2566
   178
	}
milo@2566
   179
	
milo@2566
   180
	return GetEntData(entity, offset + (client*4));
milo@2566
   181
}
milo@2566
   182
milo@2566
   183
/**
milo@2566
   184
 * Sets client data in the resource entity
milo@2566
   185
 *
milo@2566
   186
 * Note: The game overwrites these values every frame, so changing them will have very little effect.
milo@2566
   187
 *
milo@2566
   188
 * @param client		Player's index.
milo@2566
   189
 * @param type			ResourceType constant
milo@2566
   190
 * @param value			Value to set.
milo@2566
   191
 * @return				Value or -1 on failure.
milo@2566
   192
 * @error				Invalid client index, client not in game or failed to find resource entity.
milo@2566
   193
 */
milo@2566
   194
stock bool:TF2_SetPlayerResourceData(client, TFResourceType:type, any:value)
milo@2566
   195
{
milo@2566
   196
	if (!IsClientConnected(client))
milo@2566
   197
	{
milo@2566
   198
		return false;	
milo@2566
   199
	}
milo@2566
   200
	
milo@2566
   201
	new offset = FindSendPropInfo("CTFPlayerResource", TFResourceNames[type]);
milo@2566
   202
						
milo@2566
   203
	if (offset < 1)
milo@2566
   204
	{
milo@2566
   205
		return false;	
milo@2566
   206
	}
milo@2566
   207
				
milo@2566
   208
	new entity = TF2_GetResourceEntity();
milo@2566
   209
	
milo@2566
   210
	if (entity == -1)
milo@2566
   211
	{
milo@2566
   212
		return false;	
milo@2566
   213
	}
milo@2566
   214
	
milo@2566
   215
	SetEntData(entity, offset + (client*4), value);
milo@2566
   216
	
milo@2566
   217
	return true;	
milo@2566
   218
}
milo@2566
   219
milo@2566
   220
/**
milo@2566
   221
 * Removes all weapons from a client's weapon slot
milo@2566
   222
 *
milo@2566
   223
 * @param client		Player's index.
milo@2566
   224
 * @param slot			Slot index (0-5)
milo@2566
   225
 * @noreturn
milo@2566
   226
 * @error				Invalid client, invalid slot or lack of mod support
milo@2566
   227
 */
milo@2566
   228
stock TF2_RemoveWeaponSlot(client, slot)
milo@2566
   229
{
milo@2566
   230
	new weaponIndex;
milo@2566
   231
	while ((weaponIndex = GetPlayerWeaponSlot(client, slot)) != -1)
milo@2566
   232
	{
milo@2566
   233
		RemovePlayerItem(client, weaponIndex);
milo@2566
   234
		RemoveEdict(weaponIndex);
milo@2566
   235
	}
milo@2566
   236
}
milo@2566
   237
milo@2566
   238
/**
milo@2566
   239
 * Removes all weapons from a client
milo@2566
   240
 *
milo@2566
   241
 * @param client		Player's index.
milo@2566
   242
 * @noreturn
milo@2566
   243
 */
milo@2566
   244
stock TF2_RemoveAllWeapons(client)
milo@2566
   245
{
milo@2566
   246
	for (new i = 0; i <= 5; i++)
milo@2566
   247
	{
milo@2566
   248
		TF2_RemoveWeaponSlot(client, i);
milo@2566
   249
	}
milo@2566
   250
}
milo@2566
   251
skamonkey@2943
   252
/**
skamonkey@2943
   253
 * Gets a player's condition bits
skamonkey@2943
   254
 *
skamonkey@2943
   255
 * @param client		Player's index.
skamonkey@2943
   256
 * @return				Player's condition bits
skamonkey@2943
   257
 */
skamonkey@2943
   258
stock TF2_GetPlayerConditionFlags(client)
skamonkey@2943
   259
{
skamonkey@2943
   260
	return GetEntProp(client, Prop_Send, "m_nPlayerCond");
skamonkey@2943
   261
}
erik@3093
   262
erik@3093
   263
/**
erik@3093
   264
 * Gets an entity's object type.
erik@3093
   265
 *
erik@3093
   266
 * @param entity		Entity index.
erik@3093
   267
 * @return				Current TFObjectType of entity.
erik@3093
   268
 * @error				Invalid entity index.
erik@3093
   269
 */
erik@3093
   270
stock TFObjectType:TF2_GetObjectType(entity)
erik@3093
   271
{
erik@3093
   272
	new offset = GetEntSendPropOffs(entity, "m_iObjectType");
erik@3093
   273
	
erik@3093
   274
	if (offset <= 0)
erik@3093
   275
	{
erik@3093
   276
		ThrowError("Entity index %d is not an object", entity);
erik@3093
   277
	}
erik@3093
   278
	
erik@3093
   279
	return TFObjectType:GetEntData(entity, offset);
erik@3093
   280
}
erik@3093
   281
erik@3093
   282
/**
erik@3093
   283
 * Gets an entity's object mode.
erik@3093
   284
 *
erik@3093
   285
 * @param entity		Entity index.
erik@3093
   286
 * @return				Current TFObjectMode of entity.
erik@3093
   287
 * @error				Invalid entity index.
erik@3093
   288
 */
erik@3093
   289
stock TFObjectMode:TF2_GetObjectMode(entity)
erik@3093
   290
{
erik@3093
   291
	new offset = GetEntSendPropOffs(entity, "m_iObjectMode");
erik@3093
   292
	
erik@3093
   293
	if (offset <= 0)
erik@3093
   294
	{
erik@3093
   295
		ThrowError("Entity index %d is not an object", entity);
erik@3093
   296
	}
erik@3093
   297
	
erik@3093
   298
	return TFObjectMode:GetEntData(entity, offset);
erik@3093
   299
}