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 12-22-2004, 04:08 AM
ZeroTrack ZeroTrack is offline
G2K1 Developer
ZeroTrack's Avatar
Join Date: Apr 2004
Location: LongIsland, NY
Posts: 402
ZeroTrack is on a distinguished road
Send a message via AIM to ZeroTrack
Convert Graal Seconds

I am not sure if a lot of people are looking for this but i guess I just decided to post this here cause some people have asked me for it but this is a simple way to convert graal seconds into a readable format.
As you read this equation remember that % is a modification that simply makes it so that var a - int(a/b)*b is the same as var a%b. Lets say the var playeronlinetime returned 96351 which is equal to 26:45:51


Conversion to hours:
This is the easiest to do simply take the players online time (playeronlinetime) and divide by the number of seconds in a minute and the number of minutes in an hour.
NPC Code:
#v(playeronlinetime/(60*60))



Now you’re not quite done yet you should get some sort of decimal number returned there in this case it would be 26.76416. You want to take just the integer of that number or in gscript int. So now your code should like this
NPC Code:
#v(int(playeronlinetime/(60*60)))


Now you have your hours 26.

Conversion to minutes:
This is where most run into problems. Here we are going to start off the same but because we are only looking for the minutes we are going to just divide the number of seconds in a minute. So we start off with:
NPC Code:
#v(playeronlinetime/60)



This should return 1605.85. Now as you can see this IS 96351 seconds converted into minutes , but this wont do for the format we are looking for so its time to do a little modification and we should get rid of that nasty decimal as well, considering we are only need the integer of the number
NPC Code:
#v(int(playeronlinetime/60)%60)



Now you might ask why it is moded to 60, the answer is cause that’s how many minutes there are in 1 hour. Get it now? On to seconds

Conversion to seconds:
Back to the real easy part considering now you know what the mod does all you have to do mod the total number of seconds is returned.
NPC Code:
#v(playeronlinetime%60)



Only this time we did not have to take the integer on the variable because it already returns a whole number.

That concludes my quick little run through of how to make a time conversion script. There is one more thing you could do if you want to get fancy you could add the number of days online, but I wouldn't want to ruin your fun just remember there are 24 hours in a day .
__________________

Reply With Quote
  #2  
Old 12-22-2004, 07:03 PM
ZeroTrack ZeroTrack is offline
G2K1 Developer
ZeroTrack's Avatar
Join Date: Apr 2004
Location: LongIsland, NY
Posts: 402
ZeroTrack is on a distinguished road
Send a message via AIM to ZeroTrack
People say this thread is too complex... its simple math and explaining 2 commands while showing your how-to use the playeronlinetime var, whats so complex about it
__________________

Reply With Quote
  #3  
Old 12-23-2004, 12:07 AM
MysticalDragon MysticalDragon is offline
Global Administration
MysticalDragon's Avatar
Join Date: Oct 2002
Location: Lynn Ma
Posts: 883
MysticalDragon is a jewel in the roughMysticalDragon is a jewel in the rough
Send a message via AIM to MysticalDragon Send a message via MSN to MysticalDragon
Doesnt seem Complex at all.
__________________
~Delteria Support
~Playerworld Support
~PWA Chief
http://support.toonslab.com
[email protected]



Reply With Quote
  #4  
Old 12-23-2004, 06:56 AM
Slash-P2P Slash-P2P is offline
Banned
Join Date: May 2004
Location: Burning Blade
Posts: 941
Slash-P2P is on a distinguished road
playeronlinetime returns 0 for me.
Reply With Quote
  #5  
Old 12-23-2004, 08:41 AM
Python523 Python523 is offline
Banned
Join Date: Aug 2001
Location: Illinois
Posts: 3,498
Python523 is on a distinguished road
Too many unneeded calculations. Modulus is pretty inefficient to use repeatedly, I think. You can use the seconds to calculate the minutes and the minutes to calculate the seconds...

NPC Code:

if (created) {
with (getplayer(Python523)) {
this.temp = playeronlinetime;
}
this.temp = this.temp / 60^2;
this.realhrs = int(this.temp);
this.temp = this.temp - this.realhrs;
this.temp *= 60;
this.realmin = int(this.temp);
this.temp = this.temp - this.realmin;
this.temp *= 60;
sendtonc H: #v(this.realhrs) M: #v(this.realmin) S: #v(this.temp);
}

Reply With Quote
  #6  
Old 12-23-2004, 09:04 AM
ZeroTrack ZeroTrack is offline
G2K1 Developer
ZeroTrack's Avatar
Join Date: Apr 2004
Location: LongIsland, NY
Posts: 402
ZeroTrack is on a distinguished road
Send a message via AIM to ZeroTrack
i donno ... theres seems to be less code doing it my way no?

NPC Code:

if(created){
with(getplayer(ZeroTrack))
setstring this.temp,#v(int(playeronlinetime/(60*60*24)))D:#v(int(playeronlinetime/(60*60))%24)H:#v(int((playeronlinetime/60)%60))M;
sendtonc #s(this.temp);
}

__________________

Reply With Quote
  #7  
Old 12-23-2004, 09:10 AM
Python523 Python523 is offline
Banned
Join Date: Aug 2001
Location: Illinois
Posts: 3,498
Python523 is on a distinguished road
Quote:
Originally Posted by ZeroTrack
i donno ... theres seems to be less code doing it my way no?

NPC Code:

if(created){
with(getplayer(ZeroTrack))
setstring this.temp,#v(int(playeronlinetime/(60*60*24)))D:#v(int(playeronlinetime/(60*60))%24)H:#v(int((playeronlinetime/60)%60))M;
sendtonc #s(this.temp);
}

Less code doesn't make something more efficient. Do you even know how modulus works?
Reply With Quote
  #8  
Old 12-23-2004, 09:25 AM
ZeroTrack ZeroTrack is offline
G2K1 Developer
ZeroTrack's Avatar
Join Date: Apr 2004
Location: LongIsland, NY
Posts: 402
ZeroTrack is on a distinguished road
Send a message via AIM to ZeroTrack
yes i do, how else would i be able to know how to use them, i've been programing for over 5 years thats when i first started gscript as well , i really hate the lack of credit people give me just cause i am not "in" with the higher ups or post tut's here all the time, and its seems to run prefectly clean and without lag , even in a loop.
__________________

Reply With Quote
  #9  
Old 12-23-2004, 09:27 AM
ZeroTrack ZeroTrack is offline
G2K1 Developer
ZeroTrack's Avatar
Join Date: Apr 2004
Location: LongIsland, NY
Posts: 402
ZeroTrack is on a distinguished road
Send a message via AIM to ZeroTrack
Quote:
Originally Posted by Slash-P2P
playeronlinetime returns 0 for me.
its serverside slash =p
__________________

Reply With Quote
  #10  
Old 12-23-2004, 10:07 AM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
Quote:
Originally Posted by ZeroTrack
its seems to run prefectly clean and without lag , even in a loop.
That doesn't mean it's the most efficient approach.
__________________
Reply With Quote
  #11  
Old 12-23-2004, 04:11 PM
ZeroTrack ZeroTrack is offline
G2K1 Developer
ZeroTrack's Avatar
Join Date: Apr 2004
Location: LongIsland, NY
Posts: 402
ZeroTrack is on a distinguished road
Send a message via AIM to ZeroTrack
Quote:
Originally Posted by Kaimetsu
That doesn't mean it's the most efficient approach.
no it doesn't, but it does run more efficiently
__________________

Reply With Quote
  #12  
Old 12-23-2004, 04:13 PM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
Quote:
Originally Posted by ZeroTrack
no it doesn't, but it does run more efficiently
Than Jagen's method? What's your reasoning for this?
__________________
Reply With Quote
  #13  
Old 12-23-2004, 04:18 PM
ZeroTrack ZeroTrack is offline
G2K1 Developer
ZeroTrack's Avatar
Join Date: Apr 2004
Location: LongIsland, NY
Posts: 402
ZeroTrack is on a distinguished road
Send a message via AIM to ZeroTrack
I uploaded both with the same loop and his came up as one of the top 10 taking cpu time...
__________________

Reply With Quote
  #14  
Old 12-23-2004, 04:32 PM
Python523 Python523 is offline
Banned
Join Date: Aug 2001
Location: Illinois
Posts: 3,498
Python523 is on a distinguished road
Quote:
Originally Posted by ZeroTrack
yes i do, how else would i be able to know how to use them, i've been programing for over 5 years thats when i first started gscript as well , i really hate the lack of credit people give me just cause i am not "in" with the higher ups or post tut's here all the time, and its seems to run prefectly clean and without lag , even in a loop.
Being able to use something and understanding how it works are two totally different things. Let me try to rephrase.
You know how it works. Do you know why it works that way?

Quote:
Originally Posted by ZeroTrack
I uploaded both with the same loop and his came up as one of the top 10 taking cpu time...
I would either blame the way you implemented it or the graal engine itself. Mathematically, my way is superior and requires less processing.
Reply With Quote
  #15  
Old 12-23-2004, 04:38 PM
ZeroTrack ZeroTrack is offline
G2K1 Developer
ZeroTrack's Avatar
Join Date: Apr 2004
Location: LongIsland, NY
Posts: 402
ZeroTrack is on a distinguished road
Send a message via AIM to ZeroTrack
Jagen i know how commands work and why it does, this is how a programers brain works thats the only way i can really learn things it ask 'why', please dont question my ability to understand commands...

i straight inputed both codes just as is on forums, with a clientside loop checking the string and displaying the text
__________________

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 03:24 AM.


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