Here’s what you should have done:
// Server Time
if (playerenters) {
this.hours = 00;
this.minutes = 00;
this.seconds = 00;
timeout=1;
}
if(timeout){
this.seconds = this.seconds+1;
message #v(this.hours):#v(this.minutes):#v(this.seconds)
if (this.seconds == 60) {
this.seconds = this.seconds-60;
this.minutes = this.minutes+1;
}
if (this.minutes == 60) {
this.minutes = this.minutes-60;
this.hours = this.hours+1;
}
if (this.hours == 24) {
this.hours = this.hours-24;
}
timeout = 1;}
This is so every time a timeout runs out it checks the variables.
Personnally I took so much time figuring that out back in 2001… I used to put a lot of sleeps and repeat my code X_X.
Modulo and divisions would be worth it in here since you’d be using only one var and have a much shorter script.
(notice how I used “+=”)
if (playerenters) {
this.seconds = 00;
timeout=1;
}
if(timeout){
this.seconds += 1;
message #v(int(this.seconds/3600)%24):#v(int(this.seconds/60)%60):#v(this.seconds%60)
timeout = 1;}
However this would reset every time you reconnect, since you are using a this. variable… and would also reset every time the player enters the level, which is probably unwanted.
Therefore, remember that in gscript you do not have to declare your variables before using them, and that client. variables (which are sadly always stored as strings) are permanent, like flags.
You should also use a npcw so the time always increments, and not only in the current level, but there’s one problem, the timeout will stop looping once you reconnect, so you will need to init the timeout on playerenters(which is usually what happens most often after a reconnection). But you don’t always want the timeout to start back to 1 on playerenters, so we’ll use a this. var to make sure this doesn’t happen. We also don’t want the level’s npc to increment client.seconds since it’s the npcw’s job, so to avoid client.seconds incrementing twice, we make sure the npc is a weapon.
So I’d personally write it this way:
if(created){
toweapons -servertime;
this.init=1;
timeout = 1;
}
if(playerenters&&this.init==0&&isweapon){ //since this.init has not been declared, it's equal to zero
this.init = 1;
timeout = 1;
}
if(timeout&&isweapon){
setstring client.seconds,#v(strtofloat(#I(client.seconds,0))+1);
message #v(int(strtofloat(#I(client.seconds,0))/3600)%24):#v(int(strtofloat(#I(client.seconds,0))/60)%60):#v(strtofloat(#I(client.seconds,0))%60)
timeout = 1;}
The downside is that it calculates play time and not server time, anyways, this should help you script better.
Good luck, and don’t hesitate if you have further questions :)[COLOR=“Silver”]
---------- Post added at 10:37 PM ---------- Previous post was at 10:33 PM ----------
[/COLOR]Twiggy, is that Santa in your avatar?