• 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+ Cast spell front of wall.

OTcreator

Well-Known Member
Joined
Feb 14, 2022
Messages
503
Solutions
1
Reaction score
57
Hi,
Have a big problem. TFS 1.4.2.
I can use exori frigo, exevo vis hur when standing front of wall.
The hit does not go through the wall, but the spell is made which takes mana.
Shouldn't it be that the spell can't be used at all ?

When I give blockwalls=1 it doesn't change anything, when I add blocktype="Solid" then for example you can't use a spell through a rune bush.
 
Can make a custom function for that.
LUA:
function canCastInDirection(creature)
    local casterPos = creature:getPosition()
    local direction = creature:getDirection()

    local offset = Position.directionOffset[direction]
    local targetPos = casterPos + offset

    local tile = Tile(targetPos)
    if not tile or not tile:isWalkable() then
        return RETURNVALUE_NOTENOUGHROOM
    end

    return RETURNVALUE_NOERROR
end
example in a spell
LUA:
function onCastSpell(creature, var)
    local castResult = canCastInDirection(creature)
    if castResult ~= RETURNVALUE_NOERROR then
        creature:sendCancelMessage(castResult)
        return false
    end

    -- rest of spell
    return true
end
 
Can make a custom function for that.
LUA:
function canCastInDirection(creature)
    local casterPos = creature:getPosition()
    local direction = creature:getDirection()

    local offset = Position.directionOffset[direction]
    local targetPos = casterPos + offset

    local tile = Tile(targetPos)
    if not tile or not tile:isWalkable() then
        return RETURNVALUE_NOTENOUGHROOM
    end

    return RETURNVALUE_NOERROR
end
example in a spell
LUA:
function onCastSpell(creature, var)
    local castResult = canCastInDirection(creature)
    if castResult ~= RETURNVALUE_NOERROR then
        creature:sendCancelMessage(castResult)
        return false
    end

    -- rest of spell
    return true
end
And is it possible to improve this function so that, for example, when hitting: exevo gran mas flam, it does not hit places where there is no free space (not walkable) ?

UPDATE: CONSOLE LOG PROBLEM:

2025-01-01_15-08-31.781689 Lua Script Error: [Spell Interface]
2025-01-01_15-08-31.781782 data/spells/scripts/attack/energy_wave.lua:onCastSpell
2025-01-01_15-08-31.781843 getNumber(). Argument -1 has out-of-range value for t: -1.0
2025-01-01_15-08-31.781877 stack traceback:
2025-01-01_15-08-31.781908 [C]: in function '__add'
2025-01-01_15-08-31.781939 data/spells/lib/spells.lua:314: in function 'canCastInDirection'
2025-01-01_15-08-31.781970 data/spells/scripts/attack/energy_wave.lua:20: in function <data/spells/scripts/attack/energy_wave.lua:19>
 
Last edited:
And is it possible to improve this function so that, for example, when hitting: exevo gran mas flam, it does not hit places where there is no free space (not walkable) ?
List of hit positions/tiles is generated in C++.
This little Lua hack only detects wall in front of player and blocks spell cast, as it can't go thru that tile anyway (and hit monsters/players behind it).
You can't walk on some positions as player, but GM can teleport into wall/bush, also some bugged Lua scripts may teleport player into bushes etc. and we don't want them to become safe from monster spells. Getting into wall/bush is a problem, but making player immune to monster attacks is a much bigger problem.
UPDATE: CONSOLE LOG PROBLEM:
These lines are wrong:
LUA:
    local casterPos = creature:getPosition()
    local direction = creature:getDirection()

    local offset = Position.directionOffset[direction]
    local targetPos = casterPos + offset
as you cannot use negative values in Position and offset for 50% of directions is negative.
It should be (1 line in place of 4):
LUA:
    local targetPos = creature:getPosition():getNextPosition(creature:getDirection())
why: getNextPosition(direction, steps = 1) is calculated in Lua and Position.directionOffset table is defined in Lua as table with fields x,y,z, not as Positions objects, so it's never transferred to C++ and converted to Position object.
When you use local targetPos = casterPos + offset, it converts offset variable with x,y,z Lua table values into C++ Position object and it fails, as x=-1 or y=-1 makes it incompatible with C++ Position structure that allows only positive values (0+).

EDIT:
It's probably fixed in newest TFS versions by moving add, sub, concat and equals operators to Lua ( Move Position methods to Lua by ranisalt · Pull Request #4334 · otland/forgottenserver (https://github.com/otland/forgottenserver/pull/4334) ), but I did not test, if it fixes problem with negative Position.directionOffset values yet.
 
Last edited:
I understand all this, I'm just looking for some solution that will block the possibility of calling spells, for example, “Exori Frigo”, “Exevo Vis Hur” while facing the wall.

Because at the moment in TFS 1.4.2 we will perform “Exori Frigo”, no DMG will be inflicted nor the effect will be displayed on the wall , but the spell can be cast.

Xikini gave a cool trick, but there are problems.
There are things that are not walkable , but a spell can pass through them - such as stalagmite on dragons.

The simplest solution for me would be to block the ability to shoot only at walls, because theoretically such “exevo vis hur” should not hit the grid in front (because there is a wall standing there, for example), but the side areas should still be executed and hit. Unless I am wrong...
 
Xikini gave a cool trick, but there are problems.
There are things that are not walkable , but a spell can pass through them - such as stalagmite on dragons.
Can't you shot through stalagmite with SD rune? It looks like any other 'tree' item, it should allow you to shot through (ex. using SD rune).
From C++ point of view these things like 'stalagmite' are 100% the same as 'wild growth'.
Walkable (normal tile without ex. tree) and 'block solid' (wall, not ex. tree) are different things and attributes of item.
If you want to make game that works different than RL Tibia, then modify these items (make them block solid in .dat and .otb?), do not modify OTS C++/Lua code.
Because at the moment in TFS 1.4.2 we will perform “Exori Frigo”, no DMG will be inflicted nor the effect will be displayed on the wall , but the spell can be cast.
You can use attack spells without anyone getting hit, it's OK on RL Tibia. It's up to player to cast spells when there are players/monsters in range of distance spell.

If you want to block casting of range spells (waves/beams), that do not hit anyone, you have to rewrite OTS engine, as it first calculates Tiles/Positions and then calculate, if anyone at all get dmg.

I can use exori frigo, exevo vis hur when standing front of wall.
The hit does not go through the wall, but the spell is made which takes mana.
Is there anyone able to deliver RL Tibia information, if it was possible to cast wave/beam spell in front of wall at 10.x? Any movie/cam from RL tibia showing 'cant cast spell' or wasting mana by casting spell on wall?
 

Similar threads

Back
Top