This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Baaleos's profile picture

Pregen when server is empty

Started by Baaleos, 02 June 2016 - 07:39 AM
Baaleos #1
Posted 02 June 2016 - 09: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 on 02 June 2016 - 07:40 AM
Bomb Bloke #2
Posted 02 June 2016 - 10:55 AM
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…
Waitdev_ #3
Posted 02 June 2016 - 01:40 PM
For this if statement:


   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.
Baaleos #4
Posted 03 June 2016 - 11: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 :-( )
Bomb Bloke #5
Posted 03 June 2016 - 03:22 PM
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?".
TheRockettek #6
Posted 03 June 2016 - 04:06 PM
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]
Wergat #7
Posted 03 June 2016 - 04:06 PM
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 on 03 June 2016 - 02:07 PM