• 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 0.X spell attacking all target creatures

vexler222

Active Member
Joined
Apr 22, 2012
Messages
714
Solutions
15
Reaction score
46
How to create that spell? Its "UE" but attacking all target creatures.
 
In Tibia you can only have one target selected.
Or you mean all targets on the screen without effect in area (effect only on square with opponent)?
 
i mean that:

ezgif.com-video-to-gif.gif
 
Lua:
function onCastSpell(cid, var)
    local formula = {
        min = (getPlayerLevel(cid)*7.5 + getPlayerMagLevel(cid)*8.5 + 60),
        max = (getPlayerLevel(cid)*8.5 + getPlayerMagLevel(cid)*9.5 + 120),
    } 
 
    local pos, creatures = getThingPos(cid), {}

    for x = pos.x - 7, pos.x + 7 do
        for y = pos.y - 5, pos.y + 5 do
            local v = getTopCreature({x=x, y=y, z=pos.z}).uid
            if isPlayer(v) or isMonster(v) and v ~= cid then
                if isSightClear(getThingPos(cid), getThingPos(v), false) then
                    table.insert(creatures, v)
                end
            end
        end
    end

    if #creatures > 0 then
        for _, c in ipairs(creatures) do
            if isCreature(c) then
                doTargetCombatHealth(cid, c, COMBAT_ENERGYDAMAGE, - formula.min, - formula.max, 101)
            end
        end
        return true
    end
    doSendMagicEffect(getCreaturePosition(cid), 2)
    doPlayerSendCancel(cid, 'There isn\'t monsters or players near you or any creature isn\'t sight clear.')
    return false
end

If you want the shoot effect you should add doSendDistanceEffect under doSendMagicEffect.
I made it without the distance effect.
 
Lua:
function onCastSpell(cid, var)
    local formula = {
        min = (getPlayerLevel(cid)*7.5 + getPlayerMagLevel(cid)*8.5 + 60),
        max = (getPlayerLevel(cid)*8.5 + getPlayerMagLevel(cid)*9.5 + 120),
    }
 
    local pos, creatures = getThingPos(cid), {}

    for x = pos.x - 7, pos.x + 7 do
        for y = pos.y - 5, pos.y + 5 do
            local v = getTopCreature({x=x, y=y, z=pos.z}).uid
            if isPlayer(v) or isMonster(v) and v ~= cid then
                if isSightClear(getThingPos(cid), getThingPos(v), false) then
                    table.insert(creatures, v)
                end
            end
        end
    end

    if #creatures > 0 then
        for _, c in ipairs(creatures) do
            if isCreature(c) then
                doTargetCombatHealth(cid, c, COMBAT_ENERGYDAMAGE, - formula.min, - formula.max, 101)
            end
        end
        return true
    end
    doSendMagicEffect(getCreaturePosition(cid), 2)
    doPlayerSendCancel(cid, 'There isn\'t monsters or players near you or any creature isn\'t sight clear.')
    return false
end

If you want the shoot effect you should add doSendDistanceEffect under doSendMagicEffect.
I made it without the distance effect.
better code to get creatures (instead of manually iterating the area):
Lua:
local creatures = {}
for _, id in pairs(getSpectators(getCreaturePosition(cid), 7, 5, false) or {}) do
    if id ~= cid then
        creatures[#creatures+ 1] = id
    end
end
 
Lua:
function onCastSpell(cid, var)
    local formula = {
        min = (getPlayerLevel(cid)*7.5 + getPlayerMagLevel(cid)*8.5 + 60),
        max = (getPlayerLevel(cid)*8.5 + getPlayerMagLevel(cid)*9.5 + 120),
    }
 
    local pos, creatures = getThingPos(cid), {}

    for x = pos.x - 7, pos.x + 7 do
        for y = pos.y - 5, pos.y + 5 do
            local v = getTopCreature({x=x, y=y, z=pos.z}).uid
            if isPlayer(v) or isMonster(v) and v ~= cid then
                if isSightClear(getThingPos(cid), getThingPos(v), false) then
                    table.insert(creatures, v)
                end
            end
        end
    end

    if #creatures > 0 then
        for _, c in ipairs(creatures) do
            if isCreature(c) then
                doTargetCombatHealth(cid, c, COMBAT_ENERGYDAMAGE, - formula.min, - formula.max, 101)
            end
        end
        return true
    end
    doSendMagicEffect(getCreaturePosition(cid), 2)
    doPlayerSendCancel(cid, 'There isn\'t monsters or players near you or any creature isn\'t sight clear.')
    return false
end

If you want the shoot effect you should add doSendDistanceEffect under doSendMagicEffect.
I made it without the distance effect.

But how? If i use your script i dont saw magiceffect, i add distance effect bot it not work too :(

Code:
function onCastSpell(cid, var)
    local formula = {
        min = (getPlayerLevel(cid)*7.5 + getPlayerMagLevel(cid)*8.5 + 60),
        max = (getPlayerLevel(cid)*8.5 + getPlayerMagLevel(cid)*9.5 + 120),
    }

    local pos, creatures = getThingPos(cid), {}

    for x = pos.x - 7, pos.x + 7 do
        for y = pos.y - 5, pos.y + 5 do
            local v = getTopCreature({x=x, y=y, z=pos.z}).uid
            if isPlayer(v) or isMonster(v) and v ~= cid then
                if isSightClear(getThingPos(cid), getThingPos(v), false) then
                    table.insert(creatures, v)
                end
            end
        end
    end

    if #creatures > 0 then
        for _, c in ipairs(creatures) do
            if isCreature(c) then
                doTargetCombatHealth(cid, c, COMBAT_PHYSICALDAMAGE, - formula.min, - formula.max, 101)
            end
        end
        return true
    end
                        doSendMagicEffect(getCreaturePosition(cid), 3)
                    doSendDistanceEffect(getCreaturePosition(cid), 3)
    doPlayerSendCancel(cid, 'There isn\'t monsters or players near you or any creature isn\'t sight clear.')
    return false
end
 
Code:
doSendDistanceShoot(frompos, topos, type[, player])
How can i use this to send distance effect to all targeted creatures? tried creatures:getPosition() but didnt work...
Also, how can I set a limit to 3 targets, including the "main" target (not all on screen)?
 
Back
Top Bottom