plugins/include/tf2_stocks.inc
author Nicholas Hastings <skamonkey@gmail.com>
Fri Dec 16 00:24:03 2011 -0500 (2011-12-16)
changeset 3455 578a72ab7b7d
parent 3432 8f4f4c36ceb7
child 3567 c7306900ead7
permissions -rw-r--r--
Added new TF2 weapon defines (r=me).
     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 #define TF_CONDFLAG_NONE            0
    42 #define TF_CONDFLAG_SLOWED          (1 << 0)
    43 #define TF_CONDFLAG_ZOOMED          (1 << 1)
    44 #define TF_CONDFLAG_DISGUISING      (1 << 2)
    45 #define TF_CONDFLAG_DISGUISED       (1 << 3)
    46 #define TF_CONDFLAG_CLOAKED         (1 << 4)
    47 #define TF_CONDFLAG_UBERCHARGED     (1 << 5)
    48 #define TF_CONDFLAG_TELEPORTGLOW    (1 << 6)
    49 #define TF_CONDFLAG_TAUNTING        (1 << 7)
    50 #define TF_CONDFLAG_UBERCHARGEFADE  (1 << 8)
    51 #define TF_CONDFLAG_CLOAKFLICKER    (1 << 9)
    52 #define TF_CONDFLAG_TELEPORTING     (1 << 10)
    53 #define TF_CONDFLAG_KRITZKRIEGED    (1 << 11)
    54 #define TF_CONDFLAG_DEADRINGERED    (1 << 13)
    55 #define TF_CONDFLAG_BONKED          (1 << 14)
    56 #define TF_CONDFLAG_DAZED           (1 << 15)
    57 #define TF_CONDFLAG_BUFFED          (1 << 16)
    58 #define TF_CONDFLAG_CHARGING        (1 << 17)
    59 #define TF_CONDFLAG_DEMOBUFF        (1 << 18)
    60 #define TF_CONDFLAG_CRITCOLA        (1 << 19)
    61 #define TF_CONDFLAG_INHEALRADIUS    (1 << 20)
    62 #define TF_CONDFLAG_HEALING         (1 << 21)
    63 #define TF_CONDFLAG_ONFIRE          (1 << 22)
    64 #define TF_CONDFLAG_OVERHEALED      (1 << 23)
    65 #define TF_CONDFLAG_JARATED         (1 << 24)
    66 #define TF_CONDFLAG_BLEEDING        (1 << 25)
    67 #define TF_CONDFLAG_DEFENSEBUFFED   (1 << 26)
    68 #define TF_CONDFLAG_MILKED          (1 << 27)
    69 #define TF_CONDFLAG_MEGAHEAL        (1 << 28)
    70 #define TF_CONDFLAG_REGENBUFFED     (1 << 29)
    71 #define TF_CONDFLAG_MARKEDFORDEATH  (1 << 30)
    72 
    73 #define TF_DEATHFLAG_KILLERDOMINATION   (1 << 0)
    74 #define TF_DEATHFLAG_ASSISTERDOMINATION (1 << 1)
    75 #define TF_DEATHFLAG_KILLERREVENGE      (1 << 2)
    76 #define TF_DEATHFLAG_ASSISTERREVENGE    (1 << 3)
    77 #define TF_DEATHFLAG_FIRSTBLOOD         (1 << 4)
    78 #define TF_DEATHFLAG_DEADRINGER         (1 << 5)
    79 #define TF_DEATHFLAG_INTERRUPTED        (1 << 6)
    80 #define TF_DEATHFLAG_GIBBED             (1 << 7)
    81 #define TF_DEATHFLAG_PURGATORY          (1 << 8)
    82 
    83 // Custom kill identifiers for the customkill property on the player_death event
    84 enum {
    85 	TF_CUSTOM_HEADSHOT = 1,
    86 	TF_CUSTOM_BACKSTAB,
    87 	TF_CUSTOM_BURNING,
    88 	TF_CUSTOM_WRENCH_FIX,
    89 	TF_CUSTOM_MINIGUN,
    90 	TF_CUSTOM_SUICIDE,
    91 	TF_CUSTOM_TAUNT_HADOUKEN,
    92 	TF_CUSTOM_BURNING_FLARE,
    93 	TF_CUSTOM_TAUNT_HIGH_NOON,
    94 	TF_CUSTOM_TAUNT_GRAND_SLAM,
    95 	TF_CUSTOM_PENETRATE_MY_TEAM,
    96 	TF_CUSTOM_PENETRATE_ALL_PLAYERS,
    97 	TF_CUSTOM_TAUNT_FENCING,
    98 	TF_CUSTOM_PENETRATE_HEADSHOT,
    99 	TF_CUSTOM_TAUNT_ARROW_STAB,
   100 	TF_CUSTOM_TELEFRAG,
   101 	TF_CUSTOM_BURNING_ARROW,
   102 	TF_CUSTOM_FLYINGBURN,
   103 	TF_CUSTOM_PUMPKIN_BOMB,
   104 	TF_CUSTOM_DECAPITATION,
   105 	TF_CUSTOM_TAUNT_GRENADE,
   106 	TF_CUSTOM_BASEBALL,
   107 	TF_CUSTOM_CHARGE_IMPACT,
   108 	TF_CUSTOM_TAUNT_BARBARIAN_SWING,
   109 	TF_CUSTOM_AIR_STICKY_BURST,
   110 	TF_CUSTOM_DEFENSIVE_STICKY,
   111 	TF_CUSTOM_PICKAXE,
   112 	TF_CUSTOM_ROCKET_DIRECTHIT,
   113 	TF_CUSTOM_TAUNT_UBERSLICE,
   114 	TF_CUSTOM_PLAYER_SENTRY,
   115 	TF_CUSTOM_STANDARD_STICKY,
   116 	TF_CUSTOM_SHOTGUN_REVENGE_CRIT,
   117 	TF_CUSTOM_TAUNT_ENGINEER_SMASH,
   118 	TF_CUSTOM_BLEEDING,
   119 	TF_CUSTOM_GOLD_WRENCH,
   120 	TF_CUSTOM_CARRIED_BUILDING,
   121 	TF_CUSTOM_COMBO_PUNCH,
   122 	TF_CUSTOM_TAUNT_ENGINEER_ARM,
   123 	TF_CUSTOM_FISH_KILL,
   124 	TF_CUSTOM_TRIGGER_HURT,
   125 	TF_CUSTOM_DECAPITATION_BOSS,
   126 	TF_CUSTOM_STICKBOMB_EXPLOSION,
   127 	TF_CUSTOM_AEGIS_ROUND,
   128 	TF_CUSTOM_FLARE_EXPLOSION,
   129 	TF_CUSTOM_BOOTS_STOMP,
   130 	TF_CUSTOM_PLASMA,
   131 	TF_CUSTOM_PLASMA_CHARGED,
   132 	TF_CUSTOM_PLASMA_GIB,
   133 	TF_CUSTOM_PRACTICE_STICKY,
   134 	TF_CUSTOM_EYEBALL_ROCKET,
   135 };
   136 
   137 // Weapon codes as used in some events, such as player_death
   138 // (not to be confused with Item Definition Indexes)
   139 enum {
   140 	TF_WEAPON_NONE = 0,
   141 	TF_WEAPON_BAT,
   142 	TF_WEAPON_BAT_WOOD,
   143 	TF_WEAPON_BOTTLE,
   144 	TF_WEAPON_FIREAXE,
   145 	TF_WEAPON_CLUB,
   146 	TF_WEAPON_CROWBAR,
   147 	TF_WEAPON_KNIFE,
   148 	TF_WEAPON_FISTS,
   149 	TF_WEAPON_SHOVEL,
   150 	TF_WEAPON_WRENCH,
   151 	TF_WEAPON_BONESAW,
   152 	TF_WEAPON_SHOTGUN_PRIMARY,
   153 	TF_WEAPON_SHOTGUN_SOLDIER,
   154 	TF_WEAPON_SHOTGUN_HWG,
   155 	TF_WEAPON_SHOTGUN_PYRO,
   156 	TF_WEAPON_SCATTERGUN,
   157 	TF_WEAPON_SNIPERRIFLE,
   158 	TF_WEAPON_MINIGUN,
   159 	TF_WEAPON_SMG,
   160 	TF_WEAPON_SYRINGEGUN_MEDIC,
   161 	TF_WEAPON_TRANQ,
   162 	TF_WEAPON_ROCKETLAUNCHER,
   163 	TF_WEAPON_GRENADELAUNCHER,
   164 	TF_WEAPON_PIPEBOMBLAUNCHER,
   165 	TF_WEAPON_FLAMETHROWER,
   166 	TF_WEAPON_GRENADE_NORMAL,
   167 	TF_WEAPON_GRENADE_CONCUSSION,
   168 	TF_WEAPON_GRENADE_NAIL,
   169 	TF_WEAPON_GRENADE_MIRV,
   170 	TF_WEAPON_GRENADE_MIRV_DEMOMAN,
   171 	TF_WEAPON_GRENADE_NAPALM,
   172 	TF_WEAPON_GRENADE_GAS,
   173 	TF_WEAPON_GRENADE_EMP,
   174 	TF_WEAPON_GRENADE_CALTROP,
   175 	TF_WEAPON_GRENADE_PIPEBOMB,
   176 	TF_WEAPON_GRENADE_SMOKE_BOMB,
   177 	TF_WEAPON_GRENADE_HEAL,
   178 	TF_WEAPON_GRENADE_STUNBALL,
   179 	TF_WEAPON_GRENADE_JAR,
   180 	TF_WEAPON_GRENADE_JAR_MILK,
   181 	TF_WEAPON_PISTOL,
   182 	TF_WEAPON_PISTOL_SCOUT,
   183 	TF_WEAPON_REVOLVER,
   184 	TF_WEAPON_NAILGUN,
   185 	TF_WEAPON_PDA,
   186 	TF_WEAPON_PDA_ENGINEER_BUILD,
   187 	TF_WEAPON_PDA_ENGINEER_DESTROY,
   188 	TF_WEAPON_PDA_SPY,
   189 	TF_WEAPON_BUILDER,
   190 	TF_WEAPON_MEDIGUN,
   191 	TF_WEAPON_GRENADE_MIRVBOMB,
   192 	TF_WEAPON_FLAMETHROWER_ROCKET,
   193 	TF_WEAPON_GRENADE_DEMOMAN,
   194 	TF_WEAPON_SENTRY_BULLET,
   195 	TF_WEAPON_SENTRY_ROCKET,
   196 	TF_WEAPON_DISPENSER,
   197 	TF_WEAPON_INVIS,
   198 	TF_WEAPON_FLAREGUN,
   199 	TF_WEAPON_LUNCHBOX,
   200 	TF_WEAPON_JAR,
   201 	TF_WEAPON_COMPOUND_BOW,
   202 	TF_WEAPON_BUFF_ITEM,
   203 	TF_WEAPON_PUMPKIN_BOMB,
   204 	TF_WEAPON_SWORD,
   205 	TF_WEAPON_DIRECTHIT,
   206 	TF_WEAPON_LIFELINE,
   207 	TF_WEAPON_LASER_POINTER,
   208 	TF_WEAPON_DISPENSER_GUN,
   209 	TF_WEAPON_SENTRY_REVENGE,
   210 	TF_WEAPON_JAR_MILK,
   211 	TF_WEAPON_HANDGUN_SCOUT_PRIMARY,
   212 	TF_WEAPON_BAT_FISH,
   213 	TF_WEAPON_CROSSBOW,
   214 	TF_WEAPON_STICKBOMB,
   215 	TF_WEAPON_HANDGUN_SCOUT_SEC,
   216 	TF_WEAPON_SODA_POPPER,
   217 	TF_WEAPON_SNIPERRIFLE_DECAP,
   218 	TF_WEAPON_RAYGUN,
   219 	TF_WEAPON_PARTICLE_CANNON,
   220 	TF_WEAPON_MECHANICAL_ARM,
   221 	TF_WEAPON_DRG_POMSON,
   222 	TF_WEAPON_BAT_GIFTWRAP,
   223 	TF_WEAPON_GRENADE_ORNAMENT,
   224 	TF_WEAPON_RAYGUN_REVENGE,
   225 };
   226 
   227 // TF2 Weapon Slots for GetPlayerWeaponSlot
   228 enum
   229 {
   230 	TFWeaponSlot_Primary,
   231 	TFWeaponSlot_Secondary,
   232 	TFWeaponSlot_Melee,
   233 	TFWeaponSlot_Grenade,
   234 	TFWeaponSlot_Building,
   235 	TFWeaponSlot_PDA,
   236 	TFWeaponSlot_Item1,
   237 	TFWeaponSlot_Item2	
   238 };
   239 
   240 // Identifiers for the eventtype property on the teamplay_flag_event event
   241 enum {
   242 	TF_FLAGEVENT_PICKEDUP = 1,
   243 	TF_FLAGEVENT_CAPTURED,
   244 	TF_FLAGEVENT_DEFENDED,
   245 	TF_FLAGEVENT_DROPPED,
   246 	TF_FLAGEVENT_RETURNED
   247 };
   248 
   249 enum TFResourceType
   250 {
   251 	TFResource_Ping,
   252 	TFResource_Score,
   253 	TFResource_Deaths,
   254 	TFResource_TotalScore, 
   255 	TFResource_Captures,
   256 	TFResource_Defenses,
   257 	TFResource_Dominations,
   258 	TFResource_Revenge,
   259 	TFResource_BuildingsDestroyed, 
   260 	TFResource_Headshots,
   261 	TFResource_Backstabs,
   262 	TFResource_HealPoints,
   263 	TFResource_Invulns,
   264 	TFResource_Teleports,
   265 	TFResource_ResupplyPoints,
   266 	TFResource_KillAssists,
   267 	TFResource_MaxHealth,
   268 	TFResource_PlayerClass
   269 };
   270 
   271 static const String:TFResourceNames[TFResourceType][] =
   272 {
   273 	"m_iPing",
   274 	"m_iScore",
   275 	"m_iDeaths",
   276 	"m_iTotalScore",
   277 	"m_iCaptures",
   278 	"m_iDefenses",
   279 	"m_iDominations",
   280 	"m_iRevenge",
   281 	"m_iBuildingsDestroyed",
   282 	"m_iHeadshots",
   283 	"m_iBackstabs",
   284 	"m_iHealPoints",
   285 	"m_iInvulns",
   286 	"m_iTeleports",
   287 	"m_iResupplyPoints",
   288 	"m_iKillAssists",
   289 	"m_iMaxHealth",
   290 	"m_iPlayerClass"
   291 };
   292 
   293 /**
   294  * Get's a Clients current class.
   295  *
   296  * @param client		Player's index.
   297  * @return				Current TFClassType of player.
   298  * @error				Invalid client index.
   299  */
   300 stock TFClassType:TF2_GetPlayerClass(client)
   301 {
   302 	return TFClassType:GetEntProp(client, Prop_Send, "m_iClass");
   303 }
   304 
   305 /**
   306  * Set's a Clients class.
   307  *
   308  * Note: If setting player class in a player spawn hook weapons should be set to false.
   309  *
   310  * @param client		Player's index.
   311  * @param class			TFClassType class symbol.
   312  * @param weapons		This paramater is ignored.
   313  * @param persistent	If true changes the players desired class so the change stays after death.
   314  * @noreturn
   315  * @error				Invalid client index.
   316  */
   317 stock TF2_SetPlayerClass(client, TFClassType:class, bool:weapons=true, bool:persistent=true)
   318 {
   319 	SetEntProp(client, Prop_Send, "m_iClass", _:class);
   320 	
   321 	if (persistent)
   322 	{
   323 		SetEntProp(client, Prop_Send, "m_iDesiredPlayerClass", _:class);
   324 	}
   325 }
   326 
   327 /**
   328  * Retrieves client data from the resource entity
   329  *
   330  * @param client		Player's index.
   331  * @param type			ResourceType constant
   332  * @return				Value or -1 on failure.
   333  * @error				Invalid client index, client not in game or failed to find resource entity.
   334  */
   335 stock TF2_GetPlayerResourceData(client, TFResourceType:type)
   336 {
   337 	if (!IsClientConnected(client))
   338 	{
   339 		return -1;	
   340 	}
   341 	
   342 	new offset = FindSendPropInfo("CTFPlayerResource", TFResourceNames[type]);
   343 		
   344 	if (offset < 1)
   345 	{
   346 		return -1;	
   347 	}
   348 				
   349 	new entity = TF2_GetResourceEntity();
   350 	
   351 	if (entity == -1)
   352 	{
   353 		return -1;
   354 	}
   355 	
   356 	return GetEntData(entity, offset + (client*4));
   357 }
   358 
   359 /**
   360  * Sets client data in the resource entity
   361  *
   362  * Note: The game overwrites these values every frame, so changing them will have very little effect.
   363  *
   364  * @param client		Player's index.
   365  * @param type			ResourceType constant
   366  * @param value			Value to set.
   367  * @return				Value or -1 on failure.
   368  * @error				Invalid client index, client not in game or failed to find resource entity.
   369  */
   370 stock bool:TF2_SetPlayerResourceData(client, TFResourceType:type, any:value)
   371 {
   372 	if (!IsClientConnected(client))
   373 	{
   374 		return false;	
   375 	}
   376 	
   377 	new offset = FindSendPropInfo("CTFPlayerResource", TFResourceNames[type]);
   378 						
   379 	if (offset < 1)
   380 	{
   381 		return false;	
   382 	}
   383 				
   384 	new entity = TF2_GetResourceEntity();
   385 	
   386 	if (entity == -1)
   387 	{
   388 		return false;	
   389 	}
   390 	
   391 	SetEntData(entity, offset + (client*4), value);
   392 	
   393 	return true;	
   394 }
   395 
   396 /**
   397  * Removes all weapons from a client's weapon slot
   398  *
   399  * @param client		Player's index.
   400  * @param slot			Slot index (0-5)
   401  * @noreturn
   402  * @error				Invalid client, invalid slot or lack of mod support
   403  */
   404 stock TF2_RemoveWeaponSlot(client, slot)
   405 {
   406 	new weaponIndex;
   407 	while ((weaponIndex = GetPlayerWeaponSlot(client, slot)) != -1)
   408 	{
   409 		RemovePlayerItem(client, weaponIndex);
   410 		RemoveEdict(weaponIndex);
   411 	}
   412 }
   413 
   414 /**
   415  * Removes all weapons from a client
   416  *
   417  * @param client		Player's index.
   418  * @noreturn
   419  */
   420 stock TF2_RemoveAllWeapons(client)
   421 {
   422 	for (new i = 0; i <= 5; i++)
   423 	{
   424 		TF2_RemoveWeaponSlot(client, i);
   425 	}
   426 }
   427 
   428 /**
   429  * Gets a player's condition bits
   430  *
   431  * @param client		Player's index.
   432  * @return				Player's condition bits
   433  */
   434 #pragma deprecated Use TF2_IsPlayerInCondition instead.
   435 stock TF2_GetPlayerConditionFlags(client)
   436 {
   437 	return GetEntProp(client, Prop_Send, "m_nPlayerCond")|GetEntProp(client, Prop_Send, "_condition_bits");
   438 }
   439 
   440 /**
   441  * Check whether or not a condition is set on a player
   442  *
   443  * @param client		Player's index.
   444  * @return				True if set, false otherwise
   445  */
   446 stock bool:TF2_IsPlayerInCondition(client, TFCond:cond)
   447 {
   448 	// Conditions are stored across two netprops now, one for each 32-bit segment.
   449 	if (_:cond < 32)
   450 	{
   451 		new bit = 1 << _:cond;
   452 		if ((GetEntProp(client, Prop_Send, "m_nPlayerCond") & bit) == bit)
   453 		{
   454 			return true;
   455 		}
   456 		
   457 		if ((GetEntProp(client, Prop_Send, "_condition_bits") & bit) == bit)
   458 		{
   459 			return true;
   460 		}
   461 	}
   462 	else
   463 	{
   464 		new bit = (1 << (_:cond - 32));
   465 		if ((GetEntProp(client, Prop_Send, "m_nPlayerCondEx") & bit) == bit)
   466 		{
   467 			return true;
   468 		}
   469 	}
   470 	
   471 	return false;
   472 }
   473 
   474 /**
   475  * Gets an entity's object type.
   476  *
   477  * @param entity		Entity index.
   478  * @return				Current TFObjectType of entity.
   479  * @error				Invalid entity index.
   480  */
   481 stock TFObjectType:TF2_GetObjectType(entity)
   482 {
   483 	new offset = GetEntSendPropOffs(entity, "m_iObjectType");
   484 	
   485 	if (offset <= 0)
   486 	{
   487 		ThrowError("Entity index %d is not an object", entity);
   488 	}
   489 	
   490 	return TFObjectType:GetEntData(entity, offset);
   491 }
   492 
   493 /**
   494  * Gets an entity's object mode.
   495  *
   496  * @param entity		Entity index.
   497  * @return				Current TFObjectMode of entity.
   498  * @error				Invalid entity index.
   499  */
   500 stock TFObjectMode:TF2_GetObjectMode(entity)
   501 {
   502 	new offset = GetEntSendPropOffs(entity, "m_iObjectMode");
   503 	
   504 	if (offset <= 0)
   505 	{
   506 		ThrowError("Entity index %d is not an object", entity);
   507 	}
   508 	
   509 	return TFObjectMode:GetEntData(entity, offset);
   510 }