Raised This Month: $ Target: $400
 0% 

[L4D] Exact Player Lifetime in Survival


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
msleeper
Veteran Member
Join Date: May 2008
Location: Atlanta, Jawjuh
Old 04-28-2009 , 17:00   [L4D] Exact Player Lifetime in Survival
Reply With Quote #1

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(VictimVictimNamesizeof(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 
1<= maxplayersi++)
        
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 
1<= maxplayersi++)
    {
        if (
IsClientConnected(i) && IsClientInGame(i) && !IsFakeClient(i))
        {
            if (!
SvDuration[i])
                
SvDuration[i] = RoundTime;

            
GetClientName(iNamesizeof(Name));
            
PrintToChatAll("\x04%s \x01duration: %f"NameSvDuration[i]);
        }
    }

    
SvPlayersDead true;

__________________
msleeper is offline
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:58.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode