SA-MP Forums Archive
GetTime - 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: GetTime (/showthread.php?tid=625775)



GetTime - Loinal - 06.01.2017

Hi guys, how to use GetTime i use mysql how can i make system saves player time played in server since he registered?


Re: GetTime - oMa37 - 06.01.2017

PHP код:
// Forwards
forward PlayerTimer(playerid);

// Some variables
new ConnectedTimer[MAX_PLAYERS], 
    
Seconds[MAX_PLAYERS], Minutes[MAX_PLAYERS],
    
Hours[MAX_PLAYERS]; 

// OnPlayerConnect
ConnectedTimer[playerid] = SetTimerEx("PlayerTimer"10001"i"playerid);

// OnPlayerDisconnect
KillTimer(ConnectedTimer[playerid]);

// Somewhere in your script

public PlayerTimer(playerid) {

    
Seconds[playerid]++
    if(
Seconds[playerid] == 60) {

        
Seconds[playerid] = 0;
        
Minutes[playerid]++;

        if(
Minutes[playerid] == 60) {

            
Minutes[playerid] = 0;
            
Hours[playerid]++
        }
    }

Please don't just copy/paste.


Re: GetTime - Loinal - 06.01.2017

Hey, i use mysql and need it to save the played time.


Re: GetTime - Luis- - 06.01.2017

Hey, try doing it yourself.


Re: GetTime - oMa37 - 06.01.2017

And you want us to tell you have to save it too? lol
Save it as integer ...


- Loinal - 06.01.2017

Iam new at mysql , sorry.

i wan to save as mysql how to save it i mean varchar? or what?


Re: GetTime - Lordzy - 06.01.2017

Quote:
Originally Posted by oMa37
Посмотреть сообщение
PHP код:
// Forwards
forward PlayerTimer(playerid);
// Some variables
new ConnectedTimer[MAX_PLAYERS], 
    
Seconds[MAX_PLAYERS], Minutes[MAX_PLAYERS],
    
Hours[MAX_PLAYERS]; 
// OnPlayerConnect
ConnectedTimer[playerid] = SetTimerEx("PlayerTimer"10001"i"playerid);
// OnPlayerDisconnect
KillTimer(ConnectedTimer[playerid]);
// Somewhere in your script
public PlayerTimer(playerid) {
    
Seconds[playerid]++
    if(
Seconds[playerid] == 60) {
        
Seconds[playerid] = 0;
        
Minutes[playerid]++;
        if(
Minutes[playerid] == 60) {
            
Minutes[playerid] = 0;
            
Hours[playerid]++
        }
    }

Please don't just copy/paste.
That's a bad practice. You can do it better using Unix timestamps. (Search)


Re: GetTime - BiosMarcel - 06.01.2017

Here is a hint:

- MySQL Datatype "Date"/"Timestamp"
- MySQL Column Default Attribute
- MySQL Function CURDATE() / NOW()
(- MySQL Function UNIX_TIMESTAMP)

Also, there is no need to save the actual difference between now and register date, since you can calculate that at any time as long as u ahve the register date


Re: GetTime - Dayrion - 06.01.2017

You can also use
pawn Код:
NetStats_GetConnectedTime(playerid)
It's in milliseconds, you can convert it in seconds, store when the player disconnect and the job is done.


Re: GetTime - Loinal - 06.01.2017

i don't want to use unix timestamp