Hi there
I am writing an plugin and wanted to know if a selcted Block (x,y,z Coords) has one ore more buttons or a torch or .....
How can i get this information ?
Hello, and welcome to the forum.
You mean if it has a block attached to it? You'll have to check the block next to it with cWorld:GetBlock() You'll have to check the meta to see if it's actually attached though.
function IsAttached(a_World, a_BlockX, a_BlockY, a_BlockZ, a_RequiredMeta)
local Block, Meta = a_World:GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ)
if ((Block == E_BLOCK_TORCH) or (Block == E_BLOCK_STONE_BUTTON)) then
-- return true if the meta is correct
end
return false
end
function OnPlayerLeftClick(a_Player, X, Y, Z)
local World = a_Player:GetWorld()
-- I used some random numbers as meta value
if (not IsAttached(World, X + 1, Y, Z, 5) and
not IsAttached(World, X - 1, Y, Z, 2) and
not IsAttached(World, X, Y, Z + 1, 1) and
not IsAttached(World, X, Y, Z - 1, 0)
) then
-- Block is not attached, bail out.
return false
end
-- Do whatever you want to do if there is a torch or button attached
end
: Basically, yes, but a_RequiredMeta is a bad idea - what if there are blocks for which the meta differs from button's metas. A better approach would be a_BlockFace, specifying which blockface we're checking for attachment. Then each block type would check the meta for that specific blockface.