Ulysses

General => Developers Corner => Topic started by: Caustic Soda-Senpai on January 17, 2015, 04:30:35 PM

Title: Countdown Command
Post by: Caustic Soda-Senpai on January 17, 2015, 04:30:35 PM
So I'm trying to set up a ULX Command for a server restart by utilizing a countdown as a warning before it actually restarts. Is it possible to create a tick event so the command waits for (x) minutes to actually run _RESTART and display a tsay corresponding to how many minutes are left? The answer is probably right here in front of me but whatever.
Title: Re: Countdown Command
Post by: JamminR on January 17, 2015, 10:32:37 PM
My idea;

timer.simple - set time and function to run - every minute = good idea.
in function,
check if current time equals ( previously sched time) - Yes, restart. (you'll have to figure out some rounding tricks to account for variance, timer might not run function until .25 before or after your scheduled time.
check if current time is greater than ( previously set time var - 10min ) and less than (previously set future time) Yes? Display ( set time - current time) which will be (10, 9, 8 ...) each time looped.
set specific (static server time?) (manually set time 10 min from now?) variable -
run the timer.simple again
end
Title: Re: Countdown Command
Post by: Caustic Soda-Senpai on January 18, 2015, 12:24:09 AM
Yeah I was thinking something along those lines. I guess its play around till I get it.
Title: Re: Countdown Command
Post by: XxLMM13xX on January 18, 2015, 11:56:54 AM
Hello i think this would be a AWESOME thing to do i dont know if there is a really simple way to do this for like beginner coders so ill look into it!
Title: Re: Countdown Command
Post by: Caustic Soda-Senpai on January 18, 2015, 02:35:36 PM
I think I more or less have it. I'll post the finished product.
Title: Re: Countdown Command
Post by: XxLMM13xX on January 18, 2015, 05:00:17 PM
That would be awesome i want to see it for a example!
Title: Re: Countdown Command
Post by: Caustic Soda-Senpai on January 18, 2015, 11:29:40 PM
Alright I've got it figured out and tested, works 100%. Took a while to get it to loop right though. First time it ended up kicking me right out of gmod.

My solution was a few if/else statements along with a timer.Create with its own if/else statement telling it to loop back on itself if the var hasn't reached 0. So it was kindof a spin of JamminR's idea and mine. With some messing around I was also able to make an abort counter-part in case you didn't actually WANT to restart.

I'll post the final product in the release section.