Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-16-2007, 01:14 AM
godofwarares godofwarares is offline
Webmaster
godofwarares's Avatar
Join Date: Dec 2006
Location: Florida
Posts: 552
godofwarares is on a distinguished road
Send a message via ICQ to godofwarares Send a message via AIM to godofwarares Send a message via MSN to godofwarares Send a message via Yahoo to godofwarares
Current Time via Timevar2

How do I take timevar2 and manipulate it to make it display the current time?

I know this can be done, I've seen it done :o
__________________
What signature? I see no signature?
Reply With Quote
  #2  
Old 02-16-2007, 01:18 AM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
timevar2 is the number of seconds since 1/1/1970
Reply With Quote
  #3  
Old 02-16-2007, 01:28 AM
godofwarares godofwarares is offline
Webmaster
godofwarares's Avatar
Join Date: Dec 2006
Location: Florida
Posts: 552
godofwarares is on a distinguished road
Send a message via ICQ to godofwarares Send a message via AIM to godofwarares Send a message via MSN to godofwarares Send a message via Yahoo to godofwarares
I know that, I didn't need a definition >_>

But I guess i'll experiment.
__________________
What signature? I see no signature?
Reply With Quote
  #4  
Old 02-16-2007, 01:29 AM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Quote:
Originally Posted by godofwarares View Post
I know that, I didn't need a definition >_>

But I guess i'll experiment.


Do the math x-x
Reply With Quote
  #5  
Old 02-16-2007, 01:40 AM
Riot Riot is offline
Delteria Management
Join Date: Nov 2003
Location: Seminole County, Florida
Posts: 280
Riot is on a distinguished road
There are two scripts on Graal.net you might want to look at:

http://graal.net/snippet/detail.php?type=snippet&id=68
http://graal.net/snippet/detail.php?type=snippet&id=84
Reply With Quote
  #6  
Old 02-16-2007, 03:09 AM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
I have something that does this well, but is really 'barebone' right now. Once I document it and add some higher level functions, then I'll post it in the code gallery.

If you can't wait, you can also look at various time.c source files and check out the function 'gmtime'.
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #7  
Old 02-16-2007, 08:20 AM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
I requested a date() and now() function. Don't think anything will happen though .
Reply With Quote
  #8  
Old 02-17-2007, 12:28 AM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
It probably won't be too tough to write this soon, once a version with timevar3 is released (so it can be on both server- and clientside).
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #9  
Old 02-17-2007, 01:17 AM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
Ok, this is very barebone, but maybe you can make use of it. All of the hard math stuff has been done already.

PHP Code:
enum {
  
SEC,   //Seconds
  
MIN,   //Minutes
  
HOUR,  //Hours
  
WDAY,  //Day of the week (0:Sunday to 6:Saturday)
  
YEAR,  //Year
  
YDAY,  //Day of the year (starts at 0)
  
MON,   //Month (0:January to 11:December)
  
MDAY   //Day of the Month
}
const 
EPOCH_YR 1970;          //Epoch Year
const SECS_DAY 24 60 60;  //Seconds in a day

/**
  gmtime():
    Returns array (see enum)
 */
function gmtime(tvar) {
  
temp.result;
  
temp.dayclocktemp.dayno;
  
temp.year;
  
  
result = new[8];
  
year EPOCH_YR;
  
dayclock tvar SECS_DAY;
  
dayno tvar SECS_DAY;

  
result[SEC] = dayclock 60;
  
result[MIN] = (dayclock 3600) / 60;
  
result[HOUR] = dayclock 3600;
  
result[WDAY] = (dayno 4) % 7;  //Epoch starts on a Thurs.
  
  
while (dayno >= YEARSIZE(year)) {
    
dayno -= YEARSIZE(year);
    
year++;
  }
  
  
result[YEAR] = year;
  
result[YDAY] = dayno;
  
result[MON] = 0;
  while (
dayno >= this._ytab[LEAPYEAR(year)][result[MON]]) {
    
dayno -= this._ytab[LEAPYEAR(year)][result[MON]];
    
result[MON]++;
  }
  
result[MDAY] = dayno 1;
  
  return 
result;
}

function 
LEAPYEAR(year) {
  return (!((
year) % 4) && (((year) % 100) || !((year) % 400)));
}

function 
YEARSIZE(year) {
  return (
LEAPYEAR(year) ? 366 365)

Here is code that initializes some pseudo-const arrays and a little bit of sample code that will make use of the array that gmtime returns:
PHP Code:
//Pseudo-constarrays
function constArrays() {
  
//I WANT CONST ARRAYS!
  
this._ytab = {
    {
312831303130313130313031},
    {
312931303130313130313031}
  };
  
this._days = {
    
"Sunday""Monday""Tuesday""Wednesday",
    
"Thursday""Friday""Saturday"
  
};
  
this._months = {
    
"January""February""March",
    
"April""May""June",
    
"July""August""September",
    
"October""November""December"
  
};
  
//STILL WANT CONST ARRAYS!
}
function 
onCreated() {
  
constArrays();

  
//Sample Code
  
temp.result;
  
result gmtime(timevar2 60*60*8);  //GMT - 8
  
printf("Time (Pacific): %d:%d:%d"result[HOUR], result[MIN], result[SEC]);
  
printf("Date (Pacific): %s, %s %d, %d"this._days[result[WDAY]], this._months[result[MON]], result[MDAY], result[YEAR]);

Again, this is just all the math stuff done for you. If I get around to making functions that will return a date/time based on a format string (like PHP's time() function), I will release it in the code gallery, but maybe this can get you started with whatever you need to do.
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.

Last edited by napo_p2p; 02-17-2007 at 01:52 AM..
Reply With Quote
  #10  
Old 02-17-2007, 02:17 AM
godofwarares godofwarares is offline
Webmaster
godofwarares's Avatar
Join Date: Dec 2006
Location: Florida
Posts: 552
godofwarares is on a distinguished road
Send a message via ICQ to godofwarares Send a message via AIM to godofwarares Send a message via MSN to godofwarares Send a message via Yahoo to godofwarares
Cool :o
__________________
What signature? I see no signature?

Last edited by godofwarares; 02-17-2007 at 10:13 PM.. Reason: Hehe this is my 100th post ^^
Reply With Quote
  #11  
Old 02-17-2007, 02:28 AM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
Quote:
Originally Posted by godofwarares View Post
Cool :o
I should probably mention that the gmtime() function takes a single parameter, which is the timestamp that you want converted from 'epoch time' to 'real time'.
It returns an array, and the indexes correspond with the enum defined at the beginning of the script.
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #12  
Old 02-17-2007, 03:09 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Hmmm
We could add a date() function which is similar to format,
e.g. date("%Y-%m-%d",timevar2[,timezone]) which would print the time variable in a readable format. That would work on serverside-only though, the clientside timevar2 is not synchronized to the correct unix time yet (there is timevar3 on Graal3D though).
Reply With Quote
  #13  
Old 02-17-2007, 03:13 AM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
Quote:
Originally Posted by Stefan View Post
Hmmm
We could add a date() function which is similar to format,
e.g. date("%Y-%m-%d",timevar2[,timezone]) which would print the time variable in a readable format. That would work on serverside-only though, the clientside timevar2 is not synchronized to the correct unix time yet (there is timevar3 on Graal3D though).
Yeah, that what I've been planning to do, but it would be better if it were built-in.

How far is timevar2 off? Only by a couple of seconds at most, it seems.
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #14  
Old 02-17-2007, 02:25 PM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
timevar2 on the client is your computer's time if I recall correctly.
__________________
Do it with a DON!
Reply With Quote
  #15  
Old 02-17-2007, 03:09 PM
godofwarares godofwarares is offline
Webmaster
godofwarares's Avatar
Join Date: Dec 2006
Location: Florida
Posts: 552
godofwarares is on a distinguished road
Send a message via ICQ to godofwarares Send a message via AIM to godofwarares Send a message via MSN to godofwarares Send a message via Yahoo to godofwarares
I'm wondering why timevar3 hasn't been released yet?
__________________
What signature? I see no signature?
Reply With Quote
Reply


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 05:59 PM.


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