Cuberite Forum

Full Version: RandomTP
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
[Image: errrr.png]

PHP Code:
function Initialize(Plugin) Plugin:SetName("RandomTP") Plugin:SetVersion(1) cPluginManager.BindCommand("/rtp", "randomTP.rtp", Randomtp, " ~ Random Teleport"); LOG("Initialised " .. Plugin:GetName() .. " v." .. Plugin:GetVersion()) return true end function Randomtp(Split, Player) if (#Split ~= 1) then Player:SendMessage("Usage: /rtp") return true else local X = math.random(-2000, 2000) local Z = math.random(-2000, 2000) local _, Height local World = Player:GetWorld() World:ChunkStay({{math.floor(X / 16), math.floor(Z / 16)}}, nil, function() _, Height = World:TryGetHeight(X, Z) end ) Player:TeleportToCoords(X, Height, Z) Player:SendMessage(cChatColor.Yellow .. "Cords") Player:SendMessage("X: " .. X) Player:SendMessage("Y: " .. Height) Player:SendMessage("Z: " .. Z) end return true end
That's really weird. Could you add a "print(X, Height, Z)" before the TeleportToCoords line? And perhaps add "print(Height)" after the TryGetHeight function.
[Image: errrrr.png]

before error is -1227 nil 1235

PHP Code:
function Initialize(Plugin) Plugin:SetName("RandomTP") Plugin:SetVersion(1) cPluginManager.BindCommand("/rtp", "randomTP.rtp", Randomtp, " ~ Random Teleport"); LOG("Initialised " .. Plugin:GetName() .. " v." .. Plugin:GetVersion()) return true end function Randomtp(Split, Player) if (#Split ~= 1) then Player:SendMessage("Usage: /rtp") return true else local X = math.random(-2000, 2000) local Z = math.random(-2000, 2000) local _, Height local World = Player:GetWorld() World:ChunkStay({{math.floor(X / 16), math.floor(Z / 16)}}, nil, function() _, Height = World:TryGetHeight(X, Z) print(X, Height, Z) end ) print(X, Height, Z) Player:TeleportToCoords(X, Height, Z) Player:SendMessage(cChatColor.Yellow .. "Cords") Player:SendMessage("X: " .. X) Player:SendMessage("Y: " .. Height) Player:SendMessage("Z: " .. Z) end return true end

Its a madness. Values are great, teleportation should work :/
Yeah, really strange indeed. I'll try to reproduce the issue.
Oh, I believe ChunkStay is async. Because of that the Height variable isn't filled when trying to teleport the player.
If you move the teleport/sendmessage code in the function where you get the height it should work properly.
And don't forget to use

Code:
Player:SendMessageSuccess("Teleported to coordinates: " .. X .. etc.);

:)
That's a matter of preference. I personally think they look awful, and I will never use them.
What I suggested should already work. ChunkStay ensures that the chunk is loaded.
: Your code is wrong, you're using function DoCheck() before you define it. Also, ChunkStay ensures that the chunk is loaded so checking is not needed anymore, just teleport.
Pages: 1 2