Raised This Month: $12 Target: $400
 3% 

[L4D] Exact Player Lifetime in Survival


Post New Thread Reply   
 
Thread Tools Display Modes
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
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 04-28-2009 , 18:43   Re: [L4D] Exact Player Lifetime in Survival
Reply With Quote #2

You really should grab SvStartTime on round_start instead of OnPluginStart, seeing as how OnPluginStart is only called once the plugin is loaded, and not at the beginning of every round.
bl4nk is offline
msleeper
Veteran Member
Join Date: May 2008
Location: Atlanta, Jawjuh
Old 04-28-2009 , 18:50   Re: [L4D] Exact Player Lifetime in Survival
Reply With Quote #3

I set it in OnPluginStart as an admittedly redundant safety precaution. It actually gets set in event_PanicEvent, since that is when the actual in-game timer starts running too. Unfortunately round_start is fired when everyone is reset and respawned, not when the actual timer starts up like you think it would be.

I had to add some of the boolean checks in event_PanicEvent since that seems to be fired every time a new mob rush comes and originally it was really messing things up.

The one in OnPluginStart can be removed, I put it in there because I was reloading the plugin a lot during testing and was getting errors with the time being way way wrong.
__________________
msleeper is offline
Reply



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 22:22.


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