Here's how I do it in my Mutant Tanks plugin:
PHP Code:
char sWeapon[32];
int iSlot = 0;
if (GetEntProp(survivor, Prop_Send, "m_isIncapacitated", 1) == 1 || GetEntProp(survivor, Prop_Send, "m_isHangingFromLedge") == 1) // Only check if player is incapacitated or hanging from ledge.
{
int iOffset = g_bLinux ? 16320 : 16340, // Offsets found in: CTerrorPlayer::OnIncapacitatedAsSurvivor(CTakeDamageInfo const&)
iMelee = GetEntDataEnt2(survivor, iOffset);
switch (IsValidEntity(iMelee))
{
case true: iSlot = iMelee;
case false: iSlot = GetPlayerWeaponSlot(survivor, 1);
}
}
else
{
iSlot = GetPlayerWeaponSlot(survivor, 1);
}
if (iSlot > MaxClients)
{
GetEntityClassname(iSlot, sWeapon, sizeof(sWeapon));
if (StrEqual(sWeapon, "weapon_melee"))
{
GetEntPropString(iSlot, Prop_Data, "m_strMapSetScriptName", sWeapon, sizeof(sWeapon)); // Get the melee weapon's script name.
}
}
__________________