plugins/include/tf2_stocks.inc
author Scott Ehlert <ds@alliedmods.net>
Fri Nov 14 09:18:30 2008 -0600 (2008-11-14)
changeset 2400 76b7b4575e21
parent 2102 1c4c5743c411
child 2566 33656d9247c4
permissions -rw-r--r--
Added preliminary support for Left 4 Dead; some things may not yet work.
pred@1964
     1
/**
pred@1964
     2
 * vim: set ts=4 :
pred@1964
     3
 * =============================================================================
pred@1964
     4
 * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
pred@1964
     5
 * =============================================================================
pred@1964
     6
 *
pred@1964
     7
 * This file is part of the SourceMod/SourcePawn SDK.
pred@1964
     8
 *
pred@1964
     9
 * This program is free software; you can redistribute it and/or modify it under
pred@1964
    10
 * the terms of the GNU General Public License, version 3.0, as published by the
pred@1964
    11
 * Free Software Foundation.
pred@1964
    12
 * 
pred@1964
    13
 * This program is distributed in the hope that it will be useful, but WITHOUT
pred@1964
    14
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
pred@1964
    15
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
pred@1964
    16
 * details.
pred@1964
    17
 *
pred@1964
    18
 * You should have received a copy of the GNU General Public License along with
pred@1964
    19
 * this program.  If not, see <http://www.gnu.org/licenses/>.
pred@1964
    20
 *
pred@1964
    21
 * As a special exception, AlliedModders LLC gives you permission to link the
pred@1964
    22
 * code of this program (as well as its derivative works) to "Half-Life 2," the
pred@1964
    23
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
pred@1964
    24
 * by the Valve Corporation.  You must obey the GNU General Public License in
pred@1964
    25
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
pred@1964
    26
 * this exception to all derivative works.  AlliedModders LLC defines further
pred@1964
    27
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
pred@1964
    28
 * or <http://www.sourcemod.net/license.php>.
pred@1964
    29
 *
ds@1987
    30
 * Version: $Id$
pred@1964
    31
 */
pred@1964
    32
pred@1963
    33
#if defined _tf2_stocks_included
pred@1963
    34
 #endinput
pred@1963
    35
#endif
pred@1963
    36
#define _tf2_stocks_included
pred@1963
    37
pred@1963
    38
#include <tf2>
pred@1963
    39
#include <sdktools>
pred@1963
    40
pred@1963
    41
enum TFResourceType
pred@1963
    42
{
pred@1963
    43
	TFResource_Ping,
pred@1963
    44
	TFResource_Score,
pred@1963
    45
	TFResource_Deaths,
pred@1963
    46
	TFResource_TotalScore, 
pred@1963
    47
	TFResource_Captures,
pred@1963
    48
	TFResource_Defenses,
pred@1963
    49
	TFResource_Dominations,
pred@1963
    50
	TFResource_Revenge,
pred@1963
    51
	TFResource_BuildingsDestroyed, 
pred@1963
    52
	TFResource_Headshots,
pred@1963
    53
	TFResource_Backstabs,
pred@1963
    54
	TFResource_HealPoints,
pred@1963
    55
	TFResource_Invulns,
pred@1963
    56
	TFResource_Teleports,
pred@1963
    57
	TFResource_ResupplyPoints,
pred@1963
    58
	TFResource_KillAssists,
pred@1963
    59
	TFResource_MaxHealth,
pred@1963
    60
	TFResource_PlayerClass
pred@1963
    61
};
pred@1963
    62
pred@1963
    63
static const String:TFResourceNames[TFResourceType][] =
pred@1963
    64
{
pred@1963
    65
	"m_iPing",
pred@1963
    66
	"m_iScore",
pred@1963
    67
	"m_iDeaths",
pred@1963
    68
	"m_iTotalScore",
pred@1963
    69
	"m_iCaptures",
pred@1963
    70
	"m_iDefenses",
pred@1963
    71
	"m_iDominations",
pred@1963
    72
	"m_iRevenge",
pred@1963
    73
	"m_iBuildingsDestroyed",
pred@1963
    74
	"m_iHeadshots",
pred@1963
    75
	"m_iBackstabs",
pred@1963
    76
	"m_iHealPoints",
pred@1963
    77
	"m_iInvulns",
pred@1963
    78
	"m_iTeleports",
pred@1963
    79
	"m_iResupplyPoints",
pred@1963
    80
	"m_iKillAssists",
pred@1963
    81
	"m_iMaxHealth",
pred@1963
    82
	"m_iPlayerClass"
pred@1963
    83
};
pred@1963
    84
pred@1963
    85
/**
pred@1963
    86
 * Get's a Clients current class.
pred@1963
    87
 *
pred@1963
    88
 * @param client		Player's index.
pred@1963
    89
 * @param class			TFClassType to change to.
pred@1963
    90
 * @noreturn
pred@1963
    91
 * @error				Invalid client index.
pred@1963
    92
 */
pred@1963
    93
stock TFClassType:TF2_GetPlayerClass(client)
pred@1963
    94
{
pred@1963
    95
	return TFClassType:GetEntProp(client, Prop_Send, "m_iClass");
pred@1963
    96
}
pred@1963
    97
pred@1963
    98
/**
pred@1963
    99
 * Set's a Clients class.
pred@1963
   100
 *
pred@1988
   101
 * Note: If setting player class in a player spawn hook weapons should be set to false.
pred@1988
   102
 *
pred@1963
   103
 * @param client		Player's index.
pred@1963
   104
 * @param class			TFClassType class symbol.
ds@2102
   105
 * @param weapons		This paramater is ignored.
pred@2005
   106
 * @param persistant	If true changes the players desired class so the change stays after death.
pred@1963
   107
 * @noreturn
pred@1963
   108
 * @error				Invalid client index.
pred@1963
   109
 */
pred@2005
   110
stock TF2_SetPlayerClass(client, TFClassType:class, bool:weapons=true, bool:persistant=true)
pred@1963
   111
{
pred@1963
   112
	SetEntProp(client, Prop_Send, "m_iClass", _:class);
pred@1963
   113
	
pred@2005
   114
	if (persistant)
pred@2005
   115
	{
pred@2005
   116
		SetEntProp(client, Prop_Send, "m_iDesiredPlayerClass", _:class);
pred@2005
   117
	}
pred@1963
   118
}
pred@1963
   119
pred@1963
   120
/**
pred@1963
   121
 * Retrieves client data from the resource entity
pred@1963
   122
 *
pred@1963
   123
 * @param client		Player's index.
pred@1963
   124
 * @param type			ResourceType constant
pred@1963
   125
 * @return				Value or -1 on failure.
pred@1963
   126
 * @error				Invalid client index, client not in game or failed to find resource entity.
pred@1963
   127
 */
pred@1963
   128
stock TF2_GetPlayerResourceData(client, TFResourceType:type)
pred@1963
   129
{
pred@1963
   130
	if (!IsClientConnected(client))
pred@1963
   131
	{
pred@1963
   132
		return -1;	
pred@1963
   133
	}
pred@1963
   134
	
pred@2021
   135
	new offset = FindSendPropInfo("CTFPlayerResource", TFResourceNames[type]);
pred@1963
   136
		
pred@1963
   137
	if (offset < 1)
pred@1963
   138
	{
pred@1963
   139
		return -1;	
pred@1963
   140
	}
pred@1963
   141
				
pred@1963
   142
	new entity = TF2_GetResourceEntity();
pred@1963
   143
	
pred@1963
   144
	if (entity == -1)
pred@1963
   145
	{
pred@1963
   146
		return -1;
pred@1963
   147
	}
pred@1963
   148
	
pred@1963
   149
	return GetEntData(entity, offset + (client*4));
pred@1963
   150
}
pred@1963
   151
pred@1963
   152
/**
pred@1963
   153
 * Sets client data in the resource entity
pred@1963
   154
 *
pred@2021
   155
 * Note: The game overwrites these values every frame, so changing them will have very little effect.
pred@2021
   156
 *
pred@1963
   157
 * @param client		Player's index.
pred@1963
   158
 * @param type			ResourceType constant
pred@1963
   159
 * @param value			Value to set.
pred@1963
   160
 * @return				Value or -1 on failure.
pred@1963
   161
 * @error				Invalid client index, client not in game or failed to find resource entity.
pred@1963
   162
 */
pred@1963
   163
stock bool:TF2_SetPlayerResourceData(client, TFResourceType:type, any:value)
pred@1963
   164
{
pred@1963
   165
	if (!IsClientConnected(client))
pred@1963
   166
	{
pred@1963
   167
		return false;	
pred@1963
   168
	}
pred@1963
   169
	
pred@2021
   170
	new offset = FindSendPropInfo("CTFPlayerResource", TFResourceNames[type]);
pred@1963
   171
						
pred@1963
   172
	if (offset < 1)
pred@1963
   173
	{
pred@1963
   174
		return false;	
pred@1963
   175
	}
pred@1963
   176
				
pred@1963
   177
	new entity = TF2_GetResourceEntity();
pred@1963
   178
	
pred@1963
   179
	if (entity == -1)
pred@1963
   180
	{
pred@1963
   181
		return false;	
pred@1963
   182
	}
pred@1963
   183
	
dvander@1975
   184
	SetEntData(entity, offset + (client*4), value);
pred@1963
   185
	
pred@1963
   186
	return true;	
pred@1963
   187
}
pred@1963
   188
pred@1963
   189
/**
pred@1963
   190
 * Removes all weapons from a client's weapon slot
pred@1963
   191
 *
pred@1963
   192
 * @param client		Player's index.
pred@1963
   193
 * @param slot			Slot index (0-5)
pred@1963
   194
 * @noreturn
pred@1963
   195
 * @error				Invalid client, invalid slot or lack of mod support
pred@1963
   196
 */
pred@1963
   197
stock TF2_RemoveWeaponSlot(client, slot)
pred@1963
   198
{
pred@1963
   199
	new weaponIndex;
pred@1963
   200
	while ((weaponIndex = GetPlayerWeaponSlot(client, slot)) != -1)
pred@1963
   201
	{
pred@1963
   202
		RemovePlayerItem(client, weaponIndex);
pred@1963
   203
		RemoveEdict(weaponIndex);
pred@1963
   204
	}
pred@1963
   205
}
pred@1963
   206
pred@1963
   207
/**
pred@1963
   208
 * Removes all weapons from a client
pred@1963
   209
 *
pred@1963
   210
 * @param client		Player's index.
pred@1963
   211
 * @noreturn
pred@1963
   212
 */
pred@1963
   213
stock TF2_RemoveAllWeapons(client)
pred@1963
   214
{
pred@1963
   215
	for (new i = 0; i <= 5; i++)
pred@1963
   216
	{
pred@1963
   217
		TF2_RemoveWeaponSlot(client, i);
pred@1963
   218
	}
pred@1963
   219
}