• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua hangable problem

Darius93

Active Member
Joined
Oct 16, 2022
Messages
88
Reaction score
27
Hello, I have a problem – I can’t find any Lua code related to decorations. I mean things like curtains that can be hung on the walls inside a house.
The problem is that I can hang the curtain, but then I can’t remove it afterwards.
My question is: where should I look for a solution? I tried searching for Lua files but couldn’t find any, and I have this code written in C++.

C++:
        if (player && tile->hasFlag(TILESTATE_SUPPORTS_HANGABLE)) {
            //do extra checks here if the thing is accessable
            if (thing && thing->getItem()) {
                if (tile->hasProperty(CONST_PROP_ISVERTICAL)) {
                    if (player->getPosition().x + 1 == tile->getPosition().x) {
                        thing = nullptr;
                    }
                } else { // horizontal
                    if (player->getPosition().y + 1 == tile->getPosition().y) {
                        thing = nullptr;
                    }
                }
            }
        }
        return thing;
    }


TFS 1.2
 
Notice that you can only remove curtains when you are on the correct side of the wall.
For horizontal walls that is below them.
For vertical wall that is on the right side of them.

Other than that, we need more information to be able to help.
 
I’m using this same TFS — I thought maybe I had changed something in the code, but no — I logged into another server from Otservlist that uses this TFS, and the bug is the same there.
Post automatically merged:

I must have messed something up in the sources, but I can't figure it out yet. For now, I've managed to fix it this way.
LUA:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    -- lista ID firanek, które można zdjąć
    local allowedIds = {1880, 1857, 1860, 1863, 1866, 1869, 1872, 7401, 7400, 7399, 7398, 7397, 7396, 7394, 7393}

    -- sprawdź, czy itemid znajduje się na liście
    local canRemove = false
    for _, id in ipairs(allowedIds) do
        if item.itemid == id then
            canRemove = true
            break
        end
    end
    if not canRemove then
        return false
    end

    -- sprawdź, czy faktycznie wisi na ścianie
    local tile = Tile(fromPosition)
    if not tile or not tile:hasFlag(TILESTATE_SUPPORTS_HANGABLE) then
        return true
    end

    -- usuń firankę ze ściany
    item:remove(1)

    -- daj taką samą firankę (TFS sam zdecyduje, czy do bp czy na ziemię)
    player:addItem(item.itemid, 1)
    player:getPosition():sendMagicEffect(CONST_ME_POFF)

    return true
end
 
Last edited:
Hello, I have a problem – I can’t find any Lua code related to decorations. I mean things like curtains that can be hung on the walls inside a house.
The problem is that I can hang the curtain, but then I can’t remove it afterwards.
My question is: where should I look for a solution? I tried searching for Lua files but couldn’t find any, and I have this code written in C++.

C++:
        if (player && tile->hasFlag(TILESTATE_SUPPORTS_HANGABLE)) {
            //do extra checks here if the thing is accessable
            if (thing && thing->getItem()) {
                if (tile->hasProperty(CONST_PROP_ISVERTICAL)) {
                    if (player->getPosition().x + 1 == tile->getPosition().x) {
                        thing = nullptr;
                    }
                } else { // horizontal
                    if (player->getPosition().y + 1 == tile->getPosition().y) {
                        thing = nullptr;
                    }
                }
            }
        }
        return thing;
    }


TFS 1.2
My guess is that some walls are not marked with the flags horizontal or vertical in items.otb. You can see that it works on the wall with ID 1050 and does not work on the wall with ID 1052.

Sem título.webp Sem título2.webp
 
Back
Top