You need to trace the code to find out what is going on. Think like the computer does.
First things firsts it will find all the functions, hooks and variables not defined within a function.
So as it occurs on the most part in a chronological order, the first thing it loads is this:
Code:
local NPCID = 799999
Fine. Now it goes through each function.
It gets to here:
Code:
function Elite_Phase3(pUnit, event, player)
pUnit:SendChatMessage(14, 0, "Time to show you my real power!")
pUnit:RegisterEvent("Elite_Spell2", 120000, 1)
function Elite_Spell1(pUnit, Event)
pUnit:CastSpell(20566)
end
Now it's confused. A second function starts before the first function ends. So it should spit you out an error in console.
This needs to be fixed to look like this:
Code:
function Elite_Phase3(pUnit, event, player)
pUnit:SendChatMessage(14, 0, "Time to show you my real power!")
pUnit:RegisterEvent("Elite_Spell2", 120000, 1)
end
function Elite_Spell1(pUnit, Event)
pUnit:CastSpell(20566)
end
It finally comes to the hooks:
Code:
RegisterUnitEvent(799999, 1, "Elite_OnCombat")
RegisterUnitEvent(799999, 2, "Elite_OnLeaveCombat")
RegisterUnitEvent(799999, 4, "Elite_OnDeath")
These are fine but there was no point declaring NPCID if your not going to use it.
Now lets assume the creature enters combat first:
Code:
function Elite_OnCombat(pUnit, event, player)
Elite=pUnit
pUnit:SendChatMessage(12, 0, "Puny Mortals, do you really think you can defeat me?")
pUnit:RegisterEvent("Elite_Phase1", 1000, 1)
end
The Lua engine is already confused, what is Elite? You haven't declared it. Why are you setting this 'Elite' (which we don't know what it is) to the pUnit (which is a variable for the unit GUID).
Code:
function Elite_Phase1(pUnit, event, player)
if Elite:GetHealthPct() <= 75 then
Elite:SendChatMessage(14, 0, "I will not stand for your distractions, I will finish you!")
pUnit:RegisterEvent("Elite_Spell1", 120000, 1)
pUnit:RegisterEvent("Elite_Phase2", 1000, 1)
end
This is the next function that is triggered, and the Lua engine gets confused again. You start the function and end it - that is fine - but then you declare a if statement but don't end it. The Lua engine will treat this as a function in a function. The logic behind this is that the end you have here is ending the IF statement rather than the function. You need to add a second end like so:
Code:
function Elite_Phase1(pUnit, event, player)
if Elite:GetHealthPct() <= 75 then
Elite:SendChatMessage(14, 0, "I will not stand for your distractions, I will finish you!")
pUnit:RegisterEvent("Elite_Spell1", 120000, 1)
pUnit:RegisterEvent("Elite_Phase2", 1000, 1)
end
end
You all also need to add pUnit:RemoveEvents() after the GetHealthPct bit because otherwise it will continue doing that function even though it's changed to another phase and hence cause loads of bugs.
In phase two you are calling something that doesn't exist:
Code:
If Elite:GetHealthPct() <=30 then
Elite:SendChatMessage(14, 0, "Minions, come to my aid!")
What is Elite? You certainly haven't defined it. It will just error saying unit does not exist or a null reference.
Finally the last mistake, that won't cause a error but is bad coding practice, is this:
Code:
function Elite_Summon(pUnit, Event)
local x = Unit:GetX();
local y = Unit:GetY();
local z = Unit:GetZ();
local o = Unit:GetO();
pUnit:SpawnCreature (799998, x, y, z, o, 14 ,600000);
end
You don't need a semi-colon (;) after each line. This isn't C/Java etc where you have to end each process with a semi-colon, the Lua syntax is clever and doesn't require such methods.
This should help you understand where your going and to fix up your script. Don't not read this post as it's a wall of text (or so it appears), if you want help you have to respond to the help given first. :)