GetTime
#1

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

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.
Reply
#3

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

Hey, try doing it yourself.
Reply
#5

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

Iam new at mysql , sorry.

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

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)
Reply
#8

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
Reply
#9

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.
Reply
#10

i don't want to use unix timestamp
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)