Reset timer
#1

I created a timer to know how long the player is connected to the server but gave it fail, it does not reset, if a player logs in now and stays 13 min, and I log in 1 hour, it will have the same time for both.

The code is this:
PHP код:
new Text:CMlt
new 
horaslt[MAX_PLAYERS], minutoslt[MAX_PLAYERS], segundoslt[MAX_PLAYERS], timerlt[MAX_PLAYERS]; 
forward CreateCMlt(); 
public 
CreateCMlt() 

    
CMlt TextDrawCreate(498.000000125.000000" "); 
    
TextDrawBackgroundColor(CMlt255); 
    
TextDrawFont(CMlt1); 
    
TextDrawLetterSize(CMlt0.5000001.000000); 
    
TextDrawColor(CMlt, -1); 
    
TextDrawSetOutline(CMlt1); 
    
TextDrawSetProportional(CMlt1); 
    return 
1

forward ccmlt(playerid); 
public 
ccmlt(playerid

    
segundoslt[playerid]++; 
    if(
segundoslt[playerid] > 59
    { 
    
segundoslt[playerid] = 0
    
minutoslt[playerid] ++; 
    if(
minutoslt[playerid] > 59
    { 
    
minutoslt[playerid] = 0
    
horaslt[playerid]++; 
    } 
    } 
    new 
ccmltstr[24]; 
    
format(ccmltstrsizeof(ccmltstr), "%02d:%02d:%02d"horasltminutosltsegundoslt); 
    
TextDrawSetString(CMltccmltstr); 
    return 
1

public 
OnPlayerConnect(playerid

timerlt[playerid] = SetTimerEx("ccmlt"1000true"d"playerid); 
return 
1

public 
OnPlayerSpawn(playerid

TextDrawShowForPlayer(playeridCMlt); 
return 
1

OnPlayerDisconnect(playerid

KillTimer(timerlt[playerid]); 
return 
1

My goal is to show a player how long he is online, for example, for me that I just logged in, 10 seconds, and for another that is already logged in an hour ago, obviously 1 hour, but this is not happening ...
The time stays the same for everyone, regardless if it is already logged in, or will log in, help me, please ...
Sorry for my bad english :/
Reply
#2

if you want to save players online time for lifetime,
use db , mysql or anything that you can save player data,
when player online, just load that.

if only one time(from player online to offline)
just reset
horaslt, minutoslt, segundoslt
when the player online
Reply
#3

https://sampwiki.blast.hk/wiki/NetStats_GetConnectedTime
Reply
#4

No, I do not want to save, I just want to show the player how much time he has spent online since logging into the server, got it? Golden, how could I adapt this function to my code? Could you give me an example?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)