Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-28-2008, 10:13 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
Functions to get the current time

I've written some functions to return the current time of the day, even in seconds. Seconds isn't that accurate because I'm using timevar, but it should do. The functions using timevar also means you can use this both clientside and serverside, which comes in pretty handy sometimes.
The only problem is that it is off when your servertime is off, and the timezone is also the one the server is in/the servertime is set to. You can adjust this by yourself though, shouldn't be a huge problem.
I hope you can find some use for this!

PHP Code:
//time functions
function getDayTime() {
  
//timevar * 5, it incs by 1 every 5 secs; - 30 secs; - 26 mins; - 4 hours
  
temp.fixedTimeVar = ((timevar 5)        - 30       60 26  60 60 4);
  return 
fixedTimeVar # 86400;
}

public function 
getTimeHours() {
  
temp.var = intgetDayTime() / 3600 );
  return (
temp.var < 10 "0" temp.var : temp.var);
}
public function 
getTimeMinutes() {
  
temp.var = int( (getDayTime() # 3600) / 60 );
  
return (temp.var < 10 "0" temp.var : temp.var);
}
public function 
getTimeSeconds() {
  
temp.var = intgetDayTime() # 60 );
  
return (temp.var < 10 "0" temp.var : temp.var);

Note: Replace the # with %, the html code for it won't work in [php] tags.


Edit: Changed some code, less lines now, and I changed something that didn't really make sense after all, I have no idea why I divided by 10 in the first place...oh yea, and I forgot to mention, if the hours/minutes/seconds are smaller than 10 (so basically only one digit), it adds a 0 infront of it.

Last edited by Crow; 07-29-2008 at 01:19 PM..
Reply With Quote
  #2  
Old 07-28-2008, 10:14 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
http://forums.graalonline.com/forums...ad.php?t=72260

Good job, but it's already been done.
__________________
Reply With Quote
  #3  
Old 07-28-2008, 10:19 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
Ah, dangit, I didn't see that. Seems a bit complicated though, maybe if people want something simple?
Reply With Quote
  #4  
Old 07-28-2008, 10:25 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
Quote:
Originally Posted by Crow View Post
Ah, dangit, I didn't see that. Seems a bit complicated though, maybe if people want something simple?
Yours doesn't get the date though, which can be very important in some cases (e.g. logging stuff).
__________________
Reply With Quote
  #5  
Old 07-29-2008, 12:11 AM
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
My functions aren't made for logging purposes ;f
Reply With Quote
  #6  
Old 07-29-2008, 03:42 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Neat, great job
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #7  
Old 07-29-2008, 03:52 AM
TheStan TheStan is offline
Stan?
Join Date: May 2008
Location: U.S.
Posts: 100
TheStan is on a distinguished road
Send a message via AIM to TheStan Send a message via MSN to TheStan
Good Job Crow.
Reply With Quote
  #8  
Old 07-29-2008, 12:43 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Me like simpleness :]

And Chris, Kristi's is more advanced and is serverside..
Crow's simple and works on both sides =]
__________________
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 01:56 PM.


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