Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Convert Graal Seconds (https://forums.graalonline.com/forums/showthread.php?t=56557)

ZeroTrack 12-22-2004 04:08 AM

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 . ^^

ZeroTrack 12-22-2004 07:03 PM

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 x_x

MysticalDragon 12-23-2004 12:07 AM

Doesnt seem Complex at all.

Slash-P2P 12-23-2004 06:56 AM

playeronlinetime returns 0 for me.

Python523 12-23-2004 08:41 AM

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);
}


ZeroTrack 12-23-2004 09:04 AM

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);
}


Python523 12-23-2004 09:10 AM

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?

ZeroTrack 12-23-2004 09:25 AM

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.

ZeroTrack 12-23-2004 09:27 AM

Quote:

Originally Posted by Slash-P2P
playeronlinetime returns 0 for me.

its serverside slash =p

Kaimetsu 12-23-2004 10:07 AM

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.

ZeroTrack 12-23-2004 04:11 PM

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

Kaimetsu 12-23-2004 04:13 PM

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?

ZeroTrack 12-23-2004 04:18 PM

I uploaded both with the same loop and his came up as one of the top 10 taking cpu time...

Python523 12-23-2004 04:32 PM

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.

ZeroTrack 12-23-2004 04:38 PM

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

Python523 12-23-2004 04:43 PM

Quote:

Originally Posted by 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

Try assigning your hours/minutes/seconds to variables.

ZeroTrack 12-23-2004 04:50 PM

Ok i took them all out and assigned them to var's then set the string this is what happened
2. 0.035332 secs JagenTest
8. 0.006543 secs SernTest

-_- and i didnt initialize it yet

Lance 12-27-2004 12:19 AM

Quote:

Originally Posted by Python523
Try assigning your hours/minutes/seconds to variables.

Has anyone pointed out that yours uses days/hours/minutes rather than hours/minutes/seconds?

Just a thought.

CaTigus 12-30-2004 06:21 PM

Quote:

Originally Posted by Python523
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);
}


I seemed to have much more accurate time with Jagens, and I tried both.

ZeroTrack 12-30-2004 10:55 PM

Quote:

Originally Posted by CaTigus
I seemed to have much more accurate time with Jagens, and I tried both.

.... .... .. more accurate time??? lol the debate wasn't about which ones more accurate cause they both return the same time in real time, but it was over which has more load on the cpu. Before you post again refer to rule 4 here http://forums.graalonline.com/forums...cement.php?f=8

Kaimetsu 12-31-2004 12:10 AM

Um, Sern, that person didn't post a solution.

CaTigus 12-31-2004 12:29 AM

Quote:

Originally Posted by ZeroTrack
.... .... .. more accurate time??? lol the debate wasn't about which ones more accurate cause they both return the same time in real time, but it was over which has more load on the cpu. Before you post again refer to rule 4 here http://forums.graalonline.com/forums...cement.php?f=8

I was commenting, Maybe you should buy Hooked on Phonics before you go insulting my opinion. There was no solution in my post.

Evil_Trunks 12-31-2004 12:38 AM

Quote:

Originally Posted by ZeroTrack
Ok i took them all out and assigned them to var's then set the string this is what happened
2. 0.035332 secs JagenTest
8. 0.006543 secs SernTest

-_- and i didnt initialize it yet

I have tested them both offline with similar setup and it shows yours faster than Jagens.

I do not know how accurate the CPU usage indicator in the offline debugger is.

I used the following scripts.

Jagen's Method:
PHP Code:

if (playerenters) {
  
timeout 0.05;
}
if (
timeout) {
  
this.temp 23212613;
  
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;
  
message H#v(this.realhrs)  M: #v(this.realmin) S: #v(this.temp);

  
timeout 0.05;


~0.053-0.069 cpuusage

Sern's Method
PHP Code:

if (playerenters) {
  
timeout 0.05;
}
if (
timeout) {
  
this.temp 23212613;
  
this.hours int(this.temp/(60*60));
  
this.mins int((this.temp/60)%60);
  
this.secs int((this.temp)%60);
  
message #v(this.hours)H:#v(this.mins)M:#v(this.secs)S;

  
timeout 0.05;


~0.043-0.048 cpuusage

Edit: I do not know why Sern's cpuusage is less.

This is offline. Scripts may be processed completely differently online.

Python523 12-31-2004 01:30 AM

Mine deals with more variable manipulation, so maybe that adds some extra cycles... However, I was talking about the efficiency mathematically, which would be true in my case.

Lance 12-31-2004 01:37 AM

Quote:

Originally Posted by ZeroTrack
Yea i tried pushing that one only cause ben said it to me once so i wanted to haha

Let us moderators handle the moderating.

ZeroTrack 12-31-2004 01:41 AM

Quote:

Originally Posted by Kaimetsu
Um, Sern, that person didn't post a solution.

Yea i tried pushing that one only cause ben said it to me once so i wanted to haha
Quote:

Maybe you should buy Hooked on Phonics before you go insulting my opinion. There was no solution in my post
phonics has nothing to do with what i said, phonics is “a method of teaching beginners to read and pronounce words by learning the phonetic value of letters, letter groups, and especially syllables” so once again you strike out due to lack of common knowledge. this also does not exclude the fact that our debate has nothing to do with which one shows more accurate cause they both return the same time in real time, but it was over which one puts more load on the CPU.

Quote:

Originally Posted by Phyton523
Mine deals with more variable manipulation, so maybe that adds some extra cycles... However, I was talking about the efficiency mathematically, which would be true in my case.

this isn’t an attack I want to know how yours is more efficient mathematically? i dont see it

CaTigus 12-31-2004 02:10 AM

Quote:

Originally Posted by ZeroTrack
phonics has nothing to do with what i said, phonics is “a method of teaching beginners to read and pronounce words by learning the phonetic value of letters, letter groups, and especially syllables” so once again you strike out due to lack of common knowledge. this also does not exclude the fact that our debate has nothing to do with which one shows more accurate cause they both return the same time in real time, but it was over which one puts more load on the CPU.

Hooked on phonics is a program to teach children to read, and comprehend better. You obviously didn't read what I read in the first place. I simply stated an opinion on the subject and you started thrashing about. You sent me a "rule" which completely passed up the point of my post. Therefor you probably didn't read my post very thuroghly or cannot read correctly.

Python523 12-31-2004 02:53 AM

Quote:

Originally Posted by ZeroTrack
this isn’t an attack I want to know how yours is more efficient mathematically? i dont see it

Must I point out the obvious.

According to your post, a%b = a - int(a/b)*b

so if I translate Evil_Trunks's variation of your script
NPC Code:

this.hours = int(this.temp/(60*60));
this.mins = int((this.temp/60)%60);
this.secs = int((this.temp)%60);


to
NPC Code:

this.hours = int(this.temp/(60*60));
this.mins = int(this.temp/60 - int(this.temp/60^2)*60);
this.secs = int(this.temp - int(this.temp/60)*60);




You tell me what looks more efficient. Mine or yours.

ZeroTrack 12-31-2004 03:10 AM

Quote:

Originally Posted by Python523
Must I point out the obvious.

According to your post, a%b = a - int(a/b)*b

so if I translate Evil_Trunks's variation of your script
NPC Code:

this.hours = int(this.temp/(60*60));
this.mins = int((this.temp/60)%60);
this.secs = int((this.temp)%60);


to
NPC Code:

this.hours = int(this.temp/(60*60));
this.mins = int(this.temp/60 - int(this.temp/60^2)*60);
this.secs = int(this.temp - int(this.temp/60)*60);




You tell me what looks more efficient. Mine or yours.

ah i see what you mean now you lost me for a second, yes your its better in that sence , mines better on cpu load

Gambet 12-31-2004 07:11 AM

Quote:

Originally Posted by ZeroTrack
ah i see what you mean now you lost me for a second, yes your its better in that sence , mines better on cpu load

What hes been trying to prove to you in the past pages in this thread is that, mathematically, his script is more efficient then yours. Yes, yours doesnt take up as much space as his does, but it doesnt make yours more efficient then his.

Admins 01-07-2005 05:43 PM

Assignments are generally slow, even if coding in assembler assignments are much slower than reading variables. And in scripting languages like Graal Script you have additional overhead because the variables are script objects, not direct memory values. Mathematical operations are faster because they are done in the same speed like in assembler/C++ code.
So the speed of a script mainly depends on the number of variable reads, assignments and call of complex functions (showimg, putnpc2 etc.).

ZeroTrack 01-07-2005 11:05 PM

hence why mines better for graal ;) <3


All times are GMT +2. The time now is 09:52 AM.

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