Jump to content




Pregen when server is empty

computer utility command

6 replies to this topic

#1 Baaleos

  • Members
  • 11 posts

Posted 02 June 2016 - 08:39 AM

Probably not much use to the bigger servers, but for people who run small - medium servers where they would have periods of time where the server is empty.

So - Using the Admin Locator from Draconic Evolution - to teleport new players to random locations within 10,000 blocks of spawn - this can be laggy when teleporting them to a new area which has not been generated yet.
The solution for this is to pregen your world, however pregen itself is a laggy process, you cannot really play the game while it is on-going.

Note : For this script to work, you need to have ForgeEssentials installed.

Note - the getPlayers command borrowed from here
http://www.computerc...nates-and-more/
function getPlayers(radius,x,y,z)
  if x then x = "x="..x else x = "" end
  if y then y = ",y="..y else y = "" end
  if z then z = ",z="..z else z = "" end
  local command = "0 @a"
  if radius then
		command = "0 @a["..x..y..z..(",r="..radius).."]"
  end
  local state,result = commands.xp(command)
  local players = {}
  for i = 1, #result do
		table.insert(players,string.match(result[i],"Given 0 experience to (%w+)"))
  end
  return #players
end  


local inProgress = false;
while true do
   if getPlayers() == 0  then
		  if inProgress == false then
			 inProgress = true;
			 commands.say("Pregen starting!");
			 commands.exec("pregen start false 0");
		  end
   else
		 if inProgress == true then
			 inProgress = false;
			 commands.say("Pregen Stopping as a player has joined");
			 commands.exec("pregen stop")
		 end
   end
sleep(10)
end


The idea of this script is to pregen while everyone is offline, but stop when a player joins, then to resume pregen when the server empties again.
Note - this is reliant on the pregen command from ForgeEssentials, as it has a nice pregen command that resumes where it left off etc.

Im sure it could be improved on.
Script works best as a startup command.

Edited by Baaleos, 02 June 2016 - 08:40 AM.


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 02 June 2016 - 09:55 AM

View PostBaaleos, on 02 June 2016 - 08:39 AM, said:

Note - this is reliant on the pregen command from ForgeEssentials, as it has a nice pregen command that resumes where it left off etc.

You could remove that dependency - commands.getBlockInfo() can be used to generate chunks. You'd need to keep track of which chunks you've processed within your code, though...

#3 Waitdev_

  • Members
  • 432 posts
  • LocationAdelaide

Posted 02 June 2016 - 12:40 PM

For this if statement:

View PostBaaleos, on 02 June 2016 - 08:39 AM, said:

   if getPlayers() == 0  then
		  if inProgress == false then
			 inProgress = true;
			 commands.say("Pregen starting!");
			 commands.exec("pregen start false 0");
		  end
   else
		 if inProgress == true then
			 inProgress = false;
			 commands.say("Pregen Stopping as a player has joined");
			 commands.exec("pregen stop")
		 end
   end

You could do instead of "if inprogress == true then..." do "if inprogress then..." and for "if inprogress == false then..." you could do "if not inprogress then..."

Though otherwise, it looks like a pretty cool and useful program.

#4 Baaleos

  • Members
  • 11 posts

Posted 03 June 2016 - 10:29 AM

Only potentially negative effect of this is that server backups go way up in size.
I am hosted via a company - they do automated backups, which so far they aren't charging extra for, but the backups used to be finished in 30 seconds, amounting to 300-400 mb in size.
Now after running this script for 2 days (idle while players are online), the backups are up to about 3-4 gb in size and takes about 2-3 minutes to finish.

Haven't tried the draconic evolution dislocation yet - so I am unsure how positive an effect it will have had on the random warp when people enter my spawn area.

It would be nice if there was a way of detecting players on the server, without having to execute the xp command.
I don't like it spamming the console - while the players are online.
(Note - I have the gamerule for quiet command blocks on - I am just talking about when I view the server console - it looks awful when you see 'Giving 0xp to blah blah' over and over and over.
Players never see it - but I do from my admin console :-( )

#5 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 03 June 2016 - 02:22 PM

View PostBaaleos, on 03 June 2016 - 10:29 AM, said:

Now after running this script for 2 days (idle while players are online), the backups are up to about 3-4 gb in size and takes about 2-3 minutes to finish.

My first thought is "those don't sound like incremental backups...".

My second, scarier thought is "what if they are?".

#6 TheRockettek

  • Members
  • 547 posts
  • LocationRem is best girl

Posted 03 June 2016 - 03:06 PM

View PostBaaleos, on 03 June 2016 - 10:29 AM, said:

It would be nice if there was a way of detecting players on the server, without having to execute the xp command.
I don't like it spamming the console - while the players are online.
(Note - I have the gamerule for quiet command blocks on - I am just talking about when I view the server console - it looks awful when you see 'Giving 0xp to blah blah' over and over and over.

cant you do /testfor @e[type=Player]

#7 Wergat

  • Members
  • 18 posts

Posted 03 June 2016 - 03:06 PM

View PostBaaleos, on 03 June 2016 - 10:29 AM, said:

It would be nice if there was a way of detecting players on the server, without having to execute the xp command.
I don't like it spamming the console - while the players are online.
(Note - I have the gamerule for quiet command blocks on - I am just talking about when I view the server console - it looks awful when you see 'Giving 0xp to blah blah' over and over and over.
Players never see it - but I do from my admin console :-( )

There is a gamerule "logAdminCommands" (or so), wich will log your commands to the console. I am about 90% that it already is in 1.8, you need to disable this option to fix your problem.
It should be:
/gamerule logAdminCommands false

Edited by Wergat, 03 June 2016 - 03:07 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users