SA-MP Forums Archive
the time command - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: the time command (/showthread.php?tid=254877)



the time command - Swiftz - 13.05.2011

I want to make this command, To make someone leader for specific amount of time (in days) . If the define is playerinf(leader) = 0 (For not leader) 1 for leader. So if the time ends. It should automatically bcum playerinf(leader) = 0. leader variable will be ofcourse stored in userfiles. So how to make this? i think we need to store the days in a file and something, Please help


Re: the time command - Mike Garber - 13.05.2011

xkirill's code wont work, You have to use SetTimerEx


Re: the time command - __ - 13.05.2011

Store a Unix Timestamp in the player's character file.

Unix Timestamps are the amount of seconds it has been since January 1 1970, these are commonly used for anything related to temporary functions in most programming languages, usage of a Unix Timestamp for this would be ideal.

Store a timestamp in the character's file (an integer) saving what time they should lose their leadership, so you get the current unix time/stamp using gettime() without any parameters, then add however many seconds you need to it, then when the player logs back in - see if their timestamp you saved exceeds the current gettime(), do it for every login.

The code below demonstrates an example of how you can get a timestamp properly.

pawn Код:
CMD:iwanttolead(playerid, params[]) {
   // gettime() + 86400; << Gets the timestamp for tomorrow, at the exact same time
   new iDays = strval(params) * 86400; // strval(params) is the days entered, multiplied by how many seconds are in a day
   new iDynamicTime = gettime() + iDays; // Add the amount of seconds we need and we've got our timestamp
   return 1;
}



Re: the time command - Swiftz - 13.05.2011

Actually will that still count time after restart?


Re: the time command - __ - 13.05.2011

Yes, it will if you save the timestamp to an account file or use another way of saving data.