#pragma semicolon 1
#include <amxmodx>
#include <reapi>
new g_iLastHitPerson[MAX_CLIENTS + 1];
public plugin_init() {
register_plugin("Last Hit", "1.0", "PurposeLess");
register_clcmd("say /lasthit", "@clcmd_lasthit");
RegisterHookChain(RG_CBasePlayer_TakeDamage, "@CBasePlayer_TakeDamage_Post", .post = true);
RegisterHookChain(RG_CBasePlayer_Spawn, "@CBasePlayer_Spawn_Post", .post = true);
}
@clcmd_lasthit(const pPlayer) {
if(g_iLastHitPerson[pPlayer]) {
client_print_color(pPlayer, pPlayer, "Last hit from %n", g_iLastHitPerson[pPlayer]);
}
else {
client_print_color(pPlayer, pPlayer, "You haven't taken any damage yet.");
}
return PLUGIN_HANDLED;
}
@CBasePlayer_Spawn_Post(const pPlayer) {
if(!is_user_alive(pPlayer)) {
return;
}
g_iLastHitPerson[pPlayer] = 0;
}
@CBasePlayer_TakeDamage_Post(const pVictim, pInflictor, pAttacker, Float:flDamage, bitsDamageType) {
if(pVictim == pAttacker || !is_user_connected(pAttacker)) {
return;
}
g_iLastHitPerson[pVictim] = pAttacker;
}