Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


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 12:24 PM.


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