Timer and string
#1

PHP код:
format(stringsizeof(string), ""SERVERBLUE"[ AFK ]\n"WHITE"Time: %d:%d:%d"hoursminutesseconds);
        
AFKLabel[i] = CreateDynamic3DTextLabel(string0x1D9F00AAXYZ+110.0INVALID_PLAYER_IDINVALID_VEHICLE_ID0, -1, -1, -120.0); 
I have timer and time should be updated. Problem is that when I go afk it says 0:0:1 and it is always like that.. But when I debug it it updates seconds.. I don' get it..

Here is the func
PHP код:
forward AFKtimer();
public 
AFKtimer()
{
    foreach(new 
iPlayer)
    {
        new 
Float:XFloat:YFloat:Zstring[90], hours 0minutes 0seconds 0;
        
GetPlayerPos(iXYZ);
        
seconds++;
        if(
seconds == 60)
        {
            
minutes ++;
            
seconds 0;
        }
        else if(
minutes == 60)
        {
            
hours ++;
            
minutes 0;
            
seconds 0;
        }
        
format(stringsizeof(string), ""SERVERBLUE"[ AFK ]\n"WHITE"Time: %d"seconds);
        
AFKLabel[i] = CreateDynamic3DTextLabel(string0x1D9F00AAXYZ+110.0INVALID_PLAYER_IDINVALID_VEHICLE_ID0, -1, -1, -120.0);
        return 
1;
    }
    return 
1;

Reply
#2

I don't get what are you doing there.

hours, minutes and seconds are initialized with zero, then you higher seconds by one.

It will always be that since the variables are local and will be initialized with zero for every player, everytime.

Make those global, or use GetTickCount() to simply calculate the time between the moment the player went AFK and now.

Furthermore your timer will only execute for one single player. Remove the "return 1;" inside the loop.
Reply
#3

Quote:
Originally Posted by NaS
Посмотреть сообщение
I don't get what are you doing there.

hours, minutes and seconds are initialized with zero, then you higher seconds by one.

It will always be that since the variables are local and will be initialized with zero for every player, everytime.

Make those global, or use GetTickCount() to simply calculate the time between the moment the player went AFK and now.
Dang I just realised that....haahahahaha I am stupid :d Thank you for pointing that out m8
Repped
Reply
#4

Quote:
Originally Posted by Micko123
Посмотреть сообщение
Dang I just realised that....haahahahaha I am stupid :d Thank you for pointing that out m8
Repped
No problem, happens sometimes

Try the timestamp method, it's way more precise and in my opinion even easier.
Reply
#5

Quote:
Originally Posted by NaS
Посмотреть сообщение
No problem, happens sometimes

Try the timestamp method, it's way more precise and in my opinion even easier.
I will.. Thx
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)