PDA

View Full Version : [TF2] get weapon name from OnTakeDamage


LeBabouin
11-16-2014, 09:54
Hi,
I'm new but dumb too. Could you help me understand how to get the weapon name instead of the weapon classname from the following hook, where i want to check if the weapon that hit the victim is one of the following hardcoded ones:


static const String:g_strWeapons[][]={"sword", "axtinguisher", "fireaxe", "battleaxe", "headtaker"};


public OnClientPutInServer(client)
{
SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
}

public Action:OnTakeDamage(victim, &attacker, &inflictor, &Float:damage, &damagetype)
{
new TFClassType:class = TF2_GetPlayerClass(victim);

if (class == TFClass_DemoMan || class == TFClass_Pyro || class == TFClass_Heavy){

decl String:sWeapon[32];

GetEdictClassname(inflictor, sWeapon, sizeof(sWeapon));

for (new iLoop = 0; iLoop < sizeof(g_strWeapons); iLoop++)
{
if (StrEqual(sWeapon, g_strWeapons[iLoop], false))
{
damagetype |= DMG_REMOVENORAGDOLL;
return Plugin_Changed;
}
}
}
return Plugin_Continue;
}

Drixevel
11-16-2014, 12:34
OnTakeDamage has more parameters than that.


public Action:OnTakeDamage(client, &attacker, &inflictor, &Float:damage, &damagetype, &weapon, Float:damageForce[3], Float:damagePosition[3])

LeBabouin
11-16-2014, 13:17
Lol Thank you very much it could have take some time before i check.

psychonic
11-16-2014, 20:14
Most games don't populate that value. You have to determine the weapon from the inflictor (which can be a projectile, a player, or another entity).

Powerlord
11-17-2014, 10:36
Do be aware that the GetEntityClassname function returns the full classname as shown in the schema. You can't probably find it on the Item Definition Indexes (https://wiki.alliedmods.net/Team_fortress_2_item_definition_indexes) page, too. Speaking of which, has anyone else updated that lately? 'cause I haven't been.

Most games don't populate that value. You have to determine the weapon from the inflictor (which can be a projectile, a player, or another entity).

In this case, it's TF2 which iirc does populate that value.