![]() |
day/night script code
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) Table: 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! Output: this.checktime=0 this.hour=2 this.minute=1 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 this.checktime=timevar; //count years this.year=0; while (this.checktime>=103680) { this.checktime-=103680;this.year++; } //count month this.month=0; while (this.checktime>=8640) { this.checktime-=8640;this.month++; } //count day this.day=0; while (this.checktime>=288) { this.checktime-=288;this.day++; } //count hour this.hour=0; while (this.checktime>=12) { this.checktime-=12;this.hour++; } //count minute this.minute=0; while (this.checktime>=1) { this.checktime-=1;this.minute++; } if (isonmap) { if (this.hour<12) { setbackpal dusk3.png; } else { setbackpal pics1.png } } if (!isonmap) { setbackpal pics1.png;} //end backpal check //end day/night |
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 NPC Code: 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; -Kyle |
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 |
uhmm..
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)) { hide; 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); say2 #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,; } |
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..) |
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 this.checktime-=1;this.minute++; to this.checktime-=.2;this.minute++; |
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 |
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 ;) |
I wanna be smart :(
heh |
bugged...
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. |
| All times are GMT +2. The time now is 11:30 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.