View Full Version : day/night script code

05-25-2001, 06:16 AM
I just made this quickly in about 20 minutes , so it can be improved

I'll explain ...

It uses timevar (server-wide variable which adds 1 to itself every 5 seconds)

when timevar is ...
1 then on the server its 5 minutes
12 then on the server its 1 hour
288 then on the server its 1 day
8640 then on the server its 1 month
103680 then on the server its 1 year

so for example if timevar is 25 ..

the script would do this:

1)make this.checktime the timevar value

2)check to see if year is bigger (in this case its less than 1 year),
check for month (nope less than 1 month), check for day (nope),
check for hour( yes! ) 25 is bigger than 12 .. so that means that it is more than/or 1 hour...

3)Do While Loop...
here it will do this.. while this.checktime is more than 12 (which is 1 hour) take away 12 from this.checktime and then add 1 to this.hour (variable which keeps how many hours)
Here is the output:
1st loop run: this.hour = 1 , this.checktime=13
2nd looprun:this.hour=2, this.checktime=1

4)Continue checking ... check minutes( yes! )
yes, this.checktime is 1 from the last loop remember? so it is bigger or equal to 1 .. now do more loop..
While this.checktime is more than or equal to 1 add 1 to this.minute and take away 1 from this.checktime
Here is output:
1st loop: this.checktime=0, this.minute=1

5) Code is done!

Now here is the code , enuff talkin' ;)

//NPC Made By LiquidIce *Owner* (UnholyNation)
//Please let me know if you want to use this script
//dont just be greedy and use it ..

//day/night part
//check time and such for right backpal
//count years
while (this.checktime>=103680) {
//count month
while (this.checktime>=8640) {
//count day
while (this.checktime>=288) {
//count hour
while (this.checktime>=12) {
//count minute
while (this.checktime>=1) {
if (isonmap) {
if (this.hour<12) { setbackpal dusk3.png; }
else { setbackpal pics1.png }

if (!isonmap) { setbackpal pics1.png;}

//end backpal check
//end day/night

05-25-2001, 07:16 AM
I'm gonna edit this...just multiply the last number on the line by the first on the next line to get the next number, it's the same as you had though
when timevar *
.2 then on the server its 5 minutes *
60 then on the server its 1 hour *
24 then on the server its 1 day *
30 then on the server its 1 month *
12 then on the server its 1 year

this.minute = int(timevar / .2)%60;
this.hour = int(this.minute / 60)%24;
this.day = int(this.hour / 24)%30;
this.month = int(this.day / 30)%12;
this.year = int(this.month / 12);

hope that makes sense. You basically start with what you're fiding (minutes), find how many there are, divide by how many minutes were in 1 of the previous thing (timevar) and get the remainder when divided by the maximum of that type you can have (how many in an hour). The stuff in ()'s pertains to finding minutes. good job with your versoin though ;) It got the job done, just would be pretty laggy when the numbers got higher;


05-25-2001, 07:35 AM
I could make it really really short if i had made an actual arithmetics for it.. like i said i made it quick ;P
but thx for the adjust

05-25-2001, 07:44 AM
here is a little code for example if you want to have a little clock in your inventory and when you fire , it shows the time and date ...
I might make a version where it has the status bar of it also (like on g2k1 and X)

// NPC made by LiquidIce
//thx to Kyle for making a little
// 'arithmetics' =P
if (!isweapon&&(playerenters)) {
toweapons *Time;
if (weaponfired) {
this.minute = int(timevar / .2)%60;
this.hour = int(this.minute / 60)%24;
this.day = int(this.hour / 24)%30;
this.month = int(this.day / 30)%12;
this.year = int(this.month / 12);

if (this.minute<10) { setstring bclockminute,0#v(this.minute); }
else { setstring bclockminute,#v(this.minute); }

setstring bclockyear,#v(this.year);
setstring bclockmonth,#v(this.month);
setstring bclockday,#v(this.day);
setstring bclockhour,#v(this.hour);

#xCurrent Time#y#b
Year: #s(bclockmonth)/#s(bclockday)/#s(bclockyear) #x#b
Time: #s(bclockhour):#s(bclockminute) #z;
setstring bclockyear,;
setstring bclockmonth,;
setstring bclockday,;
setstring bclockhour,;
setstring bclockminute,;


05-25-2001, 07:51 AM
my bad. .
Kyle , something is wrong with yours, I believe its going to negative values. . that method wont work =\
it works up to a certain ammount until when you divide it gives negative ammounts and returns 0 ..
Is it just me or is the code actually buggy?
(if the code is buggy the little clock wont work btw..)

05-25-2001, 07:53 AM
AH. so much posting so soon =D
thx to kyle I found a little problem
in the line where it says

while (this.checktime>=1) {

change to

while (this.checktime>=.2) {

and right below that




05-25-2001, 08:06 AM
Mine doesn't seem to have any problems...I wouldn't do it that way if I made one though...I'd probably use an array or something, but it's easier to explain and use that way. The only possible bug is that the int and % is mixing up. try
(int(var / #))%#;
if you still can't get it to work

05-25-2001, 08:39 AM
I'll try later but when timevar was high it was brokage...
maybe thats it because I was thinking and I wasnt sure what was doing wrong ;)

05-25-2001, 01:19 PM
I wanna be smart :(

07-18-2001, 03:30 PM
When ever i try and use a code like that, i always get 41 months. Does anyone know what i could be doing wrong to get such a high number of months?

And im not using kyle's way.