• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua destroy() not working

Yalasari

Active Member
Joined
Jul 16, 2017
Messages
82
Solutions
8
Reaction score
46
Hello,

In my script i want to destroy all obstacles on tile where i create monster with function createMonster()

Lua:
local bossname = "Corym King" -- nazwa bossa
local isBossPresentID = 66001 -- ID z pliku storages

local xpos = 4840 -- wspolrzedne x
local ypos = 5153 -- wspolrzedne y
local zpos = 9 -- wspolrzedne z

local xrand = math.random(-1, 1)
local yrand = math.random(-1, 1)

local position = Position(xpos + xrand, ypos + yrand, zpos)

local addtionalTime = math.random(0, 180) * 100

local function spawnBoss()
   
     broadcastMessage('executing spawnBoss...', MESSAGE_STATUS_WARNING)
   
    if Game.getStorageValue(isBossPresentID) ~= 1 then
   
         broadcastMessage('if statement... ok', MESSAGE_STATUS_WARNING)

        if Tile(position) ~= nil then

            Tile(position):remove()

        else end
   
        Game.createMonster(bossname, position)
       
        -- // --

        xrand = math.random(-1, 1)
        yrand = math.random(-1, 1)
       
        addtionalTime = math.random(0, 180) * 100
   
        position = Position(xpos + xrand, ypos + yrand, zpos)
   
        addEvent(spawnBoss, 12 * 100 + addtionalTime) -- respi sie za 12h + losowy czas
       
        Game.setStorageValue(isBossPresentID, 1)
   
    else
   
         broadcastMessage('if statement failed...', MESSAGE_STATUS_WARNING)
       
        addtionalTime = math.random(0, 180) * 100
       
        addEvent(spawnBoss, 12 * 100 + addtionalTime) -- respi sie za 12 h + losowy czas
   
    end

end

function onTime(interval)
   
      broadcastMessage('executing onTime...', MESSAGE_STATUS_WARNING)
   
     addEvent(spawnBoss, addtionalTime)
     
     return true
    
end

This is the code, there's some code that i tried to use but everything causes failure and never destroys tile.

Thanks in advance
 
Solution
Code:
local tile = Tile(position)
if tile then
    local items = tile:getItems()
    if items then
        for _, item in pairs(items) do
            item:remove()
        end
    end
end
Code:
local tile = Tile(position)
if tile then
    local items = tile:getItems()
    if items then
        for _, item in pairs(items) do
            item:remove()
        end
    end
end
 
Solution
Back
Top