Posts: 7
Threads: 1
Joined: Aug 2015
Thanks: 0
Given 0 thank(s) in 0 post(s)
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
Posts: 4,629
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
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.
Posts: 7
Threads: 1
Joined: Aug 2015
Thanks: 0
Given 0 thank(s) in 0 post(s)
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 :/
Posts: 4,629
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
Yeah, really strange indeed. I'll try to reproduce the issue.
Posts: 4,629
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
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.
Posts: 952
Threads: 16
Joined: May 2013
Thanks: 66
Given 105 thank(s) in 89 post(s)
And don't forget to use
Code: Player:SendMessageSuccess("Teleported to coordinates: " .. X .. etc.);
:)
Posts: 4,629
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
That's a matter of preference. I personally think they look awful, and I will never use them.
Posts: 4,629
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
08-31-2015, 04:24 AM
(This post was last modified: 09-02-2015, 11:23 PM by NiLSPACE.)
@ DiamondToaster What I suggested should already work. ChunkStay ensures that the chunk is loaded.
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1075 thank(s) in 852 post(s)
@ DiamondToaster: 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.
|