plugins/include/tf2_stocks.inc
author Matt Woodrow <pred@alliedmods.net>
Sat Apr 05 00:06:27 2008 +0000 (2008-04-05)
changeset 1964 4dc60790d851
parent 1963 97a66409edac
child 1975 213f7f8b8ee3
permissions -rw-r--r--
Forgot license headers for the tf2 include files.
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
 *
pred@1964
    30
 * Version: $Id: sdktools_entoutput.inc 1504 2007-09-28 19:56:19Z faluco $
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@1963
   101
 * @param client		Player's index.
pred@1963
   102
 * @param class			TFClassType class symbol.
pred@1963
   103
 * @param weapons		If true, changes the players weapon set to that of the new class.
pred@1963
   104
 * @noreturn
pred@1963
   105
 * @error				Invalid client index.
pred@1963
   106
 */
pred@1963
   107
stock TF2_SetPlayerClass(client, TFClassType:class, bool:weapons=true)
pred@1963
   108
{
pred@1963
   109
	SetEntProp(client, Prop_Send, "m_iClass", _:class);
pred@1963
   110
	SetEntProp(client, Prop_Send, "m_iDesiredPlayerClass", _:class);
pred@1963
   111
	TF2_SetPlayerResourceData(client, TFResource_PlayerClass, class);
pred@1963
   112
	
pred@1963
   113
	if (weapons)
pred@1963
   114
	{
pred@1963
   115
		TF2_RemoveAllWeapons(client);
pred@1963
   116
		TF2_EquipPlayerClassWeapons(client, class)
pred@1963
   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@1963
   135
	static offset;
pred@1963
   136
	static set = false;
pred@1963
   137
	
pred@1963
   138
	if (!set)
pred@1963
   139
	{
pred@1963
   140
		offset = FindSendPropInfo("CTFPlayerResource", TFResourceNames[type]);
pred@1963
   141
		set = true;
pred@1963
   142
	}
pred@1963
   143
		
pred@1963
   144
	if (offset < 1)
pred@1963
   145
	{
pred@1963
   146
		return -1;	
pred@1963
   147
	}
pred@1963
   148
				
pred@1963
   149
	new entity = TF2_GetResourceEntity();
pred@1963
   150
	
pred@1963
   151
	if (entity == -1)
pred@1963
   152
	{
pred@1963
   153
		return -1;
pred@1963
   154
	}
pred@1963
   155
	
pred@1963
   156
	return GetEntData(entity, offset + (client*4));
pred@1963
   157
}
pred@1963
   158
pred@1963
   159
/**
pred@1963
   160
 * Sets client data in the resource entity
pred@1963
   161
 *
pred@1963
   162
 * @param client		Player's index.
pred@1963
   163
 * @param type			ResourceType constant
pred@1963
   164
 * @param value			Value to set.
pred@1963
   165
 * @return				Value or -1 on failure.
pred@1963
   166
 * @error				Invalid client index, client not in game or failed to find resource entity.
pred@1963
   167
 */
pred@1963
   168
stock bool:TF2_SetPlayerResourceData(client, TFResourceType:type, any:value)
pred@1963
   169
{
pred@1963
   170
	if (!IsClientConnected(client))
pred@1963
   171
	{
pred@1963
   172
		return false;	
pred@1963
   173
	}
pred@1963
   174
	
pred@1963
   175
	static offset;
pred@1963
   176
	static set = false;
pred@1963
   177
	
pred@1963
   178
	if (!set)
pred@1963
   179
	{
pred@1963
   180
		offset = FindSendPropInfo("CTFPlayerResource", TFResourceNames[type]);
pred@1963
   181
		set = true;
pred@1963
   182
	}
pred@1963
   183
						
pred@1963
   184
	if (offset < 1)
pred@1963
   185
	{
pred@1963
   186
		return false;	
pred@1963
   187
	}
pred@1963
   188
				
pred@1963
   189
	new entity = TF2_GetResourceEntity();
pred@1963
   190
	
pred@1963
   191
	if (entity == -1)
pred@1963
   192
	{
pred@1963
   193
		return false;	
pred@1963
   194
	}
pred@1963
   195
	
pred@1963
   196
	SetEntData(entity, offset + (client*4), value)
pred@1963
   197
	
pred@1963
   198
	return true;	
pred@1963
   199
}
pred@1963
   200
pred@1963
   201
/**
pred@1963
   202
 * Removes all weapons from a client's weapon slot
pred@1963
   203
 *
pred@1963
   204
 * @param client		Player's index.
pred@1963
   205
 * @param slot			Slot index (0-5)
pred@1963
   206
 * @noreturn
pred@1963
   207
 * @error				Invalid client, invalid slot or lack of mod support
pred@1963
   208
 */
pred@1963
   209
stock TF2_RemoveWeaponSlot(client, slot)
pred@1963
   210
{
pred@1963
   211
	new weaponIndex;
pred@1963
   212
	while ((weaponIndex = GetPlayerWeaponSlot(client, slot)) != -1)
pred@1963
   213
	{
pred@1963
   214
		RemovePlayerItem(client, weaponIndex);
pred@1963
   215
		RemoveEdict(weaponIndex);
pred@1963
   216
	}
pred@1963
   217
}
pred@1963
   218
pred@1963
   219
/**
pred@1963
   220
 * Removes all weapons from a client
pred@1963
   221
 *
pred@1963
   222
 * @param client		Player's index.
pred@1963
   223
 * @noreturn
pred@1963
   224
 */
pred@1963
   225
stock TF2_RemoveAllWeapons(client)
pred@1963
   226
{
pred@1963
   227
	for (new i = 0; i <= 5; i++)
pred@1963
   228
	{
pred@1963
   229
		TF2_RemoveWeaponSlot(client, i);
pred@1963
   230
	}
pred@1963
   231
}
pred@1963
   232
pred@1963
   233
/**
pred@1963
   234
 * Gives a named weapon to a client
pred@1963
   235
 *
pred@1963
   236
 * @param client		Player's index.
pred@1963
   237
 * @param weapon		Weapon name
pred@1963
   238
 * @return				False if weapon could not be created, true on success
pred@1963
   239
 * @error				Invalid client index or lack of mod support
pred@1963
   240
 */
pred@1963
   241
stock bool:TF2_GivePlayerWeapon(client, const String:weapon[])
pred@1963
   242
{
pred@1963
   243
	new weaponIndex = GivePlayerItem(client, weapon);
pred@1963
   244
	if (weaponIndex == -1)
pred@1963
   245
	{
pred@1963
   246
		return false;	
pred@1963
   247
	}
pred@1963
   248
	
pred@1963
   249
	EquipPlayerWeapon(client, weaponIndex);
pred@1963
   250
	
pred@1963
   251
	return true;
pred@1963
   252
}
pred@1963
   253
pred@1963
   254
/**
pred@1963
   255
 * Equips a client with a class's weapons. This does not remove existing weapons.
pred@1963
   256
 *
pred@1963
   257
 * Note: 	Some class specific items such tf_weapon_pda_engineer_build are only given 
pred@1963
   258
 *			if the client is the correct class.
pred@1963
   259
 *
pred@1963
   260
 * @param client		Player's index.
pred@1963
   261
 * @param class			TFClasssType class symbol.
pred@1963
   262
 * @noreturn
pred@1963
   263
 */
pred@1963
   264
stock TF2_EquipPlayerClassWeapons(client, TFClassType:class)
pred@1963
   265
{
pred@1963
   266
	switch(class)
pred@1963
   267
	{
pred@1963
   268
		case TFClass_Scout:
pred@1963
   269
		{
pred@1963
   270
			TF2_GivePlayerWeapon(client, "tf_weapon_scattergun");
pred@1963
   271
			TF2_GivePlayerWeapon(client, "tf_weapon_pistol_scout");
pred@1963
   272
			TF2_GivePlayerWeapon(client, "tf_weapon_bat");
pred@1963
   273
		}
pred@1963
   274
		case TFClass_Sniper:
pred@1963
   275
		{
pred@1963
   276
			TF2_GivePlayerWeapon(client, "tf_weapon_sniperrifle");
pred@1963
   277
			TF2_GivePlayerWeapon(client, "tf_weapon_smg");
pred@1963
   278
			TF2_GivePlayerWeapon(client, "tf_weapon_club");
pred@1963
   279
		}
pred@1963
   280
		case TFClass_Soldier:
pred@1963
   281
		{
pred@1963
   282
			TF2_GivePlayerWeapon(client, "tf_weapon_rocketlauncher");
pred@1963
   283
			TF2_GivePlayerWeapon(client, "tf_weapon_shotgun_soldier");
pred@1963
   284
			TF2_GivePlayerWeapon(client, "tf_weapon_shovel");
pred@1963
   285
		}
pred@1963
   286
		case TFClass_DemoMan:
pred@1963
   287
		{
pred@1963
   288
			TF2_GivePlayerWeapon(client, "tf_weapon_pipebomblauncher");
pred@1963
   289
			TF2_GivePlayerWeapon(client, "tf_weapon_grenadelauncher");
pred@1963
   290
			TF2_GivePlayerWeapon(client, "tf_weapon_bottle");
pred@1963
   291
		}
pred@1963
   292
		case TFClass_Medic:
pred@1963
   293
		{
pred@1963
   294
			TF2_GivePlayerWeapon(client, "tf_weapon_syringegun_medic");
pred@1963
   295
			TF2_GivePlayerWeapon(client, "tf_weapon_medigun");
pred@1963
   296
			TF2_GivePlayerWeapon(client, "tf_weapon_bonesaw");
pred@1963
   297
		}
pred@1963
   298
		case TFClass_Heavy:
pred@1963
   299
		{
pred@1963
   300
			TF2_GivePlayerWeapon(client, "tf_weapon_minigun");
pred@1963
   301
			TF2_GivePlayerWeapon(client, "tf_weapon_shotgun_hwg");
pred@1963
   302
			TF2_GivePlayerWeapon(client, "tf_weapon_fists");
pred@1963
   303
		}
pred@1963
   304
		case TFClass_Pyro:
pred@1963
   305
		{
pred@1963
   306
			TF2_GivePlayerWeapon(client, "tf_weapon_flamethrower");
pred@1963
   307
			TF2_GivePlayerWeapon(client, "tf_weapon_shotgun_pyro");
pred@1963
   308
			TF2_GivePlayerWeapon(client, "tf_weapon_fireaxe");
pred@1963
   309
		}
pred@1963
   310
		case TFClass_Spy:
pred@1963
   311
		{
pred@1963
   312
			TF2_GivePlayerWeapon(client, "tf_weapon_revolver");
pred@1963
   313
			TF2_GivePlayerWeapon(client, "tf_weapon_knife");
pred@1963
   314
pred@1963
   315
			if (TF2_GetPlayerClass(client) != TFClass_Spy)
pred@1963
   316
				return;
pred@1963
   317
pred@1963
   318
			TF2_GivePlayerWeapon(client, "tf_weapon_pda_spy");
pred@1963
   319
		}
pred@1963
   320
		case TFClass_Engineer:
pred@1963
   321
		{
pred@1963
   322
			TF2_GivePlayerWeapon(client, "tf_weapon_shotgun_primary");
pred@1963
   323
			TF2_GivePlayerWeapon(client, "tf_weapon_pistol");
pred@1963
   324
			TF2_GivePlayerWeapon(client, "tf_weapon_wrench");
pred@1963
   325
pred@1963
   326
			if (TF2_GetPlayerClass(client) != TFClass_Engineer)
pred@1963
   327
				return;
pred@1963
   328
pred@1963
   329
			TF2_GivePlayerWeapon(client, "tf_weapon_pda_engineer_build");
pred@1963
   330
			TF2_GivePlayerWeapon(client, "tf_weapon_pda_engineer_destroy");
pred@1963
   331
		}
pred@1963
   332
	}
pred@1963
   333
}