SPELLS

[color="Alright! The part who shows what sort of boss it is, the part who shows how hard the boss is, the part shows how great the boss is!



Spells have everything to do with what type of boss it is and how hard it is. Without spells, the boss is nothing, but you know. Let me show you some ways how to have spells.


Code:
CastSpell()
FullCastSpell()
CastSpellOnTarget()
FullCastSpellOnTarget()
have showed you in the first part how to find an ID of a spell. So, I don't need to explain that anymore. And you know how CastSpell() works so I'm going to skip that too.

FullCastSpell(), this means that he casts an Area of Efect spell with casttime or a spell on himself.
Example:


Code:
function Boss_Spell(pUnit, Event)
pUnit:FullCastSpell(SpellID)
end
CastSpellOnTarget(), this is that he casts a spell on a target. You need to have the ID in the brackets ofcourse. But there is another thing you need to have on it, I'll red it up what I'm changing

Code:
function Boss_Spell(pUnit, Event)
pUnit:CastSpellOnTarget(SpellID, pUnit:GetMainTank())
end
As you can see there is something new added. "pUnit:GetMainTank()". This means that he will target the main tank (the one with the highest treath). There are more targets he can target. I will show you which you can target more and how to use them.

Code:
pUnit:GetMainTank() -- He will target a player with the highest treath
pUnit:GetRandomPlayer(0) -- He will target a random player
pUnit:GetRandomPlayer(1) -- He will target a player in short range
pUnit:GetRandomPlayer(2) -- He will target a player in mid range
pUnit:GetRandomPlayer(3) -- He will target a player in longe range
pUnit:GetRandomPlayer(4) -- He will target a player with mana
pUnit:GetRandomPlayer(5) -- He will target a player with rage
pUnit:GetRandomPlayer(6) -- He will target a player with energy
pUnit:GetRandomPlayer(7) -- He will target a player who is not the main tank
If you want to let him target someone else, just remove "pUnit:GetMainTank()" and put another target in it, by example someone in short range: "pUnit:GetRandomPlayer(1)".

FullCastSpellOnTarget(), this is the same as CastSpellOnTarget() but this is now with casttime, looks like the same as CastSpell() and FullCastSpell(). You just need to use the same format as you did with CastSpellOnTarget().

Alright, now you know how to set the spells in an event, I'm going to show now how to register them.

Registering the spells has much to do with timing. I can't explain it really good in words now, so let me show an example. I will be using the OnCombat phase.


Code:
function Boss_OnCombat(pUnit, Event)
pUnit:SendChatMessage(14, 0, "Welcome to my lair!")
pUnit:RegisterEvent("Boss_Spell", 5000, 0)
end

function Boss_Spell(pUnit, Event)
pUnit:FullCastSpellOnTarget(SpellID, pUnit:GetMainTank())
end
I will be explaining this step by step:

pUnit:RegisterEvent, this will register the event "Boss_Spell". Without registering it, then it will not work.

("Boss_Spell", this is the name of the event what the boss registers.

, 5000, 0), Now, the boss will register the function every 5000 miliseconds so, every 5 seconds. 1000 miliseconds = 1 second. The 0 means how many time it registers. The 0 here means that it registers every 5 seconds forever. You can replace the 0 by another number, by example 2. Then it will register only 2 times so he casts the spell 2 times and not forever.

function Boss_Spell(pUnit, Event)
pUnit:FullCastSpellOnTarget(SpellID, pUnit:GetMainTank())
end,
this is the event of a spell. As you can see, it contains 3 simple lines. The function, the spell and the end. This event looks very much on the oncombat phase. Most events do look like eachother. But it is just about what they are for. I named my function "Boss_Spell" because it's simple to understand in this tutorial. If you are making your own scripts, I recommend to not use Boss_Spell1 or something. Because when you are making more scripts, there could be a script interferne. This means that it will use the script of another script and your script for the boss in one. Use the name of your NPC and the name of your spell, like "KelThuzad_FrostBolt" but this could be simple way "Kel_FrostBolt" as long as you have the same name as the name in the registering part.

Now you should know:

How to make an event with a spell
How to register the event
How to lookup the spell
How to make it target someone else

Lets move on the to next part of our journey to Lua knowledge!


** Next part " Phases" **