• 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+ Problem with blocking shots.

jacken9996

New Member
Joined
Aug 9, 2023
Messages
3
Reaction score
0
Hi guys. I have a problem with my multi-target spell. It's works almost like i want, but walls are not blocking shots...

1692010710858.png

Engine: TFS 1.4.2

viper_star.lua:

Lua:
local distanceEffect = 20
local effect = CONST_ME_HITAREA
local damageType = COMBAT_PHYSICALDAMAGE

local function combatExecute(cid, variant)

local player = Player(cid)
local pos = player:getPosition()
local screen = Game.getSpectators(pos, false, false)

local lvl = player:getLevel()
local mlvl = player:getMagicLevel()
local minDmg = ((lvl / 5) + (mlvl * 5) + 25)* 25
local maxDmg = ((lvl / 5) + (mlvl * 6.2) + 45)* 25
 
for i = 1, #screen do
    local tile = Tile(screen[i]:getPosition()):hasFlag(TILESTATE_PROTECTIONZONE)
    if tile then
        return true
    end
    if screen[i]:isMonster() then
        local posAll = screen[i]:getPosition()
        pos:sendDistanceEffect(posAll, distanceEffect)
        doAreaCombatHealth(cid, damageType, posAll, nil, -minDmg, -maxDmg, effect)
        end
    end
end


function onCastSpell(creature, variant)
    combatExecute(creature:getId(), variant)
    return true
end

spells.xml:

XML:
<instant group="attack" spellid="225" name="Viper Stars" words="viper star" level="25000" mana="15000" premium="1" selftarget="1" cooldown="1500" groupcooldown="1500" needlearn="0" blockwalls="1" script="attack/custom/RP/viper_stars.lua">
        <vocation name="Paladin" />
        <vocation name="Royal Paladin" />
    </instant>
 
Were you testing the spell with the GM account?


Test with a player account. I made some changes to your spell code.
Lua:
local distanceEffect = 20
local effect = CONST_ME_HITAREA
local damageType = COMBAT_PHYSICALDAMAGE

local function combatExecute(cid, variant)
    local player = Player(cid)
    local pos = player:getPosition()
    local screen = Game.getSpectators(pos, false, false)

    local lvl = player:getLevel()
    local mlvl = player:getMagicLevel()
    local minDmg = ((lvl / 5) + (mlvl * 5) + 25) * 25
    local maxDmg = ((lvl / 5) + (mlvl * 6.2) + 45) * 25

    for i = 1, #screen do
        local target = screen[i]
        local posAll = target:getPosition()
        
      
        if pos:isPathable(posAll) then
            if target:isMonster() then
                pos:sendDistanceEffect(posAll, distanceEffect)
                doAreaCombatHealth(cid, damageType, posAll, nil, -minDmg, -maxDmg, effect)
            end
        end
    end
end

function onCastSpell(creature, variant)
    combatExecute(creature:getId(), variant)
    return true
end
 
I tested on a normal player.

Error :/

Lua Script Error: [Spell Interface]
data/spells/scripts/attack/custom/test_spell.lua:eek:nCastSpell
data/spells/scripts/attack/custom/test_spell.lua:20: attempt to call method 'isPathable' (a nil value)
stack traceback:
[C]: in function 'isPathable'
data/spells/scripts/attack/custom/test_spell.lua:20: in function 'combatExecute'
data/spells/scripts/attack/custom/test_spell.lua:30: in function <data/spells/scripts/attack/custom/viper_stars.lua:29>
 
Lua:
local distanceEffect = 20
local effect = CONST_ME_HITAREA
local damageType = COMBAT_PHYSICALDAMAGE

local function isTileBlocked(tile)
    local tileGround = tile:getGround()
    return tileGround and tileGround:hasProperty(CONST_PROP_BLOCKSOLID)
end

local function combatExecute(cid, variant)
    local player = Player(cid)
    if not player then
        return
    end
    
    local pos = player:getPosition()
    if not pos then
        return
    end
    
    local screen = Game.getSpectators(pos, false, false)

    local lvl = player:getLevel()
    local mlvl = player:getMagicLevel()
    local minDmg = ((lvl / 5) + (mlvl * 5) + 25) * 25
    local maxDmg = ((lvl / 5) + (mlvl * 6.2) + 45) * 25

    for i = 1, #screen do
        local target = screen[i]
        if target:isMonster() then
            local posAll = target:getPosition()
            local targetTile = Tile(posAll)
            
            -- Check if the target tile is blocked by a wall
            if isTileBlocked(targetTile) then
              
            else
                pos:sendDistanceEffect(posAll, distanceEffect)
                doAreaCombatHealth(cid, damageType, posAll, nil, -minDmg, -maxDmg, effect)
            end
        end
    end
end

function onCastSpell(creature, variant)
    combatExecute(creature:getId(), variant)
    return true
end
 
Spell is working but still with the same problem. I have no idea why it's not working correctly...
Post automatically merged:

Use item attribute in items.xml like "blockProjectiles"? Im not sure what is correct name
Its spell, not a item, but i did what you wrote. Still no change.
 
Last edited:
To actually check if you can attack something, you must validade a few things, here is a function I made that I use on my server for those purposes...

Lua:
function canAttack(cid,var)
  cid = Creature(cid)
  var = Creature(var)

  if cid == var then
    return false
  end

  local creaturePosition = cid:getPosition() or {}
  local targetPosition = var:getPosition() or {}

  if cid:hasSecureMode() and var:isPlayer() then
    return false
  end

  if not Position(creaturePosition):isSightClear(targetPosition, true) then
    return false
  end

  local tile_target = Tile(targetPosition)

  if tile_target:getHouse() or tile_target:hasFlag(TILESTATE_PROTECTIONZONE) then
    return false
  end

  return true
end

you could just add it to your libs and call canAttack on ur script, or just add it locally
you might want to add to this part of the script

Code:
if screen[i]:isMonster() then
 
Back
Top