Cuberite Forum
RandomTP - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html)
+--- Thread: RandomTP (/thread-2093.html)

Pages: 1 2


RE: RandomTP - Keith - 08-30-2015

[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(SplitPlayer)
    if (
#Split ~= 1) then
        
Player:SendMessage("Usage: /rtp")
        return 
true
    
else
        
local X math.random(-20002000)
        
local Z math.random(-20002000)
        
local _Height
         
        local World 
Player:GetWorld()
        
World:ChunkStay({{math.floor(16), math.floor(16)}}, nil,  
            function()
                
_Height World:TryGetHeight(XZ)
            
end
        
)
        
Player:TeleportToCoords(XHeightZ)
        
Player:SendMessage(cChatColor.Yellow .. "Cords")
        
Player:SendMessage("X: " .. X)
        
Player:SendMessage("Y: " .. Height)
        
Player:SendMessage("Z: " .. Z)
    
end
    
return true
end 



RE: RandomTP - NiLSPACE - 08-30-2015

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.


RE: RandomTP - Keith - 08-30-2015

[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(SplitPlayer)
    if (
#Split ~= 1) then
        
Player:SendMessage("Usage: /rtp")
        return 
true
    
else
        
local X math.random(-20002000)
        
local Z math.random(-20002000)
        
local _Height
         
        local World 
Player:GetWorld()
        
World:ChunkStay({{math.floor(16), math.floor(16)}}, nil,  
            function()
                
_Height World:TryGetHeight(XZ)
                print(
XHeightZ)
            
end
        
)
        print(
XHeightZ)
        
Player:TeleportToCoords(XHeightZ)
        
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 :/


RE: RandomTP - NiLSPACE - 08-30-2015

Yeah, really strange indeed. I'll try to reproduce the issue.


RE: RandomTP - NiLSPACE - 08-30-2015

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.


RE: RandomTP - tigerw - 08-30-2015

And don't forget to use

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

:)


RE: RandomTP - NiLSPACE - 08-30-2015

That's a matter of preference. I personally think they look awful, and I will never use them.


RE: RandomTP - NiLSPACE - 08-31-2015

@DiamondToaster What I suggested should already work. ChunkStay ensures that the chunk is loaded.


RE: RandomTP - xoft - 08-31-2015

@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.