• 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!

Don't delete items on doors that close automatically

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,713
Solutions
31
Reaction score
965
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
Guys!! Merry x-mas. I have a quick question here, a player of my server found a little bug on doors, which delete backpacks as soon they get automatically closed. I attached a video of it. I wonder, this can be easily fixed? If not, there could be a script which doesn't allow to throw items to a certain door id, or even easier, don't allow to move items to tile with aid/uid?


If there's a good fix for the issue directly would be really nice to have! Otherwise, I guess i'll try that second thing. By the way the door is triggered by a a script that make it works if the player has the requiered storage. Using TFS 1.5 nekiro downgrade. Thanks in advance!
 
Last edited:
Thanks for the reply Xikini!
Nimbus bot sent me this, there could be more optimized ways to handle it?

LUA:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getStorageValue(41300) > 0 then
        local tile = Tile(toPosition)
        if tile then
            local ground = tile:getGround()
            if ground then
                local items = ground:getItems()
                for i = 1, #items do
                    local item = items[i]
                    if item then
                        item:moveTo(Position(NEW_X, NEW_Y, NEW_Z)) -- Replace NEW_X, NEW_Y, NEW_Z with the new position where you want the item to be relocated
                    end
                end
            end
        end
       
        if item.itemid == 6259 then
            player:teleportTo(toPosition, true)
            item:transform(item.itemid + 1)
        elseif item.itemid == 10475 then
            player:teleportTo(toPosition, true)
            item:transform(item.itemid + 1)
        elseif item.itemid == 6261 then
            player:teleportTo(toPosition, true)
            item:transform(item.itemid + 1)
        end
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Debes completar la tarea de Demonios antes de entrar.")
    end
   
    return true
end

My original script, which is the reason behind I opened this thread is this:
LUA:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
        if player:getStorageValue(41300) > 0 then
        if item.itemid == 6259 then
            player:teleportTo(toPosition, true)
            item:transform(item.itemid + 1)
            end
        if item.itemid == 10475 then
            player:teleportTo(toPosition, true)
            item:transform(item.itemid + 1)
            end
        if item.itemid == 6261 then
            player:teleportTo(toPosition, true)
            item:transform(item.itemid + 1)
            end
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Debes completar la tarea de Demonios antes de entrar.")
            end
            return true
        end

Thanks in advance!
 
Take a look at this

 
Take a look at this


Appreciate it! Now I completely understand it, and fixed all the doors on my server.
Thanks a lot bro! :)
 
Appreciate it! Now I completely understand it, and fixed all the doors on my server.
Thanks a lot bro! :)
This is kind of a funny thing, but if the only way to access the door is via a diagonal movement, the items would still be removed.
So, just make sure at least 1 tile adjacent to every door is walkable and you won't have further issues.
(so horizontal door, at least 1 tile east/west, vertical door, at least 1 tile north/south)

In 99.9% of cases mappers will always make a direct door path, but like on real tibia map there are some niche door entries that are diagonal only, so figured I'd mention it.
Post automatically merged:

Appreciate it! Now I completely understand it, and fixed all the doors on my server.
Thanks a lot bro! :)

I'll post it here as well, but I upgraded the script further, so it'll check all 8 directions, trying to save the items.
LUA:
function Tile.getTopMovableItem(self)
    for i = self:getThingCount() - 1, 0, -1 do
        local thing = self:getThing(i)
        if thing and thing:isItem() and ItemType(thing:getId()):isMovable() then
            return thing
        end
    end
    return nil
end

function onStepOut(creature, item, position, fromPosition)
    local tile = Tile(position)
    if tile:getCreatureCount() > 0 then
        return true
    end
  
    local doorPosition = item:getPosition()
    local topMovableItem = Tile(doorPosition):getTopMovableItem()
  
    if topMovableItem then
        local directions = {
            {x = 1, y = 0},   -- east
            {x = 0, y = 1},   -- south
            {x = -1, y = 0},  -- west
            {x = 0, y = -1},  -- north
            {x = 1, y = -1},  -- northeast
            {x = -1, y = 1},  -- southwest
            {x = -1, y = -1}, -- northwest
            {x = 1, y = 1},   -- southeast
        }
  
        for _, dir in ipairs(directions) do
            local newPosition = {
                x = doorPosition.x + dir.x,
                y = doorPosition.y + dir.y,
                z = doorPosition.z
            }
  
            local query = Tile(newPosition):queryAdd(topMovableItem)
            if query == RETURNVALUE_NOERROR then
                doRelocate(doorPosition, newPosition)
                break
            end
        end
    end
  
    local i, tileItem, tileCount = 1, true, tile:getThingCount()
    while tileItem and i < tileCount do
        tileItem = tile:getThing(i)
        if tileItem and tileItem:getUniqueId() ~= item.uid and tileItem:getType():isMovable() then
            tileItem:remove()
        else
            i = i + 1
        end
    end
  
    item:transform(item.itemid - 1)
    return true
end
 
Last edited by a moderator:
This is kind of a funny thing, but if the only way to access the door is via a diagonal movement, the items would still be removed.
So, just make sure at least 1 tile adjacent to every door is walkable and you won't have further issues.
(so horizontal door, at least 1 tile east/west, vertical door, at least 1 tile north/south)

In 99.9% of cases mappers will always make a direct door path, but like on real tibia map there are some niche door entries that are diagonal only, so figured I'd mention it.
Post automatically merged:



I'll post it here as well, but I upgraded the script further, so it'll check all 8 directions, trying to save the items.
LUA:
function Tile.getTopMovableItem(self)
    for i = self:getThingCount() - 1, 0, -1 do
        local thing = self:getThing(i)
        if thing and thing:isItem() and ItemType(thing:getId()):isMovable() then
            return thing
        end
    end
    return nil
end

function onStepOut(creature, item, position, fromPosition)
    local tile = Tile(position)
    if tile:getCreatureCount() > 0 then
        return true
    end
 
    local doorPosition = item:getPosition()
    local topMovableItem = Tile(doorPosition):getTopMovableItem()
 
    if topMovableItem then
        local directions = {
            {x = 1, y = 0},   -- east
            {x = 0, y = 1},   -- south
            {x = -1, y = 0},  -- west
            {x = 0, y = -1},  -- north
            {x = 1, y = -1},  -- northeast
            {x = -1, y = 1},  -- southwest
            {x = -1, y = -1}, -- northwest
            {x = 1, y = 1},   -- southeast
        }
 
        for _, dir in ipairs(directions) do
            local newPosition = {
                x = doorPosition.x + dir.x,
                y = doorPosition.y + dir.y,
                z = doorPosition.z
            }
 
            local query = Tile(newPosition):queryAdd(topMovableItem)
            if query == RETURNVALUE_NOERROR then
                doRelocate(doorPosition, newPosition)
                break
            end
        end
    end
 
    local i, tileItem, tileCount = 1, true, tile:getThingCount()
    while tileItem and i < tileCount do
        tileItem = tile:getThing(i)
        if tileItem and tileItem:getUniqueId() ~= item.uid and tileItem:getType():isMovable() then
            tileItem:remove()
        else
            i = i + 1
        end
    end
 
    item:transform(item.itemid - 1)
    return true
end
Amazing as always bro! If I found situations where is diagonal paths I'll inmediatelly merge this changes.
Thanks a lot, regards :)
 

Similar threads

Back
Top