SA-MP Forums Archive
Timer and string - 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: Timer and string (/showthread.php?tid=625070)



Timer and string - Micko123 - 27.12.2016

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;




Re: Timer and string - NaS - 27.12.2016

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.


Re: Timer and string - Micko123 - 27.12.2016

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


Re: Timer and string - NaS - 27.12.2016

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.


Re: Timer and string - Micko123 - 27.12.2016

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