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

TFS 1.X+ mwall wont appear if player is standing in the sqm

Jeyci

Banned User
Joined
May 6, 2023
Messages
289
Solutions
3
Reaction score
36
Hi, as title says. TFS 1.5 - protocol 8.6

This is the script of the banshee quests, where you push a lever and it makes mwall dissapear for x amount of time. In this case, the mwall in not being created if the player is standing in the sqm where the mwall should appear. How do i do in order to make the wall appears again, although the player is standing in this sqm? I have no errors in console, the mwall just do not appears
Lua:
local config = {
    [49998] = {position = Position(32259, 31891, 10), revert = true},
    [49999] = {position = Position(32259, 31890, 10), revert = true},
    [50000] = {position = Position(32259, 31891, 10), revert = true},
    [50001] = {position = Position(32259, 31890, 10), revert = true},
    [50002] = {position = Position(32266, 31860, 11)},

    time = 200
}

local function revertWall(wallPosition, leverPosition)
    local leverItem = Tile(leverPosition):getItemById(1946)
    if leverItem then
        leverItem:transform(1945)
    end

    Game.createItem(1498, 1, wallPosition)
end

local function removeWall(position)
    local tile = position:getTile()
    if not tile then
        return
    end

    local thing = tile:getItemById(1498)
    if thing then
        thing:remove()
        position:sendMagicEffect(CONST_ME_MAGIC_RED)
    end
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid ~= 1945 then
        player:sendCancelMessage('The lever has already been used.')
        return true
    end

    local wall = config[item.uid]
    removeWall(wall.position)
    if wall.revert then
        addEvent(revertWall, config.time * 1000, wall.position, toPosition)
    end
    item:transform(1946)
    return true
end
 
Solution
Lua:
local config = {

    [49999] = {position = Position(32259, 31890, 10), relocateTo = Position(32605, 31903, 3), revert = true},
   


    time = 4

}

--local config2 = {
--WallPosition = {position = Position(32259, 31890, 10)},
--newPos = {position = Position(32259, 31889, 10)},

--}
local function revertWall(wallPosition, leverPosition)
    local leverItem = Tile(leverPosition):getItemById(1946)
    if leverItem then
        leverItem:transform(1945)
    end

     Tile(wallPosition):relocateTo(newPos)
    Game.createItem(1498, 1, wallPosition)
    --Tile(wallPosition):relocateTo(newPos)

end

Code:
local function removeWall(position)
    local tile = position:getTile()
    if not tile then
        return
    end

    local thing =...
It's added but also removed due to that:

If it's PvP world try with ITEM_MAGICWALL_NOPVP or put no pvp zone there
Yes i remmeber that it was removed, thank you for point me it out. do you have the commit? i want to revert it, if i put a no pvp zone there it will cause problem while pking since it's a pvp world
edit okey i reveted this, now mw is appearing
Lua:
{
    const ItemType& it = items[getID()];
    if (it.conditionDamage) {
        Condition* conditionCopy = it.conditionDamage->clone();
        uint32_t ownerId = getOwner();
        if (ownerId) {
            bool harmfulField = true;

            if (g_game.getWorldType() == WORLD_TYPE_NO_PVP || getTile()->hasFlag(TILESTATE_NOPVPZONE)) {
                Creature* owner = g_game.getCreatureByID(ownerId);
                if (owner) {
                    if (owner->getPlayer() || (owner->isSummon() && owner->getMaster()->getPlayer())) {
                        harmfulField = false;
                    }
                }
            }

            Player* targetPlayer = creature->getPlayer();
            if (targetPlayer) {
                Player* attackerPlayer = g_game.getPlayerByID(ownerId);
                if (attackerPlayer) {
                    if (Combat::isProtected(attackerPlayer, targetPlayer)) {
                        harmfulField = false;
                    }
                }
            }

            if (!harmfulField || (OTSYS_TIME() - createTime <= 5000) || creature->hasBeenAttacked(ownerId)) {
                conditionCopy->setParam(CONDITION_PARAM_OWNER, ownerId);
            }
        }

        creature->addCondition(conditionCopy);
    }
}


how do i push the player one step back once the mw appears? like push the player ? with my script
Code:
local config = {
    [49998] = {position = Position(32259, 31891, 10), revert = true},
    [49999] = {position = Position(32259, 31890, 10), revert = true},
    [50000] = {position = Position(32259, 31891, 10), revert = true},
    [50001] = {position = Position(32259, 31890, 10), revert = true},
    [50002] = {position = Position(32266, 31860, 11)},

    time = 10
}

local function revertWall(wallPosition, leverPosition)
    local leverItem = Tile(leverPosition):getItemById(1946)
    if leverItem then
        leverItem:transform(1945)
    end

    Game.createItem(1498, 1, wallPosition)
end

local function removeWall(position)
    local tile = position:getTile()
    if not tile then
        return
    end

    local thing = tile:getItemById(1498)
    if thing then
        thing:remove()
        position:sendMagicEffect(CONST_ME_MAGIC_RED)
    end
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid ~= 1945 then
        player:sendCancelMessage('The lever has already been used.')
        return true
    end

    local wall = config[item.uid]
    removeWall(wall.position)
    if wall.revert then
        addEvent(revertWall, config.time * 1000, wall.position, toPosition)
    end
    item:transform(1946)
    return true
end

by now obviously player is standing on top of mwall
 
Last edited:
Before Game.createItem add:
Lua:
Tile(wallPosition):relocateTo(newPos)

WallPosition = mw position
newPos = player position after being pulled
 
Before Game.createItem add:
Lua:
Tile(wallPosition):relocateTo(newPos)

WallPosition = mw position
newPos = player position after being pulled
Lua:
local function revertWall(wallPosition, leverPosition)
    local leverItem = Tile(leverPosition):getItemById(1946)
    if leverItem then
        leverItem:transform(1945)
    end

    Game.createItem(1498, 1, wallPosition)
    Tile(wallPosition):relocateTo(newPos)
end
added the line here but didn't work, or what should i do? i was looking this thread where you fixed few scripts but didn't get what you did quite well since the whjole scripts changed :( TFS 1.X+ - how to kick monsters and items off a wall in lever script tfs 1.5 (https://otland.net/threads/how-to-kick-monsters-and-items-off-a-wall-in-lever-script-tfs-1-5.284434/#post-2720082)
 
you have to pay attention, I said before the Game.createItem and what is wallPosition and newPos, not a simple copy and paste.

if you make the necessary changes it will work.
 
you have to pay attention, I said before the Game.createItem and what is wallPosition and newPos, not a simple copy and paste.

if you make the necessary changes it will work.
Yes i tried this:
Lua:
local config = {
    [49998] = {position = Position(32259, 31891, 10), revert = true},
    [49999] = {position = Position(32259, 31890, 10), revert = true},
    [50000] = {position = Position(32259, 31891, 10), revert = true},
    [50001] = {position = Position(32259, 31890, 10), revert = true},
    [50002] = {position = Position(32266, 31860, 11)},

    time = 4
}

WallPosition = {position = Position(32259, 31890, 10)},
newPos = {position = Position(32259, 31889, 10)},
local function revertWall(wallPosition, leverPosition)
    local leverItem = Tile(leverPosition):getItemById(1946)
    if leverItem then
        leverItem:transform(1945)
    end

Tile(wallPosition):relocateTo(newPos)
    Game.createItem(1498, 1, wallPosition)
end
 
you do not need to declare wallPosition as it has already been declared in your function, now you need newPos, but you must declare or put it like this relocateTo(position here) or local newPos = Position(...)
 
Lua:
local config = {

    [49999] = {position = Position(32259, 31890, 10), relocateTo = Position(32605, 31903, 3), revert = true},
    


    time = 4

}

--local config2 = {
--WallPosition = {position = Position(32259, 31890, 10)},
--newPos = {position = Position(32259, 31889, 10)}, 

--}
local function revertWall(wallPosition, leverPosition)
    local leverItem = Tile(leverPosition):getItemById(1946)
    if leverItem then
        leverItem:transform(1945)
    end

     Tile(wallPosition):relocateTo(newPos)
    Game.createItem(1498, 1, wallPosition)
    --Tile(wallPosition):relocateTo(newPos)

end

Code:
local function removeWall(position)
    local tile = position:getTile()
    if not tile then
        return
    end

    local thing = tile:getItemById(1498)
    if thing then
        thing:remove()
        position:sendMagicEffect(CONST_ME_MAGIC_RED)
    end
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid ~= 1945 then
        player:sendCancelMessage('The lever has already been used.')
        return true
    end

    local wall = config[item.uid]
    removeWall(wall.position)
    if wall.revert then
        addEvent(revertWall, config.time * 1000, wall.position, toPosition)
    end
    item:transform(1946)
    return true
end
tried this way now
what's wrong ?
 
Lua:
local function revertWall(wallPosition, leverPosition)
    local leverItem = Tile(leverPosition):getItemById(1946)
    if leverItem then
        leverItem:transform(1945)
    end

    Tile(wallPosition):relocateTo(Position(32259, 31889, 10))
    Game.createItem(1498, 1, wallPosition)
end
 
Lua:
local config = {

    [49999] = {position = Position(32259, 31890, 10), relocateTo = Position(32605, 31903, 3), revert = true},
   


    time = 4

}

--local config2 = {
--WallPosition = {position = Position(32259, 31890, 10)},
--newPos = {position = Position(32259, 31889, 10)},

--}
local function revertWall(wallPosition, leverPosition)
    local leverItem = Tile(leverPosition):getItemById(1946)
    if leverItem then
        leverItem:transform(1945)
    end

     Tile(wallPosition):relocateTo(newPos)
    Game.createItem(1498, 1, wallPosition)
    --Tile(wallPosition):relocateTo(newPos)

end

Code:
local function removeWall(position)
    local tile = position:getTile()
    if not tile then
        return
    end

    local thing = tile:getItemById(1498)
    if thing then
        thing:remove()
        position:sendMagicEffect(CONST_ME_MAGIC_RED)
    end
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid ~= 1945 then
        player:sendCancelMessage('The lever has already been used.')
        return true
    end

    local wall = config[item.uid]
    removeWall(wall.position)
    if wall.revert then
        addEvent(revertWall, config.time * 1000, wall.position, toPosition)
    end
    item:transform(1946)
    return true
end
tried this way now
what's wrong ?

Kind of right.
The table is good, where you add the relocate position.

Now you need to send that information to the revertWall function.

change
Lua:
addEvent(revertWall, config.time * 1000, wall.position, toPosition)
to
Lua:
addEvent(revertWall, config.time * 1000, wall.position, wall.relocateTo, toPosition)

change
Lua:
local function revertWall(wallPosition, leverPosition)
to
Lua:
local function revertWall(wallPosition, wallRelocateToPosition, leverPosition)
change
Lua:
Tile(wallPosition):relocateTo(newPos)
to
Lua:
Tile(wallPosition):relocateTo(wallRelocateToPosition)
 
Solution
worked, thanks for your patience, to you both guys, everything super cool .
Another how i do for a second mwall in the same table?

if im doing in it this way?
Lua:
local function revertWall(wallPosition, wallRelocateToPosition, leverPosition)
    local leverItem = Tile(leverPosition):getItemById(1946)
    if leverItem then
        leverItem:transform(1945)
    end

    Tile(wallPosition):relocateTo(Position(32259, 31889, 10))
    Game.createItem(1498, 1, wallPosition)
end

was trying like in a table in order to ahcieve something like i want
Code:
[49999] = {position = Position(32259, 31890, 10), relocateTo = Position(32605, 31903, 3), revert = true},
 
Last edited:
worked, thanks for your patience, to you both guys, everything super cool .
Another how i do for a second mwall in the same table?

if im doing in it this way?
Lua:
local function revertWall(wallPosition, wallRelocateToPosition, leverPosition)
    local leverItem = Tile(leverPosition):getItemById(1946)
    if leverItem then
        leverItem:transform(1945)
    end

    Tile(wallPosition):relocateTo(Position(32259, 31889, 10))
    Game.createItem(1498, 1, wallPosition)
end

was trying like in a table in order to ahcieve something like i want
Code:
[49999] = {position = Position(32259, 31890, 10), relocateTo = Position(32605, 31903, 3), revert = true},
you forgot to change this line
Lua:
Tile(wallPosition):relocateTo(Position(32259, 31889, 10))

Once you do that, you'll be able to add as many things to the table as you want.
 
Yeah now it's working like I want. thank you guys, i've learned something new and that i found a bit tricky
Lua:
local config = {
    [49998] = {position = Position(32259, 31891, 10),  revert = true},
    [49999] = {position = Position(32259, 31890, 10), relocateTo = Position(32605, 31903, 3), revert = true},
    [50000] = {position = Position(32259, 31891, 10), revert = true},
    [50001] = {position = Position(32259, 31890, 10), revert = true},
    [50002] = {position = Position(32266, 31860, 11)},


    time = 10

}
--local config2 = {
--WallPosition = {position = Position(32259, 31890, 10)},
--newPos = {position = Position(32259, 31889, 10)},

--}
local function revertWall(wallPosition, wallRelocateToPosition, leverPosition)
    local leverItem = Tile(leverPosition):getItemById(1946)
    if leverItem then
        leverItem:transform(1945)
    end
--Tile(wallPosition):relocateTo(newPos)
    --Tile(wallPosition):relocateTo(Position(32259, 31889, 10))
    Tile(wallPosition):relocateTo(wallRelocateToPosition)
    Game.createItem(1498, 1, wallPosition)
end

edit: instead of a teleporting the behavior could be like an slighly step out? like when you be pushed out because you used the door and you're standing in it
 
Last edited:
Yeah now it's working like I want thank you guys
Lua:
local config = {
    [49998] = {position = Position(32259, 31891, 10),  revert = true},
    [49999] = {position = Position(32259, 31890, 10), relocateTo = Position(32605, 31903, 3), revert = true},
    [50000] = {position = Position(32259, 31891, 10), revert = true},
    [50001] = {position = Position(32259, 31890, 10), revert = true},
    [50002] = {position = Position(32266, 31860, 11)},


    time = 10

}
--local config2 = {
--WallPosition = {position = Position(32259, 31890, 10)},
--newPos = {position = Position(32259, 31889, 10)},

--}
local function revertWall(wallPosition, wallRelocateToPosition, leverPosition)
    local leverItem = Tile(leverPosition):getItemById(1946)
    if leverItem then
        leverItem:transform(1945)
    end
--Tile(wallPosition):relocateTo(newPos)
    --Tile(wallPosition):relocateTo(Position(32259, 31889, 10))
    Tile(wallPosition):relocateTo(wallRelocateToPosition)
    Game.createItem(1498, 1, wallPosition)
end

edit: instead of a teleporting the behavior could be like an slighly step out? like when you be pushed out because you used the door and you're standing in it
You'd have to modify this function in data/lib/core/tile.lua


specifically this line
Lua:
thing:teleportTo(toPosition)
to include the push movement
Lua:
-- creature:teleportTo(position[, pushMovement = false])
thing:teleportTo(toPosition, true)

--
Edit

Like this would be best, so you have both options.
Lua:
function Tile.relocateTo(self, toPosition, pushCreature) 
    if self:getPosition() == toPosition or not Tile(toPosition) then
        return false
    end
 
    for i = self:getThingCount() - 1, 0, -1 do
        local thing = self:getThing(i)
        if thing then
            if thing:isItem() then
                if thing:getFluidType() ~= 0 then
                    thing:remove()
                elseif ItemType(thing:getId()):isMovable() then
                    thing:moveTo(toPosition)
                end
            elseif thing:isCreature() then
                pushCreature = pushCreature or false
                thing:teleportTo(toPosition, pushCreature)
            end
        end
    end
 
    return true
end

and in your function you'd change it to
Lua:
Tile(wallPosition):relocateTo(wallRelocateToPosition, true)
 
Last edited:
You'd have to modify this function in data/lib/core/tile.lua


specifically this line
Lua:
thing:teleportTo(toPosition)
to include the push movement
Lua:
-- creature:teleportTo(position[, pushMovement = false])
thing:teleportTo(toPosition, true)

--
Edit

Like this would be best, so you have both options.
Lua:
function Tile.relocateTo(self, toPosition, pushCreature)
    if self:getPosition() == toPosition or not Tile(toPosition) then
        return false
    end
 
    for i = self:getThingCount() - 1, 0, -1 do
        local thing = self:getThing(i)
        if thing then
            if thing:isItem() then
                if thing:getFluidType() ~= 0 then
                    thing:remove()
                elseif ItemType(thing:getId()):isMovable() then
                    thing:moveTo(toPosition)
                end
            elseif thing:isCreature() then
                pushCreature = pushCreature or false
                thing:teleportTo(toPosition, pushCreature)
            end
        end
    end
 
    return true
end

and in your function you'd change it to
Lua:
Tile(wallPosition):relocateTo(wallRelocateToPosition, true)
Incredible, thank you very much
 
Back
Top