Author Topic: Auto-server reset script  (Read 5090 times)

0 Members and 1 Guest are viewing this topic.

JerryTheStampede

  • Guest
Auto-server reset script
« on: July 08, 2008, 04:50:27 PM »
Hello, I've read a couple threads about this before but nobody really released anything. Is it possible that someone make an addon that will reset the server if no one is in it for like 5 minutes?
Our server gets Reliable Snapshot Overflows. We have simple prop protection but it doesn't clear the snapshot. If we had an auto server reset then when the server RSOs it would just reset since nobody would be in it.

Can anyone tell me if theres a script like this ulx or not? I know there was one for lua but its a year old and all the links for it are dead. I think that if this works well it should be implemented into the main ulx addon.

One more thing. Our server automatically will reset if it crashes so just having the addon execute and exit or quit command after having no one in it for a while would suffice.

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Auto-server reset script
« Reply #1 on: July 08, 2008, 05:05:57 PM »
Code: [Select]
// ARestart V1.0

local RDelay = 5 // Delay in minutes

function Reset()
local playerslist = player.GetAll()
if table.Count(playerslist) == 0 then
timer.Create("ResetTimer", RDelay * 60, 1, RestartServer)
else
timer.IsTimer("ResetTimer") then
timer.Destroy("ResetTimer")
end
end
timer.Create("ResetThinkTimer", 60, 0, Reset)
function RestartServer()
game.ConsoleCommand( "quit" )
end

Not tested, but should work.
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Auto-server reset script
« Reply #2 on: July 08, 2008, 05:09:07 PM »
table.Count() shouldn't be used, use the # operator instead.
Experiencing God's grace one day at a time.

JerryTheStampede

  • Guest
Re: Auto-server reset script
« Reply #3 on: July 08, 2008, 05:29:43 PM »
That script looks alright. But... how would I use # operator instead of table.Count().


Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Auto-server reset script
« Reply #4 on: July 08, 2008, 05:58:05 PM »
Jerry, one extra tip... make sure to get the latest SVN of Tad2020's advanced duplicator.
I pointed him to a discussion regarding reliable snapshot errors here.
Tad2020 added a timer to adv. dupe that removes what is believed to be a major contributor to Reliable Snapshot overflows.
It's not a cure mind you... heavily prop loaded servers will/can still get it, but I've personally noticed a big difference on those servers that have upgraded to the latest SVN of Advanced duplicator.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Auto-server reset script
« Reply #5 on: July 08, 2008, 07:48:57 PM »
Code: [Select]
// ARestart V1.0

local RDelay = 5 // Delay in minutes

function Reset()
local playerslist = player.GetAll()
if #playerslist == 0 then
timer.Create("ResetTimer", RDelay * 60, 1, RestartServer)
else
if timer.IsTimer("ResetTimer") then
timer.Destroy("ResetTimer")
end
end
timer.Create("ResetThinkTimer", 60, 0, Reset)
function RestartServer()
game.ConsoleCommand( "quit" )
end

Ok, added Megiddo's suggestion.

Quote
table.Count() shouldn't be used, use the # operator instead.
« Last Edit: July 16, 2008, 11:53:29 AM by jay209015 »
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Auto-server reset script
« Reply #6 on: July 09, 2008, 05:59:46 AM »
Let me revise my statement there. I thought you were actually using table.getn(), so it's time for a little history lesson!

# is a lua unary operator for getting the number of indexed values in a table. That means it will only count values that have a numeric index. It works perfectly for player.GetAll() and it's what you should use for that.

table.getn() basically maps to the # operator in lua 5.1. It's deprecated so you shouldn't use it.

table.Count() is another garry function that's nice but mistakenly used. Unlike the unary operator #, it counts ALL values in a table. You should only ever use it in cases where # won't since it's rather inefficient.
Experiencing God's grace one day at a time.

JerryTheStampede

  • Guest
Re: Auto-server reset script
« Reply #7 on: July 09, 2008, 10:17:56 AM »
Jay do you mind if I put your code on Facepunch, I'd give you credit of course. I think that a lot more people would be interested in this.

Offline Tophat Man

  • Newbie
  • *
  • Posts: 17
  • Karma: 2
Re: Auto-server reset script
« Reply #8 on: July 09, 2008, 11:38:09 AM »
Would there be a way to have the timer start when there is 1 player on and then they leave, so it doesn't keep resetting itself over and over when no one even went on?

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Auto-server reset script
« Reply #9 on: July 09, 2008, 12:42:57 PM »
Timers aren't called until someone joins (or at least this used to be the behavior), so it shouldn't continually restart already.
Experiencing God's grace one day at a time.

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Auto-server reset script
« Reply #10 on: July 09, 2008, 12:43:25 PM »
Quote
Jay do you mind if I put your code on Facepunch, I'd give you credit of course. I think that a lot more people would be interested in this.

Yeah, sure.

==EDIT==
Quote
Timers aren't called until someone joins (or at least this used to be the behavior), so it shouldn't continually restart already.
Tested, still applies.
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline nofear1999

  • Newbie
  • *
  • Posts: 30
  • Karma: 0
Re: Auto-server reset script
« Reply #11 on: August 07, 2008, 11:14:06 PM »
Would u make this a .bat or .lua if .lua where do i put it and name it

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Auto-server reset script
« Reply #12 on: August 08, 2008, 03:22:24 AM »
you can save it as anything.lua and drop it in your servers lua/autorun folder. If your server doesn't restart automatically after crashing, then this wont be of any use.
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly