Total Time Played

Started by Coolkid, Mar 30, 2016, 02:00 AM

Previous topic - Next topic

Coolkid

hi guys i am not asking for any codes i just want to ask how can i get total time played

Mötley

#1
You should look into if someone had a code for server uptime and convert it into game time(when the player is authorized in the accounting system the gametime should run, careful of lagging the player, There is ways to do this with a timer, you should be capable of doing this in a players class)

Found something

http://forum.vc-mp.org/?topic=1523.msg10735#msg10735

Mötley


KAKAN

more easy one:
function onScriptLoad(){
ptime <- array(100,0);
}
function onPlayerJoin( player ){
ptime[ player.ID ] = time();
}
function onPlayerCommand( player, cmd, text ){
if( cmd == "MyPlayTime" ) PrivMessage(player,"You have played for: " + ( time() - ptime[ player.ID ] ) + " seconds." );
}
Save it in a database.
oh no

.

#4
I don't get why this was so hard to even begin with :-\

// Should be executed at server start up
g_PlayerUptime <- array(GetMaxPlayers(), 0);

// Returns an integer with the player uptime (in seconds)
function PlayerUptime(player_id)
{
    // Is this player even tracked?
    if (g_PlayerUptime[player_id] == 0)
    {
        return 0; // No uptime!
    }
    // Return the difference
    return (::time() - g_PlayerUptime[player_id]);
}

// Returns a string with the player uptime
function PlayerUptimeStr(player_id)
{
    // Get the uptime
    local s = PlayerUptime(player_id);
    // Get the days
    local d = (((s/60)/60)/24);
    // Remove the days
    s -= (((d*60)*60)*24);
    // Get the hours
    local h = ((s/60)/60);
    // Remove the hours
    s -= ((h*60)*60);
    // Get the minutes
    local m = (s/60);
    // Remove the minutes
    s -= (m*60);
    // Format the time string
    return ::format(@"%d day%s, %d hour%s, %d minute%s, %d seconds%s",
                    d, (d == 1 ? "": "s"),
                    h, (h == 1 ? "": "s"),
                    m, (m == 1 ? "": "s"),
                    s, (s == 1 ? "": "s")
    );
}

function onPlayerJoin(player)
{
    // Initialize the connection time-stamp
    g_PlayerUptime[player.ID] = time();
}

function onPlayerPart(player, reason)
{
    // Reset the connection time-stamp
    g_PlayerUptime[player.ID] = 0;
}

function onPlayerCommand(player, cmd, text)
{
    if(cmd == "playtime")
    {
        PrivMessage(player, "You've' played for: " +  PlayerUptimeStr(player.ID));
    }
}
.

Thijn

if (g_PlayerUptime == 0) should probably be if (g_PlayerUptime[player_id] == 0)