Just some "gettime" questions.
#1

How does it exactly work?
Can you actually create commands like /SetTempAdmin with the gettime, or do you need something else?
Can you create a command(Most likely in '/stats'), that shows for how long the player has been online, or do you again need to do something else?
If it's possible, could someone give me some examples(Optional, but i would want to see some examples of the gettime function, since wikipedia didn't teach me anything..)
Reply
#2

The function on its own, without parameters, returns a unix timestamp; the number of seconds elapsed since the epoch on 1/1/1970. If you (for example) want to give someone a premium account for a month, you add 2678400 seconds to the current timestamp (60 seconds in a minute, times 60 minutes in an hour, times 24 hours in a day, times 31 days in a month). Then save that new value in their account. Every time they log in, check if the value is smaller than the current timestamp. If it is, then their premium has expired.

You can also measure time. Save a timestamp once they log on. When they log off get the current timestamp and subtract the one you saved earlier. You will end up with a value in seconds, which can be converted to hours and minutes.
Reply
#3

here's an example of how it works:

Quote:
Originally Posted by CutX
Посмотреть сообщение
okey, this method works until January 19, 2038

store the timestamp of the actual time a player wins the VIP thingy in your player files

tempVIP[playerid] = gettime();

now to check if 1 day has passed, we just do this:

if(tempVIP[playerid])
{
if(gettime() - tempVIP[playerid] > 60*60*24) return //vip time is up remove the vip state
}

we can place that if statement somewhere where it gets called like every 3 or 5 seconds. We dont need a dirty timer
for example, place it in OnPlayerStatechange
time will still "pass by" even if the server is offline since were doing the timestamp-method
its indeed a nice n resource friendly replacement for any kind of timer
Reply
#4

Alright, thanks.
@CutX - I didn't really understand that example D:
But still, thanks for helping.
So, basically, if i would want to create a SetTempLevel command
I would need to do
pAdminTemp[playerid] = gettime();

if(pAdminTemp[playerid])
{
...etc..?
}
Or something like that?D:
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)