I will show you a fairly easy way of creating your own bossfight. This guide will go over the basics. If this thread gets good reviews n' replies, ill consider making a guide for advanced LUA boss fights.
Note: This is a guide to create the LUA script. You must already have a creature/npc you wish to attach the script to!
Open up notepad and start a new document.
Since this is a basic fight, we will do a 2 phase fight.
First, lets begin to make our first phase. Lets say we want our creature to enter this phase at 70% hp, we will start by doing this:
function Boss_Phase1(Unit, event)
if Unit:GetHealthPct() < 70 then
end
end
Now you have constructed the checking portion. Once the creature enters Hp lower than 70%, it will do everything in between 'if' and 'end'.
This is all fine and dandy, but we want to make him blast a shadow nova! So lets add in the cast spell script.
function Boss_Phase1(Unit, event)
if Unit:GetHealthPct() < 70 then
Unit:CastSpell(33846)
end
end
Now, once he enters this phase - he will cast the spell Shadow Nova (Id: 33846)
But now we want him to cast the spell every 10 seconds. So lets make a new function. It will be formatted like such:
function Boss_Nova(Unit)
Unit:CastSpell(33846)
Unit:SendChatMessage(12, 0, "DIE!")
end
Great, if this function is called, he will cast a shadow nova and yell the words "DIE". But now we need to tie this function to the main phase. Since time is in miliseconds, when you see the 10000, it really means 10 seconds. So lets add this in:
function Boss_Phase1(Unit, event)
if Unit:GetHealthPct() < 70 then
Unit:CastSpell(33846)
Unit:RegisterEvent("Boss_Nova",10000, 0)
end
end
Great, your first phase is complete! Onto the next one. We will again, build it the same way - but add in a new line. And this time, we will make the health percent at 50.
function Boss_Phase2(Unit, event)
if Unit:GetHealthPct() < 50 then
Unit:RemoveEvents()
end
end
See what i did there? That RemoveEvents line will de-register the 10 second shadow nova function, so he will no longer do it in this phase. In this phase, we also want this boss to yell, and enrage. So add this in:
function Boss_Phase2(Unit, event)
if Unit:GetHealthPct() < 50 then
Unit:RemoveEvents()
Unit:CastSpell(23537)
Unit:SendChatMessage(12, 0, "Omg no wai!")
end
end
So now, once the Boss reaches 50% hp, he will shout - enrage, and remove the shadow nova functions. This is great and all, but we need to tie this to the first phase in order for it to work So add in the new line to the first phase:
function Boss_Phase1(Unit, event)
if Unit:GetHealthPct() < 70 then
Unit:CastSpell(33846)
Unit:RegisterEvent("Boss_Nova",10000, 0)
Unit:RegisterEvent("Boss_Phase2",1000, 0)
end
end
Now, during the first boss fight, the script will periodically (every 1 second, 1000 miliseconds) check to see if phase 2 is ready. So when his hp reaches 50%, he will switch phases.
We are almost done! We just need to, again, register the first phase. We will do this with the onCombat function. So add in a new function as such:
function Boss_OnCombat(Unit, event)
Unit:RegisterEvent("Boss_Phase1",1000, 0)
end
RegisterUnitEvent(ENTRY ID, 1, "Boss_OnCombat")
All you need to do now, is change ENTRY ID to the ID of your boss!
Save this as a .lua and put it in your /scripts/ folder!
I hope you all enjoyed this guide, and continue to practice your LUA scripting!
Here is an example of a complete Bossfight.lua
Code:
function phase_1(pUnit, Event)
if pUnit:GetHealthPct() < 70 then
pUnit:RemoveEvents();
pUnit:FullCastSpell(16033)
pUnit:RegisterEvent("phase_2",1000, 0)
end
end
function phase_2(pUnit, Event)
if pUnit:GetHealthPct() < 50 then
pUnit:RemoveEvents();
pUnit:FullCastSpell(33452)
pUnit:RegisterEvent("phase_3",1000, 0)
end
end
function phase_3(pUnit, Event)
if pUnit:GetHealthPct() < 30 then
pUnit:RemoveEvents();
pUnit:FullCastSpell(34807)
end
end
function boss_start(pUnit, Event)
pUnit:RegisterEvent("phase_1",1000, 0)
end
RegisterUnitEvent(ENTRYID, 1, "boss_start")