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

Lua Multi target weapon bug

mRefaat

Marketing and Coding
Joined
Jan 18, 2014
Messages
854
Solutions
3
Reaction score
141
Location
Egypt
Hello

I found bug in this script
if you attack a player and there is another one next to him but blocked by a wall, the wand still can atk him.
any help with that?


Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 0)
setCombatParam(combat, COMBAT_PARAM_BLOCKSHIELD, 0)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HOLYDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HOLYDAMAGE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_HOLY)
setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, -0.2, -25, -0.2, -3)
 
local manaNeededPerTarget = 20
local hitExtraTargets = 2 -- number of extra targets, so it should attack our target + X other monsters/players
local hitExtraTargetsInRange = 2 -- distance to 'extra target' from our target
 
 
function onUseWeapon(cid, var)
    local ret = doCombat(cid, combat, var)
    if(ret == LUA_ERROR) then
        return LUA_ERROR
    end
    local manaSpent = manaNeededPerTarget
    local target = variantToNumber(var)
    local hitplayers = false
    if(target ~= 0) then
        if(isPlayer(target)) then
            hitplayers = true
        end
        local otherTargets = getSpectators(getCreaturePosition(target), hitExtraTargetsInRange, hitExtraTargetsInRange, false)
        if(#otherTargets > 0) then
            local i = 1
            while(i ~= #otherTargets) do
                local pid = otherTargets[i]
                if(isNpc(pid) or pid == cid or pid == target or (isPlayer(pid) and (not hitplayers or getTileInfo(getCreaturePosition(pid)).protection))) then
                    table.remove(otherTargets, i)
                else
                    i = i + 1
                end
            end
        end
        for i = 1, hitExtraTargets do
            if(#otherTargets > 0 and getCreatureMana(cid) >= manaSpent + manaNeededPerTarget) then   
                local randomId = math.random(1, #otherTargets)
                local nowHit = otherTargets[randomId]
                table.remove(otherTargets, randomId)
                ret = doCombat(cid, combat, numberToVariant(nowHit))
                if(ret ~= LUA_ERROR) then
                    manaSpent = manaSpent + manaNeededPerTarget
                end
            else
                break
            end
        end
    end
    doPlayerAddSpentMana(cid, manaSpent)
    doCreatureAddMana(cid, -manaSpent)
    return true
end
 
Back
Top