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

Solved Walking through creatures

Moj mistrz

Monster Creator
Joined
Feb 1, 2008
Messages
932
Solutions
10
Reaction score
295
Location
Poland
Hi guys, I need help with this script which is based on script from this thread. I tried to remake it for monster spell(so monster can go through players and other monsters, but no blocking objects like walls, bushes etc.), but I failed. This is where I get so far. I wanted to make it for TFS 1.2.
Code:
function onCastSpell(creature, var)
    local direction = creature:getDirection()
    local nextPosition = creature:getPosition()
    if Tile(nextPosition):queryAdd(creature) == RETURNVALUE_NOERROR then
        nextPosition:getNextPosition(direction)
       
        creature:teleportTo(nextPosition, true)
    end
    return true
end
Actually it works only for players + it checks if item is blockable only when you are already teleported on it :/, it wouldn't be so bad, but it still don't work for monsters, dunno why. It only works when I remove queryTileAddThing line, but it gives monster opportunity to walk on walls etc. Would be also good if it pushes creatures on its way(just like giant spider pushes minotaur for example).
Thanks for any help :).
 
use isMonster()
I'm not sure but var might be the target aka monster?
 
Last edited:
I tried using isMonster(), but it dont change anything, still it dont work with that line.
Code:
if Tile(nextPosition):queryAdd(creature) == RETURNVALUE_NOERROR then
Like it is ignoring this line or this dont work for monsters :/. This is only working only if I remove it, but it still passes walls.
 
It didn't work properly because you added Tile.queryAdd above Position.getNextPosition.
Code:
function onCastSpell(creature, var)
    local direction = creature:getDirection()
    local nextPosition = creature:getPosition()
    nextPosition:getNextPosition(direction)

    local tile = Tile(nextPosition)
    if tile and tile:queryAdd(creature) == RETURNVALUE_NOERROR then
        creature:teleportTo(nextPosition, true)
    end
    return true
end
 
It didn't work properly because you added Tile.queryAdd above Position.getNextPosition.
Code:
function onCastSpell(creature, var)
    local direction = creature:getDirection()
    local nextPosition = creature:getPosition()
    nextPosition:getNextPosition(direction)

    local tile = Tile(nextPosition)
    if tile and tile:queryAdd(creature) == RETURNVALUE_NOERROR then
        creature:teleportTo(nextPosition, true)
    end
    return true
end
Still don't work for monsters(for players works), so they don't pass other monsters/players. :/
 
Last edited:
Monsters won't pass players, or other monsters (unless they're pushable). So if Tile.queryAdd is not enough for you, then you might want to create a function based on isWalkable, and add some conditions of your own.

You can probably write the pushing part in Lua with the help of this.
 
Monsters won't pass players, or other monsters (unless they're pushable). So if Tile.queryAdd is not enough for you, then you might want to create a function based on isWalkable, and add some conditions of your own.

You can probably write the pushing part in Lua with the help of this.
Ok, so if it won't pass creatures, can it just push(teleport) creatures on its way by 1sqm in random directions, just like pushable flag works?
 
Back
Top