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 08-25-2011, 03:17 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
Post Calculating Offline Time

How would I calculate offline time? I mean how can I tell time, like in 2hrs a player would be unjailed even if he/she is offline. (I'm currently not concerned on the "setlevel2();") for when the players unjailed offline. But, I need a way to calculate time while offline. So it invokes something in 2hrs if the player is offline or not. And please explain the way simply. As timevar2 gets me confused.
__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #2  
Old 08-25-2011, 03:24 AM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is a jewel in the roughTricxta is a jewel in the rough
Use timevar, so basically...
you set the time you want the player to get out

PHP Code:
client.jailrelease=timevar+(hours*720); 
then
PHP Code:
if (client.jailrelease<timevar)
{
//release the player

I get 720 since timevar increments by 1 every 5 seconds
so 60*60/5 == 720

Edit: In case you might not fully understand timevar is just a variable that the server increments by 1 ever 5 seconds, so its forever going up. Therefore the way in which you can apply timevar is very straight forward. Timevar2 is a more accurate way of judging time(increments every .1 of a second, maybe faster lol but the basis is its a more accurate presentation of time) but I tend to avoid it when doing big time distance calculations as it just ends up giving you messy numbers. Hope this helped you.

Have fun

Last edited by Tricxta; 08-25-2011 at 03:52 AM.. Reason: just further elaboration on this
Reply With Quote
  #3  
Old 08-25-2011, 04:42 AM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
timevar2 is the one most people use because it's more accurate, as timevar increases by 1 every 5 seconds and timevar2 increases as fast as Graal runs, 1:1 ratio.
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #4  
Old 08-25-2011, 04:46 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
Why not just remove a person from jail when they log in, rather than while they are offline?
Reply With Quote
  #5  
Old 08-25-2011, 05:01 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 Switch View Post
timevar2 is the one most people use because it's more accurate, as timevar increases by 1 every 5 seconds and timevar2 increases as fast as Graal runs, 1:1 ratio.
Explain more
__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #6  
Old 08-25-2011, 12:47 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by Astram View Post
Explain more
timevar2 on the serverside is basically a UNIX time stamp with millisecond precision, but with the milliseconds moved to the decimals. You could do something similar to this:
PHP Code:
player.clientr.jailReleaseTime timevar2 3600// release in an hour 
And then just check periodically and whenever the player logs on:
PHP Code:
if (timevar2 >= player.clientr.jailReleaseTime)
  
// release the player from jail/whatever 
__________________
Reply With Quote
  #7  
Old 08-25-2011, 04:11 PM
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
Quote:
Originally Posted by Astram View Post
So it invokes something in 2hrs if the player is offline or not. And please explain the way simply. As timevar2 gets me confused.
timevar increases by 1 every 5 seconds
timevar2 increases by 1 every 1 second

With a little algebra, we can determine how much time has passed by setting a variable equal to a time variable, then later on, subtracting the variable you set from the time variable.

You can read and write some player variables even when the player is offline by creating a TServerPlayer object.

The 3 vars you are concerned with are "x", "y", and "levelname".

Here are some examples that might help you..
PHP Code:
// ex: getOfflinePlayerVar("Graal123456", "x"); 
// returns the player's x coordinate
function getOfflinePlayerVar(temp.accounttemp.varname) {
  
temp.pl = new TServerPlayer(@account);
  
temp.rtn makevar("pl." varname);
  
pl.destroy();
  return 
rtn;
}

// ex: setOfflinePlayerVar("Graal123456", "x", 30); 
// sets the player's x coordinate to 30. 
// They will login at the new position.
function setOfflinePlayerVar(temp.accounttemp.varnametemp.value) {
  
temp.pl = new TServerPlayer(@account);
  
makevar("pl." varname) = value;
  
pl.saveaccount();
  
pl.destroy();

e.
Depending on how your script works, you might not even need to use timevar or timevar2.
When you jail someone, schedule an event to release their account in however many seconds you wish...
then in the event:
PHP Code:
temp.pl findplayer(acc);
if (
pl == NULL)
  
// edit offline
else
  
// setlevel2 
Reply With Quote
  #8  
Old 08-25-2011, 04:45 PM
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
So does timevar2 go down on its own?
__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #9  
Old 08-25-2011, 07:34 PM
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 increases automatically as time goes on.
Reply With Quote
  #10  
Old 08-25-2011, 08:35 PM
ff7chocoboknight ff7chocoboknight is offline
Skyzer Zolderon
ff7chocoboknight's Avatar
Join Date: Dec 2006
Location: New Hampshire, United States
Posts: 725
ff7chocoboknight is a glorious beacon of lightff7chocoboknight is a glorious beacon of lightff7chocoboknight is a glorious beacon of light
Send a message via AIM to ff7chocoboknight Send a message via MSN to ff7chocoboknight
Didn't you already make a thread about timevar, Astram?
__________________
Reply With Quote
  #11  
Old 08-25-2011, 09:14 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
To further clarify...

On the server-side timevar2 is the amount of seconds since the unix epoch (January 1st 1970).

On the client-side timevar2 is the amount of seconds the client has been on for.

I believe timevar is the same on both server-side and client-side, it's been forever since I've actually used it though.
__________________
Quote:
Reply With Quote
  #12  
Old 08-25-2011, 09:57 PM
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
I wish Stefan would enable timevar3 for non-G3D servers.

Quote:
Originally Posted by fowlplay4 View Post
On the client-side timevar2 is the amount of seconds the client has been on for.
Except on Mac (and Linux?), where it's the number of seconds since the unix epoch, but may differ from the server's value due to a bad time setting on the client's computer.

Quote:
Originally Posted by 0PiX0 View Post
PHP Code:
// ex: getOfflinePlayerVar("Graal123456", "x"); 
// returns the player's x coordinate
function getOfflinePlayerVar(temp.accounttemp.varname) {
  
temp.pl = new TServerPlayer(@account);
  
temp.rtn makevar("pl." varname);
  
pl.destroy();
  return 
rtn;
}

// ex: setOfflinePlayerVar("Graal123456", "x", 30); 
// sets the player's x coordinate to 30. 
// They will login at the new position.
function setOfflinePlayerVar(temp.accounttemp.varnametemp.value) {
  
temp.pl = new TServerPlayer(@account);
  
makevar("pl." varname) = value;
  
pl.saveaccount();
  
pl.destroy();

You should try to avoid makevar as much as possible

PHP Code:
pl.(@ varname) = value
does the same thing, and doesn't make the object-orientation gods cry.

Quote:
Depending on how your script works, you might not even need to use timevar or timevar2.
When you jail someone, schedule an event to release their account in however many seconds you wish...
then in the event:
PHP Code:
temp.pl findplayer(acc);
if (
pl == NULL)
  
// edit offline
else
  
// setlevel2 
It's best not to use events for stuff like this since they're lost on server restart, and just create another point of failure (e.g. if the script is updated and you introduce a bug, events could not be received/set, ...). Using events is only a good idea if you use it in conjunction with a "release on" time which is checked periodically and/or on login.
__________________
Reply With Quote
  #13  
Old 08-25-2011, 10:13 PM
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
Quote:
Originally Posted by cbk1994 View Post
PHP Code:
pl.(@ varname) = value
does the same thing, and doesn't make the object-orientation gods cry.
No, it doesn't do the same thing.
PHP Code:
makevar("pl.clientr.subvar"); // works
pl.(@ "clientr.subvar"); // does not work 
Quote:
Originally Posted by cbk1994 View Post
Using events is only a good idea if you use it in conjunction with a "release on" time which is checked periodically and/or on login.
I agree with checking upon login as well to prevent any issues.
Reply With Quote
  #14  
Old 08-26-2011, 04:35 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
I made this quickly
PHP Code:
//#CLIENTSIDE
function onCreated() {
  
client.blah 0;
  
onTimeOut();
}
function 
onTimeOut() {
  
client.blah timevar2;
  
player.chat client.blah;
  
setTimer(0.05);

But, I can't seem to get it down to 0...

Edit:
I can't get on Graal but would this work.
PHP Code:
//#CLIENTSIDE
function onCreated() {
  
client.timestart client.blah;
  
onTimeOut();
}
function 
onTimeOut() {
  
client.blah timevar2;
  
player.chat client.blah -= client.timestart;
  
setTimer(0.05);

__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #15  
Old 08-26-2011, 04:37 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Astram View Post
But, I can't seem to get it down to 0...
Please read nearly every post in this thread. It's been said countless times that timevar2 is an auto-incrementing variable based on the amount of seconds since a specific time period.

If you just want a countdown do something like this:

PHP Code:
//#CLIENTSIDE
function onCreated() {
  
this.ticks 100;
  
onTimeout();
}

function 
onCreated() {
  
this.ticks--;
  
player.chat this.ticks;
  
setTimer(1);

__________________
Quote:
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 10:16 AM.


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