Graal Forums

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

excaliber7388 10-10-2005 04:04 PM

time
 
here's my current time/day/night script, I wanted to make it so it was more like real time, and possible modify it so it matched current time in real time. How would I do this?
NPC Code:
//#CLIENTSIDE
if(created||timeout){
this.seconds=timevar%60;
this.minutes=int(timevar/60)%60;
this.hours=int(timevar/3600)%24;
showimg 888,dr-hourglass.png,293,10;
showtext 889,316,10,Comic Sans,b,#v(this.hours):#v(this.minutes):#v (this.seconds);
changeimgvis 888,5;
changeimgvis 889,5;
changeimgzoom 888,.85;
if(this.hours==16) {
setbackpal dusk1.png;
}
if(this.hours==20){
setbackpal dusk3.png;
}
if(this.hours==24){
setbackpal dusk5.png;
}
if(this.hours==1) {
setbackpal dusk4.png;
}
if(this.hours==4) {
setbackpal dusk3.png;
}
if(this.hours==5) {
setbackpal dusk2.png;
}
if(this.hours==6) {
setbackpal pics1.png;
}
timeout=.05;

}


Skyld 10-10-2005 08:07 PM

Make a script that counts, I guess.

That, or make creative use of timevar. It increases by one every 5 seconds. Use it to your advantage, boy.

excaliber7388 10-10-2005 08:50 PM

Quote:

Originally Posted by Skyld
Make a script that counts, I guess.

That, or make creative use of timevar. It increases by one every 5 seconds. Use it to your advantage, boy.

yeah I tried something like int(timevar*.2)%60 but that 'froze' the time x_x

ApothiX 10-10-2005 09:10 PM

If you want to be the real time, use timevar2,

PHP Code:

timezone = -5// GMT-5 (EST)
seconds int(timevar2 60);
minutes int((timevar2 60) % 60);
hours int((timevar2 / (60 60)) % 24) + (timezone 1); 


excaliber7388 10-10-2005 10:50 PM

Quote:

% 24) + (timezone + 1);
that would change the ammount of hours allowed, and the time, I just need to find out how to change the time

ZeLpH_MyStiK 10-10-2005 11:38 PM

Quote:

Originally Posted by excaliber7388
yeah I tried something like int(timevar*.2)%60 but that 'froze' the time x_x

why would you multiply by .2? since it increases by one every five seconds, you'd multiply by 5. Plus timevar is the amount of time passed since the server was up. You would have to find a way around the different days in a month (28,30,31), the leap year increments (.25 day every year)...and etc.

excaliber7388 10-11-2005 09:34 PM

I just need it to count hours and such, the other stuff would be easy to add anyway, I am still having trouble setting the time though. Can you edit the timevar? Or is there another way? Like:
NPC Code:
 if(created){
timevar=timevar-2;
}


Any help?

ZeLpH_MyStiK 10-11-2005 11:51 PM

Quote:

Originally Posted by excaliber7388
I just need it to count hours and such, the other stuff would be easy to add anyway, I am still having trouble setting the time though. Can you edit the timevar? Or is there another way? Like:
NPC Code:
 if(created){
timevar=timevar-2;
}


Any help?

o.O err timevar is a builtin variable. the only way to change timevar is reset your server and it will begin counting at 0 again. Use '%' to figure out the minutes, and hours, and such.

Lance 10-12-2005 12:50 AM

Quote:

Originally Posted by ZeLpH_MyStiK
o.O err timevar is a builtin variable. the only way to change timevar is reset your server and it will begin counting at 0 again. Use '%' to figure out the minutes, and hours, and such.

No, no, it won't.

ZeLpH_MyStiK 10-12-2005 01:18 AM

Quote:

Originally Posted by Lance
No, no, it won't.

Isn't it server uptime?

excaliber7388 10-12-2005 02:33 AM

Hmm, not gonna restart my server anyway XD, but is there a way to modify this, without disabling the ammount for hours min, etc?

ZeLpH_MyStiK 10-12-2005 03:50 AM

Quote:

Originally Posted by excaliber7388
Hmm, not gonna restart my server anyway XD, but is there a way to modify this, without disabling the ammount for hours min, etc?

you can use another variable:
NPC Code:

this.time=timevar-2;


Polo 10-12-2005 12:25 PM

On Classic we have a 24 hour clock for doing accurate day/night. We use timevar2 on clientside (seconds since they turned thier computer on). To change this into somthing synced for everyone, we calculate the offset to the serverside timevar2 (unix time) when they log in, and then adjust for this before calculating the actual time.

Theoretically, everyone is then getting thier times as unix time, give or take a small error for lag reasons.

excaliber7388 10-12-2005 10:15 PM

here's what I'm using right now, but everyone has different times, and I think the time changes when you log on x_X suggestions?

NPC Code:
//#CLIENTSIDE
if(created||timeout){
this.hour=timevar2+16*3600;
this.min=timevar2-24*60;
this.seconds=int(timevar2)%60;
this.minutes=int(this.min/60)%60;
this.hours=int(this.hour/3600)%24;
showimg 888,dr-hourglass.png,290,10;
showtext 889,316,10,Comic Sans,b,#v(this.hours):#v(this.minutes):#v(this.sec onds);
changeimgvis 888,5;
changeimgvis 889,5;
changeimgzoom 888,.85;
if(isonmap){
if(this.hours==16&&this.hours<20) {
setbackpal dusk1.png
}
if(this.hours=>17&&this.hours<20){
setbackpal dusk3.png
}
if(this.hours=>20&&this.hours<24){
setbackpal dusk4.png
}
if(this.hours==24){
setbackpal dusk5.png
}
if(this.hours=<3) {
setbackpal dusk4.png
}
if(this.hours==4) {
setbackpal dusk3.png
}
if(this.hours==5) {
setbackpal dusk1.png
}
if(this.hours=>6&&this.hours<16) {
setbackpal pics1.png
}
}
if(!isonmap){setbackpal pics1.png}
timeout=.05;

}


excaliber7388 10-12-2005 11:43 PM

Time changes when you log in, different times for everyone x_X bad

ZeLpH_MyStiK 10-12-2005 11:50 PM

Quote:

Originally Posted by Polo
On Classic we have a 24 hour clock for doing accurate day/night. We use timevar2 on clientside (seconds since they turned thier computer on). To change this into somthing synced for everyone, we calculate the offset to the serverside timevar2 (unix time) when they log in, and then adjust for this before calculating the actual time.

Theoretically, everyone is then getting thier times as unix time, give or take a small error for lag reasons.

So I'm assuming once it's synced, client computers will do the addition of seconds and minutes and etc in a timeout loop? It's not accurate since the calculation will take cpu speed and throw off following loops. Plus, as Spark has said before, having a 24 hour clock will mean that half of your players will always play in the dark while the other half play in the light.


As for excaliber7388's problem, i don't see anything that would cause everyone to have different times. However, setbackpal is very outdated and should no longer be used. Instead, replace with seteffect.

excaliber7388 10-13-2005 12:04 AM

How do you sync it???(And it changes EVERY time you log on in my current script

ZeLpH_MyStiK 10-13-2005 12:21 AM

Quote:

Originally Posted by excaliber7388
How do you sync it???(And it changes EVERY time you log on in my current script

It's supposed to change? Since timevar2 is a freakin' nanosecond precisioned counting machine! j/k but timevar2 increases whether you're on player or not, same goes for timevar.

Ajira 10-13-2005 02:37 AM

Quote:

Originally Posted by excaliber7388
How do you sync it???(And it changes EVERY time you log on in my current script

It's because it's CLIENTSIDE. It's the seconds since your computer's on. If you do it serverside, it should be the same. Or at least sync it with the serverside when you log on first.

excaliber7388 10-13-2005 03:03 AM

I've tried it serverside...didn't work, explain how I could do this :\ (all i did was move the //#CLIENTSIDE line to the middle, where the text is displayed, etc.

Polo 10-13-2005 03:37 AM

Quote:

Originally Posted by ZeLpH_MyStiK
So I'm assuming once it's synced, client computers will do the addition of seconds and minutes and etc in a timeout loop? It's not accurate since the calculation will take cpu speed and throw off following loops. Plus, as Spark has said before, having a 24 hour clock will mean that half of your players will always play in the dark while the other half play in the light.

Actually, timeout is running using the system clock, and is therefore pretty accurate regardless of the users CPU. As a general comparison, between my Intel Pentium3 450mhz, and my AMD AthlonXP 2600+ Barton, there is no discernable difference, and I think most people would agree that these are very different levels of CPU.

The calculation is not summing an ammount of seconds periodically anyway, it is always resalsculating the time from the stored offset, and the clientside timevar2. If we count the difference caused by the delay transmitting the offset back to the player as negligable, then the clock is acurate enough to create evolving day/night and weather effects. We can even creat extra snow in winter for example, by correctly identifying weather changes and simulating these as sinusoids (using the synced clock, with varying offsets and periods).

As for players playing in the dark, as weather and day/night are not central to the theme of Classic, users have the option to disable them (infact, for all players these effects are disabled by default).

excaliber7388 10-13-2005 03:40 AM

Everyone talks about syncing the clock x_x I have no idea how to do this :\

ForgottenLegacy 10-13-2005 03:51 AM

Note: setbackpal is BAD BAD BAD BAD BAD BAD -Shoots it-

Do not use this command. Ever. Ever! Or behold the wrath of Rabid's projectile kitties! :D (Don't ask)

Anyway, use seteffect(red,green,blue,alpha);, all numbers are between 0 and 1, and Alpha is the darkness of the level. Fiddle with it! Set all four values to 0 to reset it.

ZeLpH_MyStiK 10-13-2005 05:28 AM

Quote:

Originally Posted by excaliber7388
Everyone talks about syncing the clock x_x I have no idea how to do this :\

if (actionserverside) {
triggeraction 0,0,clientside,WEAPONNAME,#v(timevar2);
}
//#CLIENTSIDE
if (created) {
triggeraction 0,0,serverside,WEAPONNAME,;
}
if (actionclientside) {
this.timingthingamajig=strtofloat(#p(0));
}

excaliber7388 10-13-2005 03:29 PM

Quote:

Originally Posted by ForgottenLegacy
Note: setbackpal is BAD BAD BAD BAD BAD BAD -Shoots it-

Do not use this command. Ever. Ever! Or behold the wrath of Rabid's projectile kitties! :D (Don't ask)

Anyway, use seteffect(red,green,blue,alpha);, all numbers are between 0 and 1, and Alpha is the darkness of the level. Fiddle with it! Set all four values to 0 to reset it.

I know that but I used seteffect for other things, then I realized that it would reset to 0,0,0,0...but now i just realized that it may reset, but then the time script would change it to the current day/night setting. I'd test the thing for syncing now...but I'm at school and I don't have graal on this comp XD
Quote:

if (actionclientside) {
this.timingthingamajig=strtofloat(#p(0));
}
exactly what would I put in for a timeingthingamajig?

ApothiX 10-13-2005 03:32 PM

Quote:

Originally Posted by excaliber7388
I've tried it serverside...didn't work, explain how I could do this :\ (all i did was move the //#CLIENTSIDE line to the middle, where the text is displayed, etc.

Hmm, and you're manager of a server? o_o

ZeLpH_MyStiK 10-13-2005 05:22 PM

Quote:

Originally Posted by excaliber7388
exactly what would I put in for a timeingthingamajig?

x.x this.timeingthingamajig would be the variable that has synced with serverside timevar2, thus you'd use that clientside instead of timevar2 in your script.

excaliber7388 10-13-2005 08:57 PM

Thanks, sorry I havn't been able to explain this much, I was at school, and the teacher came over a lot x_X . Thanks for the help though guys, I'll see if it works (it should)
It works, (i think) changed a bit (added timeout) thanks!

petro1212 10-13-2005 10:20 PM

excaliber7388.... one small notice never ever ever use setbackpal

Its an old outdated retarted command that simply replaces the colours from the tileset... wich is unnessasery in your case.

Just use seteffect and so on..

ontop of that setbackpal is removed in g2 as far as I recall >.>

excaliber7388 10-14-2005 02:02 AM

I don't like backpal anyway, I only used it because i wasn't thinking, I thought the effect would replace other effects, etc. Like I said...not thinking XD

ApothiX 10-14-2005 05:59 PM

Quote:

Originally Posted by petro1212
excaliber7388.... one small notice never ever ever use setbackpal

Its an old outdated retarted command that simply replaces the colours from the tileset... wich is unnessasery in your case.

Just use seteffect and so on..

ontop of that setbackpal is removed in g2 as far as I recall >.>

retarted, eh Angelus? :P


[EDIT]
Another thing, excaliber, don't delete your threads when the problem is solved, people might have the same problem as you, and can use your threads for help.
[/EDIT]

Skyld 10-14-2005 07:49 PM

Quote:

Originally Posted by ApothiX
Hmm, and you're manager of a server? o_o

I often think this myself.

Excaliber, you would probably be doing yourself a number of favours by learning to script before trying to create a playerworld.

If it must be said, scripts that are created during the development of scripting skills often don't compare to a script that is written, with sufficient knowledge from the beginning.

So far, you have asked the forums to fix a large number of scripts for your playerworld. I don't think this is really a good idea.

ApothiX 10-14-2005 08:27 PM

Quote:

Originally Posted by Skyld
So far, you have asked the forums to fix a large number of scripts for your playerworld. I don't think this is really a good idea.

This is very true, just take a look at all the threads that have been deleted by him.

excaliber7388 10-14-2005 08:32 PM

Yeah, I'll admit I am unfamiliar with online scripting, as you may notice, all my scripts would have worked offline, but not online, this is because i learned offline for years, without ever reading a guide, etc. so sorry, but I find this is the best way to learn, to see correct scripts, to change them, etc. Sorry I've been a pain in the ass, soon you won't hear much from me here (untill i switch my server to GS2 x_x not looking foward to THAT)

ApothiX 10-14-2005 08:34 PM

Quote:

Originally Posted by excaliber7388
Yeah, I'll admit I am unfamiliar with online scripting, as you may notice, all my scripts would have worked offline, but not online, this is because i learned offline for years, without ever reading a guide, etc. so sorry, but I find this is the best way to learn, to see correct scripts, to change them, etc. Sorry I've been a pain in the ass, soon you won't hear much from me here (untill i switch my server to GS2 x_x not looking foward to THAT)

If you are still learning, my advice would be to wait until the new engine is enabled, and start learning from there. Old GScript has a lot of potential to let errors slip by without being noticed. In turn, creating unreliable, unprofessional scripts.

excaliber7388 10-14-2005 09:34 PM

But i like old script =*(
I wish it was 100% useable when GS2 is activated on that server, that way i can switch NOW and start putting scripts in GS2, then once I'm good at it, switch it back

Skyld 10-14-2005 09:47 PM

Quote:

Originally Posted by excaliber7388
But i like old script =*(
I wish it was 100% useable when GS2 is activated on that server, that way i can switch NOW and start putting scripts in GS2, then once I'm good at it, switch it back

Old gscript does work completely on a new engine-enabled server. If you've had problems with it, I suggest it's a problem with your scripting somewhere.

ApothiX 10-14-2005 09:51 PM

Quote:

Originally Posted by Skyld
Old gscript does work completely on a new engine-enabled server. If you've had problems with it, I suggest it's a problem with your scripting somewhere.

Which is why a lot of people don't want to get it enabled <_<

excaliber7388 10-14-2005 09:57 PM

wait, completly? I heard some things were removed, that only a few worked, (though these were things that no longer we used in GS i think) so I could have
something like destroy
instead of, destroy(), even with GS2 enabled?

Skyld 10-14-2005 09:59 PM

Quote:

Originally Posted by excaliber7388
wait, completly? I heard some things were removed, that only a few worked, (though these were things that no longer we used in GS i think) so I could have
something like destroy
instead of, destroy(), even with GS2 enabled?

Yes, you can still use destroy; and so forth.


All times are GMT +2. The time now is 04:31 PM.

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