auto(500)
--init start
local attackSpellOptionName = 'UeName' -- name of the attack spell widget
local isPvPOptionName = 'SafeAttacks' -- name of the pvp widget


local attackSpell = getuseroption(attackSpellOptionName)

local creatures = {"lizard high guard", "lizard dragon priest", "lizard legionnaire"}
local amountOfCreatures = getuseroption("AmountToUE")

local val = getuseroption("Avg to UE")
local hpMin = val.from
local hpMax = val.to

local players = {
enabled = getuseroption(isPvPOptionName),
distance = 8,
floorDifference = 1,
safeList = {"Bubble", "Eternal Oblivion"}
}

local sdcreatures = {
{name = 'lizard zaogun', hppc = 25},
{name = 'lizard dragon priest', hppc = 40},
{name = 'lizard legionnaire', hppc = 50},
}

-- dont change anything below this line
table.lower(players.safeList)
table.lower(creatures)
for _,j in ipairs(sdcreatures) do j.name = j.name:lower() end

local attackSpellInfo = spellinfo(attackSpell)
-- filteruseroptions(true)
--
-- function inputevents(e)
-- if e.name == attackSpellOptionName then
-- attackSpell = e.value
-- elseif e.name == isPvPOptionName then
-- players.enabled = e.value
-- end
-- end
--init end

--auto(500)
local monstersAround = 0
local playersAround = 0
AvaWalk = getuseroption("AvaWalking")
UseMaxStrike = getuseroption("UseUltimateStrike")
UseStrongStrike = getuseroption("UseStrongStrike")

local shouldUseRunes = false
if cancastspell(attackSpellInfo) and $wptsection == "Hunt" then
foreach creature m do
if m.ismonster then
if isonspellarea(m, attackSpell) and m.hppc <= hpMax and m.hppc >= hpMin and table.find(creatures, m.name:lower()) then
monstersAround = monstersAround + 1
end
elseif players.enabled and m ~= $self and m.isplayer and math.abs(m.posz - $posz) <= players.floorDifference and m.dist <= players.distance and not table.find(players.safeList, m.name:lower()) then
playersAround = playersAround + 1
end
end
listas(monstersAround)
if monstersAround >= amountOfCreatures and playersAround == 0 then
while cooldown(attackSpellInfo.words) == 0 do
shouldUseRunes = false
cast(attackSpellInfo.words)
end

else
shouldUseRunes = true
end

else
shouldUseRunes = true
end

if shouldUseRunes then
local strikeType = 'frigo'
if $vocshort == 'S' then
strikeType = 'vis'
end

local result = {amount = 0}
if (AvaWalk and not $targeting) and itemcount('avalanche rune') > 0 and $standtime < 60000 and cooldown('avalanche rune') < 1000 then
result = getarearunetile(true, "lizard high guard")

elseif ($targeting) and itemcount('avalanche rune') > 0 and $standtime < 60000 and cooldown('avalanche rune') < 1000 then
result = getarearunetile(true, unpack(creatures))
end

if (((AvaWalk and not $targeting and $wptsection == "Hunt") and result.amount >= 3) or ($targeting and result.amount >= 2)) then
pausewalking(500)
useitemon('avalanche rune', topitem(result.x,result.y,result.z), result.tile)
elseif $attacked.id > 0 and $attacked.isshootable then
local temp = table.find(sdcreatures, $attacked.name:lower(), 'name')

if (temp and $attacked.hppc > sdcreatures[temp].hppc) or $standtime >= 60000 then
useoncreature('sudden death rune', $attacked.id)
elseif $attacked.dist <= 3 and UseMaxStrike and cancastspell('exori max '..strikeType, $attacked) and (($attacked.name == "Lizard Zaogun" and $attacked.hppc < 20 and $attacked.hppc > 10) or ($attacked.name == "Lizard High Guard" and $attacked.hppc < 40 and $attacked.hppc > 15) or ($attacked.name == "Lizard Legionnaire" and $attacked.hppc < 45 and $attacked.hppc > 25)) then
cast('exori max '..strikeType)
elseif $attacked.dist <= 3 and UseStrongStrike and cancastspell('exori gran '..strikeType, $attacked) and (($attacked.hppc > 5 and $attacked.name == "Lizard High Guard" and $attacked.hppc < 50) or ($attacked.hppc > 15 and $attacked.name ~= "Lizard Zaogun" and $attacked.hppc < 40))then
cast('exori gran '..strikeType)
elseif $attacked.dist <= 3 and cancastspell('exori frigo', $attacked) then
cast('exori frigo')
end
end
end