This snippet will store the player's exact death time in Survival, and print out their lifetime right when they die, and a summary of all the players at the end of the round when everyone has wiped. What I do is store the engine time at the start of the Survival run, and compare it to the engine time at the time of the player's death. GetEngineTime() seems to be pretty accurate and is precise enough to have milliseconds which is a bonus.
PHP Code:
new Float:SvStartTime;
new Float:SvDuration[MAXPLAYERS + 1];
new bool:SvRunning = false;
new bool:SvPlayersDead = false;
// Here we go!
public OnPluginStart()
{
HookEvent("create_panic_event", event_PanicEvent);
HookEvent("player_death", event_PlayerDeath);
HookEvent("round_start", event_RoundStart);
HookEvent("round_end", event_RoundEnd);
SvStartTime = GetEngineTime();
}
public Action:event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
if (!SvRunning || SvPlayersDead)
return;
new Victim = GetClientOfUserId(GetEventInt(event, "userid"));
if (!Victim || IsFakeClient(Victim))
return;
new String:VictimName[32];
GetClientName(Victim, VictimName, sizeof(VictimName));
SvDuration[Victim] = FloatSub(GetEngineTime(), SvStartTime);
new Float:tmp[3];
tmp[0] = float(RoundToFloor(FloatDiv(SvDuration[Victim], 60.0)));
tmp[1] = FloatSub(SvDuration[Victim], FloatMul(tmp[0], 60.0));
tmp[2] = FloatFraction(tmp[1]);
PrintToChatAll("\x04%s \x01has died!", VictimName);
PrintToChatAll("Time: \x04%f", SvDuration[Victim]);
PrintToChatAll("Time: \x04%2.0f:%2.2f", tmp[0], tmp[1]);
}
public Action:event_PanicEvent(Handle:event, const String:name[], bool:dontBroadcast)
{
if (SvRunning)
return;
new maxplayers = GetMaxClients();
for (new i = 1; i <= maxplayers; i++)
SvDuration[i] = 0.0;
SvStartTime = GetEngineTime();
SvRunning = true;
}
public Action:event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
SvRunning = false;
SvPlayersDead = false;
}
public Action:event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
new Float:RoundTime = GetEventFloat(event, "time");
if (RoundTime == 0)
return;
new String:Name[32];
new maxplayers = GetMaxClients();
for (new i = 1; i <= maxplayers; i++)
{
if (IsClientConnected(i) && IsClientInGame(i) && !IsFakeClient(i))
{
if (!SvDuration[i])
SvDuration[i] = RoundTime;
GetClientName(i, Name, sizeof(Name));
PrintToChatAll("\x04%s \x01duration: %f", Name, SvDuration[i]);
}
}
SvPlayersDead = true;
}
__________________