Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-10-2011, 03:23 AM
Astram Astram is offline
Era iPhone PR
Astram's Avatar
Join Date: Aug 2010
Posts: 324
Astram can only hope to improve
Send a message via AIM to Astram
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. Thanks!
__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #2  
Old 05-10-2011, 03:27 AM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
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.
__________________
Skyld
Reply With Quote
  #3  
Old 05-10-2011, 03:54 AM
Astram Astram is offline
Era iPhone PR
Astram's Avatar
Join Date: Aug 2010
Posts: 324
Astram can only hope to improve
Send a message via AIM to Astram
Quote:
Originally Posted by Skyld View Post
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?
__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #4  
Old 05-10-2011, 04:01 AM
0PiX0 0PiX0 is offline
Coder
0PiX0's Avatar
Join Date: Jan 2011
Posts: 130
0PiX0 is a jewel in the rough0PiX0 is a jewel in the rough
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");

Reply With Quote
  #5  
Old 05-10-2011, 10:08 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Are you familiar with joining classes to the player serverside?
__________________
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:47 AM.


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