Fixed and tested.
lua code:
local Spells = {
{words = 'exori flam', hppc = 0, range = 3, mana = 20, count = 3, list = {'rat', 'cave rat', 'bat', 'corym charlatan'}
}
}
local PvPRadiusSafety = 3
local MonsterRange = 8
function SafeRadius(radius)
for n, c in Creature.iPlayers() do
if c:DistanceFromSelf() < radius then
return true
end
end
end
function MonstersAround(list, radius)
local k = 0
for name, creature in Creature.iMonsters({distancefromself = {lt, radius}}) do
if (list ~= nil) then
if table.contains(list, name:lower()) then
k = k + 1
end
else
k = k + 1
end
end
return k
end
BattleMessageProxy.OnReceive('shooter', function(proxy, message)
local givendmg = string.match(message, "(.+) due to your attack.")
if (givendmg) then
local id = Self.TargetID()
if (id ~= 0) then
local mp = Self.Mana()
local c = Creature.New(id)
for i = 1, #Spells do
if table.contains(Spells[i].list, c:Name():lower()) then
if MonstersAround(Spells[i].list, MonsterRange) >= Spells[i].count then
if Self.CanCastSpell(Spells[i].words) and mp > Spells[i].mana and c:HealthPercent() >= Spells[i].hppc then
local isUnsafe = SafeRadius(PvPRadiusSafety)
if not (isUnsafe) and c:DistanceFromSelf() <= Spells[i].range then
if c:isTarget() then
Self.Cast(Spells[i].words, Spells[i].mana)
end
end
break
end
end
end
end
end
end
end)