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

Spawn/Chunk Generator - commands.tp() help

Started by Rader2146, 24 March 2015 - 04:57 AM
Rader2146 #1
Posted 24 March 2015 - 05:57 AM
Hi Pros,

I am trying to write a program that will TP a player around a large area to "pre-grenerate" chunks. I have the main code complete and working but I'd like for the program to TP the player back to the original center location (the location of the computer). I have not been able to figure out the correct way to get commands.getBlockPosition() and commands.tp() to work together to TP the player back to the computer's location.

Main Code:

x, y, z = commands.getBlockPosition()

function vertLoop()
	for i = 1, 10, 1 do
		commands.tp("@p ~ 255 ~200")
		print(i)
		sleep(20)
	end	
end	

function nextColumn()
	commands.tp("@p ~200 255 ~-2000")
	sleep(20)
end	

function chunkGen()
	for x = 1, 9, 1 do
		vertLoop()
		nextColumn()
	end
	vertLoop()
end	

--Main Code
commands.tp("@p ~-1000 255 ~-1000")   --TP player to NW corner.
sleep(20)
chunkGen()

--Return to Computer's location.  (NOT WORKING)
commands.tp("@p x y x")

Code used in testing:

x, y, z = commands.getBlockPosition()

print( "Command Computer's position:" )
print("X: ", x)
print("Y: ", y)
print("Z: ", z)

commands.tp("@p x y z")

The terminal will print the computer's position but i do not get TP'd, it just returns to the command line. I've tried multiple differnt argument areangements, comma's between arguments, concatenation, and this bit of code from another thread that is said to work and TP the player 20 blocks above the computer:


local x, y, z = commands.getBlockPosition()
commands.tp("@a[x="..x..",y="..(y+1)..",z="..z..",r=1] ~ ~20 ~")

The tp commands are working fine in the mainc code with absolute and relative values, but I seem to be missing something when using the variables.
HPWebcamAble #2
Posted 24 March 2015 - 10:56 PM
You'd need to concatenate the variables with the command:
(That just means combine)


commands.tp("@p "..x.." "..y.." "..z)
Edited on 24 March 2015 - 09:56 PM
Bomb Bloke #3
Posted 24 March 2015 - 11:38 PM
Really you'd be better off using commands.getBlockInfo() for this; it also generates chunks, but doesn't require an actual player to move around (which should make it much, much faster; plus simpler, because you don't need to find where the player already is every time you want to teleport them somewhere else…). Only catch is that you need to target a chunk at a time, but that's no big problem.

Something like this should do the trick:

local length = 128  -- In chunks.

local x, y, z = commands.getBlockPosition()

x, z = math.floor(x / 16 - length / 2), math.floor(z / 16 - length / 2)

for i = z, z + length - 1 do for j = x, x + length - 1 do
	commands.getBlockInfo(j * 16 + 8, y, i * 16 + 8)
end end
Edited on 24 March 2015 - 10:40 PM
Rader2146 #4
Posted 25 March 2015 - 04:16 AM
You'd need to concatenate the variables with the command:
(That just means combine)


commands.tp("@p "..x.." "..y.." "..z)

This works perfectly. Thank you.

Really you'd be better off using commands.getBlockInfo() for this <snip>

I wanted to use TP for this because it will also render Mapwriter's full screen map. The initial purpose for the program was to aid in finding a good seed. I got tired of flying around aimlessly just to miss the fact that a HUGE area of the map is nothing but ocean (for example). Now I will run program, wait a bit, evaluate the map to see if its an acceptable seed.

If i only wanted to generate the chunks I would use the Admin Command Toolbox mod.

Thanks for your help guys!!!