Originally Posted by
warlock2000
Hi, quick question for the knowledgeable guys. Here's a piece of code I've written for a Shadowburn function with Havoc up. It works perfectly for its designed function so far in raids.
The weird thing is, if I'm running around Shrine or in a raid instance and do not have a target, I get huge LUA error spam. The moment I target any player or Npc, the spam stops.
Code:
local Targethealth = 100*UnitHealth("target")/UnitHealthMax("target")
local Havoc,_,_,Havocstacks = UnitBuffID("player",80240)
local TargetID = tonumber(UnitGUID("target"):sub(6,10),16)
----------------------------------------------------------------------------
if UnitAffectingCombat("player")
and UnitExists("target") ~= nil then
if TargetID == 73195 -- Kor'kron Jailer
or TargetID == 71720 -- Ice Tomb
or TargetID == 71979 -- Kor'kron Warbringer
or TargetID == 71983 -- Farseer Wolf Rider
or TargetID == 72154 -- Desecrated Weapon
or TargetID == 72198 -- Empowered Desecrated Weapon
or TargetID == 72272 then -- Minion of Y'Shaarj
if IsPlayerSpell(17877) == true
and PQR_SpellAvailable(17877) == true
and IsSpellInRange(GetSpellInfo(17877),"target") == 1
and Havoc ~= nil and Havocstacks >= 1
and UnitPower("player",14) >= 1
and Targethealth <= 20 then
CastSpellByName(GetSpellInfo(17877),"target")
LASTCAST = "Shadowburn"
return true
end
end
end
Any ideas?!?
the lua errors stem prob from you math not getting a value or its returning a nil.
i've made some mods to your code however, take them as you see them or change them up again.
PHP Code:
local sTargets = { 73195, 71720, 71979, 71983, 72154, 72198, 72272 } --add your mobs here
local Havoc,_,_,Havocstacks = UnitBuffID("player",80240)
local Targethealth = 999 --using this to prevent nil math errors
if UnitExits("target") then Targethealth = 100*UnitHealth("target")/UnitHealthMax("target") else Targethealth = 999 end
--above keeps Targethealth as a local for ya
function isStarget() --pretty much this is ments specialUnit function
if UnitExists("target") then
local TargetID = tonumber(UnitGUID("target"):sub(6,10),16)
for i=1, #sTargets do
if sTargets[i] == TargetID then
return true
end
return false
end
else
return false
end
end
--the core
if UnitAffectingCombat("player") and UnitExists("target") then
if IsPlayerSpell(17877)
and PQR_SpellAvailable(17877)
and IsSpellInRange(GetSpellInfo(17877),"target") == 1
and Havoc ~= nil and Havocstacks >= 1
and UnitPower("player",14) >= 1
and Targethealth <= 20
and isStarget() --the new function to check npcids
then
CastSpellByName(GetSpellInfo(17877),"target")
LASTCAST = "Shadowburn"
return true
end
end