Hello, my lua script for shovel is not working like I wanted.
For now is openning hole always, doesn't matter if is field on it or any other item:
I would like players first destroy field, move items or disintegrate first before open hole (only ground tile?)
shovel.lua
For now is openning hole always, doesn't matter if is field on it or any other item:
I would like players first destroy field, move items or disintegrate first before open hole (only ground tile?)
shovel.lua
LUA:
local holes = {468, 481, 483}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if toPosition.x == CONTAINER_POSITION then
return false
end
local tile = Tile(toPosition)
if not tile then
return false
end
local ground = tile:getGround()
if not ground then
return false
end
local groundId = ground:getId()
if isInArray(holes, groundId) then
ground:transform(groundId + 1)
ground:decay()
toPosition.z = toPosition.z + 1
tile:relocateTo(toPosition)
elseif groundId == 231 then
local randomValue = math.random(1, 100)
if randomValue == 1 then
Game.createItem(2159, 1, toPosition)
elseif randomValue > 95 then
Game.createMonster("Scarab", toPosition)
end
toPosition:sendMagicEffect(CONST_ME_POFF)
else
return false
end
return true
end