I needed a way of checking whether or not a player shot hit anyone and thought someone here might find it useful too.
PHP Code:
public void OnClientPutInServer(int client)
{
SDKHook(client, SDKHook_TraceAttackPost, TraceAttack);
}
bool g_bShot[MAXPLAYERS + 1];
public Action TF2_CalcIsAttackCritical(int client, int weapon, char[] weaponname, bool &result)
{
g_bShot[client] = true;
RequestFrame(DidHit, GetClientUserId(client));
return Plugin_Continue;
}
public void TraceAttack(int victim, int attacker, int inflictor, float damage, int damagetype, int ammotype, int hitbox, int hitgroup)
{
if(g_bShot[attacker])
{
g_bShot[attacker] = false;
}
}
public void DidHit(int userid)
{
int client = GetClientOfUserId(userid);
if(client > 0)
{
PrintToChatAll("DidHit? %s", !g_bShot[client] ? "Yes" : "No");
}
}
Obiviously it doesn't work with projectile weapons.
__________________