Help timestamp
#1

Good morning.

A friend advised me to use timestamp, here is the principle:

I have a system of weed and I want 5h after planting (for example) the planting silk finished and I can harvest.

I used to increment timer before my variable + + every minute, but he advised me timestamp!

Could you help me?

Thx
Reply
#2

If you want something to happen (an action performed by the server) after 5 hours I don't think using only timestamps will do, you will need a timer for that. But if you are using a command to show the status of the plant for example, you can just use the timestamp to determine whether 5 hours have passed since planting.
So if you just want to check the status when somebody uses the /harvest command for example you could just calculate the difference between the saved timestamp when the weed was planted and the timestamp when the command is executed.
Reply
#3

Yes this is precisely the idea.
Wholesale after planting if 5h have not passed it can not be harvested.
Reply
#4

Something like this:

pawn Код:
if(timesaved + 18000 <= gettime())
{
    ...
}
should be put into your main timer. 'timesaved' would be whatever timestamp you set it to when planting. 18000 is 5 hours - 3600 seconds is in each hour.
Reply
#5

And how do I find the time to hour / minute / second or I plant pour save timesave?
Gettime?
Reply
#6

Just save the unix timestamp (with gettime()) and then do what brent94 recommended.
The saved timestamp will look something like 1400773076 which is the amount of seconds since January 1st, 1970. And then as brent94 stated, check whether the timestamp now (gettime() again) equals the saved timestamp + 18000 (seconds, so 5 hours). That way you don't have to worry about the format of the timestamp, so no hours or minutes.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)