Event "player_death"not appear when player get killed by C4 explosion.
So if some reason you want trace these players who die in explosion (or survive), here is one way, using events.
When event round_end (#Target_Bombed) come first
- list players using event player_hurt (they still alive at this point)
-- on event bomb_exploded check list players which are alive/dead (player die at this point)
This all happen in same one Tick
Notice:
When this not work, something else cause player death, example: Losing team slay.
It slay players on round_end event.
*forgot, this not work when round_end already (all ct dead)
click to expand
PHP Code:
public OnPluginStart() { // This likely order of events launched in game, you can see net_showevents 2 in server console // But ordering HookEvents here in plugin code not matter tough :P, but not need remember events order.
//HookEventEx("cs_win_panel_round", mycallback); HookEventEx("round_end", mycallback); HookEventEx("player_hurt", mycallback); // Notice, I use same callback. HookEventEx("bomb_exploded", mycallback);
HookEventEx("round_start", newround, EventHookMode_PostNoCopy); // EXTRA, To print list players on new round }
new list_c4_expl_injured[MAXPLAYERS+1]; // global list players who injured in the explode new number_c4_expl_injured; // Counter how many players
new list_c4_expl_died[MAXPLAYERS+1]; // global list players who died in the explode new number_c4_expl_died; // Counter how many players died
new bool:start_check; // When start check
public mycallback(Handle:event, const String:name[], bool:dontBroadcast) { PrintToServer(name); // Echo event name in server console. EXTRA
if(StrEqual(name, "round_end", false)) // This event should launch first { number_c4_expl_injured = 0; // Reset counters every round_end number_c4_expl_died = 0;
// Let's look reason index from round_end if(GetEventInt(event, "reason") == 0) // Zero should be reason index for #Target_Bombed { decl String:msg[20]; GetEventString(event, "message", msg, sizeof(msg)); PrintToServer(msg); // This is EXTRA, to show round_end message (#Target_Bombed), what tells player to print it from they own translation file: // "Cstrike_TitlesTXT_Target_Bombed" "Target successfully bombed!" // But let's forget this and continue...
// Enable check to start list players who get hurt. start_check = true;
} // This is end of round_end callback } else if(start_check && StrEqual(name, "player_hurt", false)) // start_check is enabled and these events should come after round_end ? Never know { // To be confident that player get hurt by explosion, let's check attacker. It should return #userid 0 ("world") // Player fall damage also return "world", but it's very unlikely it happens between round_end & bomb_exploded if(GetEventInt(event, "attacker") == 0) // Hurt by "world" { // Ok, let's find victim (player) new client = GetClientOfUserId(GetEventInt(event, "userid")); // Get player index using event #userid
if(client != 0) // if GetClientOfUserId(userid) return 0, client not exist anymore. { // Can't check in this point is player alive/dead, it always return alive. Let's check later // List now all players who get damage by explosion list_c4_expl_injured[number_c4_expl_injured] = client; // Add injured player in list number_c4_expl_injured++; // Count +1 } } // This is end of player_hurt callback } else if(start_check && StrEqual(name, "bomb_exploded", false)) // start_check is enabled and last event launch { start_check = false; // Stop listing players !!
new client; // temp variable to save client index new recount; // We will relist injured players
for(new a = 0 ; a < number_c4_expl_injured; a++) // Loop injured list { client = list_c4_expl_injured[a]; // pick client index from list
if(IsClientInGame(client)) // Still in game ? { if(IsPlayerAlive(client)) // Player alive!! { list_c4_expl_injured[recount] = client; // We re-add player in same list starting top recount++; // Re count new list } else // dead { list_c4_expl_died[number_c4_expl_died] = client; // List dead ones number_c4_expl_died++; } } } number_c4_expl_injured = recount // new number of injured list
// This is end of bomb_exploded callback } }
public newround(Handle:event, const String:name[], bool:dontBroadcast) { decl client; // temp variable save client index for(new a = 0 ; a < number_c4_expl_injured; a++) { client = list_c4_expl_injured[a]; if(IsClientInGame(client)) // Still in game ? { PrintToServer("> %N injured", client); } }
for(new a = 0 ; a < number_c4_expl_died; a++) { client = list_c4_expl_died[a]; if(IsClientInGame(client)) // Still in game ? { PrintToServer("- %N died", client); } } }
apologize for bad english
*edit
console output
Code:
03/06/2012 - 16:01:22: bomb_planted 0.01
03/06/2012 - 16:01:24: round_end
03/06/2012 - 16:01:24: #Target_Bombed
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: player_hurt
03/06/2012 - 16:01:24: bomb_exploded
03/06/2012 - 16:01:34: > Eric injured
03/06/2012 - 16:01:34: > Paul injured
03/06/2012 - 16:01:34: > Wyatt injured
03/06/2012 - 16:01:34: > Ethan injured
03/06/2012 - 16:01:34: > Grant injured
03/06/2012 - 16:01:34: > Mike injured
03/06/2012 - 16:01:34: > Wade injured
03/06/2012 - 16:01:34: > Nate injured
03/06/2012 - 16:01:34: > Rick injured
03/06/2012 - 16:01:34: > Adrian injured
03/06/2012 - 16:01:34: > Wayne injured
03/06/2012 - 16:01:34: > Xavier injured
03/06/2012 - 16:01:34: - Yahn died
03/06/2012 - 16:01:34: - Adam died
03/06/2012 - 16:01:34: - Nick died
03/06/2012 - 16:01:34: - Jeff died
03/06/2012 - 16:01:34: - Jason died
03/06/2012 - 16:01:34: - Keith died
03/06/2012 - 16:01:34: - Matt died
03/06/2012 - 16:01:34: - Bill died
03/06/2012 - 16:01:34: - Harold died
03/06/2012 - 16:01:34: - Reed died
03/06/2012 - 16:01:34: - Doug died
03/06/2012 - 16:01:34: - Alfred died
03/06/2012 - 16:01:34: - Chris died
03/06/2012 - 16:01:34: - Dustin died
03/06/2012 - 16:01:34: - Finn died
03/06/2012 - 16:01:34: - Dave died
03/06/2012 - 16:01:34: - Ted died
03/06/2012 - 16:01:34: - Bacardi died
*edit
Using SDKhooks
PHP Code:
#include <sdkhooks>
public OnPluginStart() { HookEventEx("round_start", rounds); HookEventEx("round_end", rounds);
for(new i = 1; i <= MaxClients; i++) { if(IsClientInGame(i)) { OnClientPutInServer(i); } } }
new list_c4_expl_injured[MAXPLAYERS+1]; // global list players who injured in the explode new number_c4_expl_injured; // Counter how many players
new list_c4_expl_died[MAXPLAYERS+1]; // global list players who died in the explode new number_c4_expl_died; // Counter how many players died
public OnClientPutInServer(client) { SDKHook(client, SDKHook_OnTakeDamagePost, OnTakeDamagePost); }