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=58811)

KuJi 05-01-2005 07:06 AM

timevar
 
Recently, I was looking for documents on "timevar". I could not find any documentations on timevar. Can someone explain it or find a documentation on it for me. (I already used search ;-)).

Possibly, just explain how you would get hours/minutes/seconds out of the big long variable.

Maybe, if possible, someone can show me how to divide it correctly so it would be like hmm. Half Hour (irl) --> One day (Graal)

I would TRULY appreciate if you can show me how this would be done. (thanks)

Kaimetsu 05-01-2005 07:23 AM

Set to zero when server starts, increments every five seconds.

There are 60 seconds in a minute, 60 minutes in an hour and 24 hours in a day.

If you can't figure it out from there, you need a new hobby.

Velox Cruentus 05-01-2005 07:48 AM

seconds = (timevar*5)%60;
minutes = int((timevar*5)/60)%60;
hours = int((timevar*5)/(60*60))%24;
days = int((timevar*5)/(60*60*24));

I believe? I'm not sure. I did this pretty fast.

KuJi 05-01-2005 08:11 AM

so would it be like:

NPC Code:
//#CLIENTSIDE
if (timeout || created) {
//Some variables
setstring this.month,January,February,March,April,May,June,J uly,August,September,October,November,December;
this.minute = int(timevar/.2);
this.hour = int(this.minute/60);
this.day = int(this.hour/24);
this.month = int(this.day/31);
this.year = int(this.month/12);
this.Nminute = this.minute%60;
this.Nhour = this.hour%24;
this.Nday = this.day%24;
this.Nmonth = this.month%12;
this.Nyear = this.year%1;
//Variable Ending
if (this.Nminute < 10) setstring this.Nminute,0#v(this.Nminute);
else setstring this.Nminute,#v(this.Nminute);
if (this.Nhour > 12) setstring this.Nhour,#v(this.Nhour-12); else
if (this.Nhour == 0) setstring this.Nhour,1; else
setstring this.Nhour,#v(this.Nhour);
if (this.Nhour > 12) setstring this.time,PM; else setstring this.time,AM;
message The time is now #s(this.Nhour):#s(this.Nminute) #s(this.time) on #I(this.month,this.Nmonth-1) #v(this.Nday), #v(this.Nyear)!;
timeout = 0.05;
}





Err, I probally can code it better. But I was just rushing, how is that? Is that every 30 min --> 1 graal day?


Quote:

Originally Posted by Velox Cruentus
seconds = (timevar*5)%60;
minutes = int((timevar*5)/60)%60;
hours = int((timevar*5)/(60*60))%24;
days = int((timevar*5)/(60*60*24));

I believe? I'm not sure. I did this pretty fast.

Is that 30 minutes per graal day or no?

Velox Cruentus 05-01-2005 09:05 AM

No. That's a direct conversion of.. 1 day = 1 graal day.

Kaimetsu 05-01-2005 10:03 AM

Quote:

Originally Posted by KuJi
this.minute = int(timevar/.2);

Why the heck would you divide by 0.2 when you can multiply by 5?

KuJi 05-01-2005 04:40 PM

Quote:

Originally Posted by Kaimetsu
Why the heck would you divide by 0.2 when you can multiply by 5?

I asked a friend, he gave me the conversion.

Kaimetsu 05-01-2005 08:43 PM

Quote:

Originally Posted by KuJi
I asked a friend, he gave me the conversion.

Haha, okay.

adam 05-02-2005 04:53 PM

Because not everybody is familier with programming theory.

Velox Cruentus 05-02-2005 06:32 PM

Ah! Adam! You are the guilty person who gave the script! Note that I gave it before it was posted in real-time conversion... =3 Ohwell... I haven't heard much from you. Where've you been?

Lance 05-02-2005 07:11 PM

Quote:

Originally Posted by Velox Cruentus
seconds = (timevar*5)%60;
minutes = int((timevar*5)/60)%60;
hours = int((timevar*5)/(60*60))%24;
days = int((timevar*5)/(60*60*24));

I believe? I'm not sure. I did this pretty fast.

What do you suppose would happen if timevar incremented during the execution of your script?

Velox Cruentus 05-02-2005 07:40 PM

It will most likely not have an impact -- Considering that it would only rise of one... The only cases that it would actually matter is if it was the last second required for the minute, hour, day, so on... And while that time, it would display an entire minute/hour/day - 5 seconds more. However... The likelihood of such occurance is very minimal, and the actual damage it may cause, depending on the situation, won't matter at all.

Admins 05-02-2005 08:16 PM

"timevar" is not changed in the middle of a script execution, so you can use that securely.
On serverside you also have the option to use "timevar2" which gives the seconds since Janurar 1st 1970, and is very precise (nano seconds), but might change between the call of two script functions, but you can still assign it to some temp variable before getting the seconds, minutes etc.

Velox Cruentus 05-02-2005 11:17 PM

Ohh! "timevar2" would actually be quite useful for finding the actual date...

Wait! How do we know how much seconds past since? Considering there are leap years, and well... The amount of days in a year is something like 365.245...

Evil_Trunks 05-02-2005 11:59 PM

Almost all languages have built in functions for doing this because it's a quite complicated process.

Velox Cruentus 05-03-2005 12:46 AM

ALL!... Except Graal.

PHP Code:

function date()
{
  
this.time int(timevar2);
  
this.day int(int(this.time/(60*60*24))%365.242199);
  
this.month := find_month(this.day);
  
this.year 1970 int(this.time/(60*60*24*365.242199));

  return 
this.month[0] @ "/" @ (this.month[1] + 1) @ "/" this.year;
}

function 
find_month(day)
{
  
:= 0;
  while (
true)
  {
    if (
day days_in_month(i))
      return {
day,i};

    
day -= days_in_month(i);
    
++;
  }
}

function 
days_in_month(month)
{
  return (
month == 28 30 + (month 2));


I don't have it leap years intergrated, but the next leap year is in three years. This is what I made ;)

Admins 05-03-2005 01:10 AM

It would be possible to add a function which returns the year, month, day of the year, day of the month, day of the week, hours, minutes, and seconds for a given unix time (timevar2 + 3600*timezone)

KuJi 05-03-2005 01:53 AM

Quote:

Originally Posted by Stefan
It would be possible to add a function which returns the year, month, day of the year, day of the month, day of the week, hours, minutes, and seconds for a given unix time (timevar2 + 3600*timezone)

What about a timevar that gets the time automatically determining what timezone is put in the serveroptions:

EX


If GMT in options --> -5:00 (Daylights Saving)

then it would show automatically the time for that zone. I believe if you script something like this the time may change or be too fast/slow or just be quitely laggy. Not sure.

Time would show: 7:52 PM (time i posted this --> Eastern Time)

pacMASTA 05-03-2005 02:37 AM

Or just make it a client var for people to change for their own timezone but make it so they cant change it >_> cause its not fun when you can only play at 8:00 on server time
and something shuts at 7 and ect.

Kaimetsu 05-03-2005 02:43 AM

Quote:

Originally Posted by KuJi
What about a timevar that gets the time automatically determining what timezone is put in the serveroptions

Too inflexible. It'd be extremely easy to script using the feature Stefan described, assuming we'd be given access to timezone information.

Quote:

I believe if you script something like this the time may change or be too fast/slow or just be quitely laggy
No.

adam 05-03-2005 06:29 AM

Quote:

Originally Posted by Velox Cruentus
Ah! Adam! You are the guilty person who gave the script! Note that I gave it before it was posted in real-time conversion... =3 Ohwell... I haven't heard much from you. Where've you been?

I gave no script. Don't know a thing about it really.
I was just claiming, most people who script don't understand
what it means to make a script clean and efficient.

I just stopped by to see if anything was new, like usual.
I'm playing another mmorpg (I'll be kind and not mention it on the forums of another mmorpg)
But mostly I am working, and spending time with my girlfriend. I dont' have time for this anymore. AIM: RogueTCN I answer if i'm there. Your welcome to send a message even if it says i'm busy (which it does for days on end, even if i'm not there, or if I am there.)


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

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