ULX

Author Topic: Countdown Command  (Read 2544 times)

0 Members and 1 Guest are viewing this topic.

Offline Caustic Soda-Senpai

  • Sr. Member
  • ****
  • Posts: 469
  • Karma: 54
  • <Insert something clever here>
    • Steam Page
Countdown Command
« 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.
Once you get to know me, you'll find you'll have never met me at all.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Countdown Command
« Reply #1 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
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Caustic Soda-Senpai

  • Sr. Member
  • ****
  • Posts: 469
  • Karma: 54
  • <Insert something clever here>
    • Steam Page
Re: Countdown Command
« Reply #2 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.
Once you get to know me, you'll find you'll have never met me at all.

Offline XxLMM13xX

  • Sr. Member
  • ****
  • Posts: 265
  • Karma: -51
  • New to lua development
    • Twitch
Re: Countdown Command
« Reply #3 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!

Offline Caustic Soda-Senpai

  • Sr. Member
  • ****
  • Posts: 469
  • Karma: 54
  • <Insert something clever here>
    • Steam Page
Re: Countdown Command
« Reply #4 on: January 18, 2015, 02:35:36 PM »
I think I more or less have it. I'll post the finished product.
Once you get to know me, you'll find you'll have never met me at all.

Offline XxLMM13xX

  • Sr. Member
  • ****
  • Posts: 265
  • Karma: -51
  • New to lua development
    • Twitch
Re: Countdown Command
« Reply #5 on: January 18, 2015, 05:00:17 PM »
That would be awesome i want to see it for a example!

Offline Caustic Soda-Senpai

  • Sr. Member
  • ****
  • Posts: 469
  • Karma: 54
  • <Insert something clever here>
    • Steam Page
Re: Countdown Command
« Reply #6 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.
Once you get to know me, you'll find you'll have never met me at all.