Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Timevar? (https://forums.graalonline.com/forums/showthread.php?t=134263174)

Astram 05-10-2011 03:23 AM

Timevar?
 
How do I use timevar and timevar2?
I'm making a stat booster for my server vortex. That buffs my stats for 20 minutes. I just need to make a way so it stops buffing after 20 minutes. I dont want to use sleep(); because it stops after the player logs out. So please help me learn timevar and timevar2. Scripthelp didnt help me so I need actual human help. :D Thanks!

Skyld 05-10-2011 03:27 AM

Well, timevar increases by 1 every 5 seconds. timevar2 is the number of seconds since the UNIX epoch (midnight 1st January 1970).

If you save timevar2's value somewhere (for example, clientr.lasttime), you can then do something like timevar2 - clientr.lasttime to see how many seconds have passed since the flag clientr.lasttime was set. You could even do something like if ((timevar2 - clientr.lasttime) > 30) which would check if the flag was set over 30 seconds ago.

The only problem is that timevar2's behaviour is not perfect on the clientside, it works differently on Windows/Mac/Linux (on Windows, it returns how many seconds the client has been open, whereas on Mac and Linux it returns the seconds since the UNIX epoch based on the system clock/timezone). On the serverside though it will work well, and should provide good relative calculations. Plain ol' timevar, on the other hand, should be the same on both clientside and serverside (it is synchronised by the client automatically), but the fact that it increases by 1 every 5 seconds makes it a much less accurate measure of time.

Astram 05-10-2011 03:54 AM

Quote:

Originally Posted by Skyld (Post 1648714)
Well, timevar increases by 1 every 5 seconds. timevar2 is the number of seconds since the UNIX epoch (midnight 1st January 1970).

If you save timevar2's value somewhere (for example, clientr.lasttime), you can then do something like timevar2 - clientr.lasttime to see how many seconds have passed since the flag clientr.lasttime was set. You could even do something like if ((timevar2 - clientr.lasttime) > 30) which would check if the flag was set over 30 seconds ago.

The only problem is that timevar2's behaviour is not perfect on the clientside, it works differently on Windows/Mac/Linux (on Windows, it returns how many seconds the client has been open, whereas on Mac and Linux it returns the seconds since the UNIX epoch based on the system clock/timezone). On the serverside though it will work well, and should provide good relative calculations. Plain ol' timevar, on the other hand, should be the same on both clientside and serverside (it is synchronised by the client automatically), but the fact that it increases by 1 every 5 seconds makes it a much less accurate measure of time.

I understand what you say, I just dont understand how to use it in a script? Can you give me a mini example?

0PiX0 05-10-2011 04:01 AM

It is a read-only variable.
Here is a simple, useless example.
PHP Code:

function onCreated() {
  
// set a variable to whatever timevar2 is currently
  
this.oldtime timevar2;
  
setTimer(5);
}

function 
onTimeout() {
  
// output the difference between the current time, and the old time to know how many seconds have passed
  
echo(timevar2 this.oldtime SPC "seconds passed");



cbk1994 05-10-2011 10:08 AM

Are you familiar with joining classes to the player serverside?


All times are GMT +2. The time now is 06:48 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.