• 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 Add blockwall check to weapon with multiple targets

Paulix

Active Member
Joined
Sep 13, 2012
Messages
129
Solutions
7
Reaction score
26
I have this weapon on my server, that hits up to 3 targets (target +2) and it is working fine, the problem is that it igore walls if the "target" is in 2x2 range,
people can attack creatures in protection zones and behind walls if in area, how do check if it can attack the secondary targets to prevent this?

Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_POISONDAMAGE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_POISON)

function onGetFormulaValues(cid, level, maglevel)

    local min = -(((((level/80)+5) * (maglevel/2.2)) * 1.7) * ((getExtra(cid, EXTRA_DAMAGE)/6)+1))
    local max = -(((((level/80)+5) * (maglevel/2.2)) * 2.1) * ((getExtra(cid, EXTRA_DAMAGE)/6)+1))

    return min, max
end

setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onUseWeapon(cid, var)
local blind = getCreatureStorage(cid, 50005)

    if (blind*20) >= math.random(1,100) then
        doSendAnimatedText(getPlayerPosition(cid), "Miss!", COLOR_GREY)
    else
        local c = getSpectators(getCreaturePosition(var.number), 2, 2)
        local v = 1
        for i=1,#c do
            if v <= 2 then
                if isPlayer(var.number) then
                    if c[i] ~= cid and c[i] ~= var.number then
                        c[i] = {number = c[i], type = 1}
                        doCombat(cid, combat, c[i])
                        v = v+1
                    end
                else
                    if c[i] ~= cid and c[i] ~= var.number and not isPlayer(c[i]) then
                        c[i] = {number = c[i], type = 1}
                        doCombat(cid, combat, c[i])
                        v = v+1
                    end
                end
            end
        end
        doCombat(cid, combat, var)
    end
    return 1
end
 
0.X TFS
Code:
isSightClear(fromPos, toPos, floorCheck)

solution, checking pz, house and walls:
Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_POISONDAMAGE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_POISON)

function onGetFormulaValues(cid, level, maglevel)

    local min = -(((((level/80)+5) * (maglevel/2.2)) * 1.7) * ((getExtra(cid, EXTRA_DAMAGE)/6)+1))
    local max = -(((((level/80)+5) * (maglevel/2.2)) * 2.1) * ((getExtra(cid, EXTRA_DAMAGE)/6)+1))

    return min, max
end

setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function canAttack(cid,var)
local cpos = getCreaturePosition(cid)
local vpos = getCreaturePosition(var)
    if cid == var then
        return false
    end
    if not isSightClear(cpos, vpos, true) then
        return false
    end
    if getHouseFromPos(vpos) or getTilePzInfo(vpos) then
        return false
    end
    return true
end

function onUseWeapon(cid, var)
local blind = getCreatureStorage(cid, 50005)

    if (blind*20) >= math.random(1,100) then
        doSendAnimatedText(getPlayerPosition(cid), "Miss!", COLOR_GREY)
    else
        local c = getSpectators(getCreaturePosition(var.number), 2, 2)
        local v = 1
        for i=1,#c do
            if v <= 2 and c[i] ~= var.number and canAttack(cid,c[i]) then
                c[i] = {number = c[i], type = 1}
                if isPlayer(var.number) then
                    doCombat(cid, combat, c[i])
                    v = v+1
                else
                    if not isPlayer(c[i].number) then
                        doCombat(cid, combat, c[i])
                        v = v+1
                    end
                end
            end
        end
        doCombat(cid, combat, var)
    end
    return 1
end
 
Last edited:
Maybe?
Code:
getTilePzInfo()
getTileZoneInfo()



I know i use functions like this on TFS 1.X
Code:
tile:hasFlag(flag)
tile:hasProperty(property[, item]) 
tile:getHouse()
 
Back
Top