As you can see, I have a spell that hits random targets in an area, but it ignores walls and other objects that should block a spell.

Can anyone help with a solution for this?
the code uses Game.getSpectators to find the targets in the area
Here is the code of the spell, if anyone want to check it.

Can anyone help with a solution for this?
the code uses Game.getSpectators to find the targets in the area
Here is the code of the spell, if anyone want to check it.
Lua:
local config = {targetNumber = 8}
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, 97)
function onGetFormulaValues(player, skill, attack, factor)
local min = (player:getLevel() / 5) + (skill * attack * 0.04) + 11
local max = (player:getLevel() / 5) + (skill * attack * 0.08) + 21
return -min, -max
end
combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
local spell = Spell("instant")
function spell.onCastSpell(creature, variant)
local spectators = Game.getSpectators(creature:getPosition(), false, false, 5, 5, 5, 5)
local count = 0
local rep = 0
local targets = {}
local playerPos = creature:getPosition()
while count <= config.targetNumber do
rep = rep +1
local target = math.random(1, #spectators)
local pos = spectators[target]:getPosition()
local var = positionToVariant(pos)
if var and not table.contains(targets, target) and spectators[target] ~= creature then
targets[#targets +1] = target
count = count+1
combat:execute(creature, var)
var = nil
end
if rep > 70 then
count = config.targetNumber+1
end
end
r
Attachments
-
spectators wall.gif301.1 KB · Views: 1 · VirusTotal