Posts: 7
Threads: 1
Joined: Aug 2015
Thanks: 0
Given 0 thank(s) in 0 post(s)
Hi, its my first plugin in LUA.
I don't know how to check the ID of block in random XYZ position.
Sometimes its move me into blocks. I want to teleport olny on grass, sand, dirt.
Please help
PHP Code: function Randomtp(Split, Player) if (#Split ~= 1) then Player:SendMessage("Usage: /rtp") return true else X = math.random(-2000, 2000) Y = math.random(40,70) Z = math.random(-2000, 2000) Player:TeleportToCoords(X, Y, Z) Player:SendMessage(cChatColor.Yellow .. "Cords") Player:SendMessage("X: " .. X) Player:SendMessage("Y: " .. Y) 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)
08-30-2015, 12:11 AM
(This post was last modified: 08-30-2015, 12:12 AM by NiLSPACE.)
Hello, and welcome to the forum
You can use this:
local BlockID = Player:GetWorld():GetBlock(X, Y, Z)
if ((BlockID == E_BLOCK_GRASS) or (BlockID == E_BLOCK_DIRT) or (BLOCKID == E_BLOCK_SAND)) then
-- Teleport the player
end
But keep in mind that a player can now be teleported inside block. If you use this:
local X = math.random(-2000, 2000)
local Z = math.random(-2000, 2000)
local Succes, Y = Player:GetWorld():TryGetHeight(X, Z)
the player should teleport to the highest block instead.
Posts: 7
Threads: 1
Joined: Aug 2015
Thanks: 0
Given 0 thank(s) in 0 post(s)
I used :
PHP Code: X = math.random(-2000, 2000) Z = math.random(-2000, 2000) Y = Player:GetWorld():GetHeight(X, Z)
Trying to use TryGetHeight(X, Z), returned bool value and error in colsole.
Posts: 350
Threads: 18
Joined: Oct 2014
Thanks: 26
Given 54 thank(s) in 47 post(s)
TryGetHeight() returns two different variables on completion. The first is a boolean which indicates if the chunk is even loaded and a second which is the highest block point on those X and Z coordinates. You would have to set TryGetHeight() equal to 2 variables and use the second one to get the right value.
local IsChunkLoaded
local Height
IsChunkLoaded, Height = Player:GetWorld():TryGetHeight(X, Z)
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 X = math.random(-2000, 2000) Z = math.random(-2000, 2000) local IsChunkLoaded local Height IsChunkLoaded, Height = Player:GetWorld():TryGetHeight(X, Z) Player:TeleportToCoords(X, Height, Z) Player:SendMessage(cChatColor.Yellow .. "Cords") Player:SendMessage("X: " .. X) Player:SendMessage("Y: " .. Y) 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)
08-30-2015, 02:07 AM
(This post was last modified: 08-30-2015, 02:25 AM by NiLSPACE.)
The chunk is most likely not loaded. Try this:
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
)
It will ensure that the chunks are loaded and then get the height.
Btw, I didn't test this code. There might be a syntax error in it.
Posts: 7
Threads: 1
Joined: Aug 2015
Thanks: 0
Given 0 thank(s) in 0 post(s)
08-30-2015, 04:39 AM
(This post was last modified: 08-30-2015, 04:40 AM by Keith.)
NiLSPACE,
It works with GetHeight(X, Z). But sometimes it is teleporting me before chunk load, and im locking in blocks
Posts: 4,629
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
Ooh, I see the problem. Try:
World:ChunkStay({{math.floor(X / 16), math.floor(Z / 16)}}, nil,
Posts: 7
Threads: 1
Joined: Aug 2015
Thanks: 0
Given 0 thank(s) in 0 post(s)
PHP Code: argument #3 is nil ; 'number' expected
Posts: 4,629
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
That's weird. Could you post the whole code + whole error?
|