SA-MP Forums Archive
Time Stamps - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Time Stamps (/showthread.php?tid=553912)



Time Stamps - kesarthakur - 01.01.2015

pawn Код:
new gOnlineTime[MAX_PLAYERS];

enum pInfo
{
    Hours,
    Minutes,
    Seconds
}
new PlayerInfo[MAX_PLAYERS][pInfo];

public OnPlayerConnect(playerid)
{
    gOnlineTime[playerid] = gettime();
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    PlayerInfo[playerid][Seconds] = gettime() - gOnlineTime[playerid];
    PlayerInfo[playerid][Minutes] = PlayerInfo[playerid][Seconds] / 60;
    PlayerInfo[playerid][Hours] = PlayerInfo[playerid][Minutes] / 60;
    INI_WriteInt(File, "Hours", PlayerInfo[playerid][Hours]);
    INI_WriteInt(File, "Minutes", PlayerInfo[playerid][Minutes]);
    INI_WriteInt(File, "Seconds", PlayerInfo[playerid][Seconds]);
    return 1;
}


Is this is the way to save hours minutes seconds of a player's online time through timestamps??
i know it is possibly wrong so im asking here..

if not can please correct me and help me

please help me

Thanks for reading


Re: Time Stamps - rickisme - 01.01.2015

pawn Код:
new gOnlineTime[MAX_PLAYERS];

enum pInfo
{
    Hours,
    Minutes,
    Seconds
}
new PlayerInfo[MAX_PLAYERS][pInfo];

public OnPlayerConnect(playerid)
{
    gOnlineTime[playerid] = gettime();
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new h,m,s,diff;
    diff = gettime() - gOnlineTime[playerid];
    h = floatround(diff / 3600, floatround_floor);
    m = floatround((diff - h * 3600) / 60, floatround_floor);
    s = diff - h * 3600 - m * 60;
    printf("playerid %d play %d hours %d minutes %d secconds in this session", playerid, h, m, s);

    return 1;
}
Sorry for my bad english


Re: Time Stamps - kesarthakur - 01.01.2015

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new h,m,s,diff,th,tm,ts;
    diff = gettime() - gOnlineTime[playerid];
    h = floatround(diff / 3600, floatround_floor);
    m = floatround((diff - h * 3600) / 60, floatround_floor);
    s = diff - h * 3600 - m * 60;
    players_connected--;
    th = PlayerInfo[playerid][Hours] + h;
    tm = PlayerInfo[playerid][Minutes] + m;
    ts = PlayerInfo[playerid][Seconds] + s;
    PlayerInfo[playerid][Seconds] = ts;
    PlayerInfo[playerid][Minutes] = tm;
    PlayerInfo[playerid][Hours] = th;
    return 1;
}
This isnt working

please help me


Re: Time Stamps - dusk - 01.01.2015

pawn Код:
new gConnectTimestamp[MAX_PLAYERS], gOnlineTime[ MAX_PLAYERS ];



public OnPlayerConnect(playerid)
{
   gConnectTimestamp[ playerid ] = gettime();
   
   // I will assume that you will load seconds online into "gOnlineTime"
}

public OnPlayerDisconnect(playerid, reason)
{
    gOnlineTime[ playerid ] += gettime() - gConnectTimestamp[ playerid ];
    // If you didnt ignore my previous comment the "gOnlineTime" will now contain the total seconds connected.
}



Re: Time Stamps - kesarthakur - 01.01.2015

How can i save them as hours and minutes now??

Please help me...

* kesarthakur Noob Scripter


Re: Time Stamps - rickisme - 01.01.2015

You don't need to save them hours, minutes
Cause it's can be calculator by secconds

look at dusk post, i just explain how to get total hours / minutes / secs they already played from secconds

here's a example, it's will show total time you already played on server when you type "/playedtime"

pawn Код:
new gOnlineTime[MAX_PLAYERS];

enum pInfo
{
    Hours,
    Minutes,
    Seconds
}
new PlayerInfo[MAX_PLAYERS][pInfo];
stock GetPlayerOnlineTime(playerid)
{
    new h,m,s,diff, str[128];
    diff = PlayerInfo[playerid][Seconds] + (gettime() - gOnlineTime[playerid]);
    h = floatround(diff / 3600, floatround_floor);
    m = floatround((diff - h * 3600) / 60, floatround_floor);
    s = diff - h * 3600 - m * 60;
    format(str, sizeof str, "Total time already play: %d hours %d minutes %d secconds", h, m, s);
    SendClientMessage(playerid, -1, str);
}
public OnPlayerConnect(playerid)
{
    gOnlineTime[playerid] = gettime();
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    PlayerInfo[playerid][Seconds] += gettime() - gOnlineTime[playerid];
    INI_WriteInt(File, "Seconds", PlayerInfo[playerid][Seconds]);
    return 1;
}

CMD:playedtime(playerid, params[])
{
    // check they connected, blah blah
    GetPlayerOnlineTime(playerid);
}



Re: Time Stamps - kesarthakur - 01.01.2015

i got you but i also want to store PlayerInfo[playerid][Minutes] PlayerInfo[playerid][Hours] tooo

please help me


Re: Time Stamps - rickisme - 01.01.2015

nvm, read ****** post


Re: Time Stamps - kesarthakur - 01.01.2015

Quote:
Originally Posted by ******
Посмотреть сообщение
Why? Storing minutes and hours is extra data you don't need - it can be calculated directly from seconds and only complicates your code. The thing that all the code so far is missing is loading. When a player connects, you should load the stored playing time, to add on to the playing time from the current session, otherwise you will only save their last play time not their total play time.
Thanks for your suggestion..
can u tell me how to add on the playing time from the current session...??

Please help me..


Re: Time Stamps - Virtual1ty - 01.01.2015

People have posted multiple codes and examples, check the response from dusk.