PART 1: BASIC START
Ok, for starters every function will start with this:
Code:
Code:
function UnitName_Event/Function (Unit, Event)
and end with
Code:
So for example
Code:
Code:
function test_OnCombat (Unit, Event)
end
Easy? It should be!
PART 2: TEXT/TALKING
Ok, so you have an npc and you really want it to yell out something when it enters combat or something? Well thats easy! All you have to do is add this to our script:
Code:
Code:
Unit:SendChatMessage (type, language,"some text")
The type is if the npc will say, yell or whisper the text:
Code:
Code:
say: 11
yell: 12
whisper: 13
The language can be
Code:
Code:
0 = UNIVERSAL <= The most used (all languages)
1 = ORCISH
2 = DARNASSIAN
3 = TAUREN
6 = DWARVISH
7 = COMMON
8 = DEMONIC
9 = TITAN
10 = THELASSIAN
11 = DRAGONIC
12 = KALIMAG
13 = GNOMISH
14 = TROLL
33 = GUTTERSPEAK
35 = DRAENEI
And now just insert the text you want. So now are script should look like this:
Code:
Code:
function test_OnCombat (Unit, Event)
Unit:SendChatMessage(12, 0, "Die all!")
end
Of couse with your own type, language and text.
PART 3: MAKING THE NPC CAST A SPELL (NOT AN AOE OR BUFF)
Ok so now you want the fight to get interesting by adding a spell? Easy just add this:
Code:
Code:
Unit:RegisterEvent("nameofthefunction", timeinmiliseconds, howmanytimes)
The name of the function will be:
Code:
So now we should have something like mine:
Code:
Code:
function Test_OnCombat
Unit:SendChatMessage (12, 0, "Die all!")
Unit:RegisterEvent ("Test_ShadowBolt", 10000, 10)
end
Now we need to make another function so go 2 lines down under the end and put this:
Code:
Code:
function NpcName_SpellName (pUnit, Event)
pUnit:CastSpellOnTarget(spellid, pUnit:GetInfo)
The get info can be:
Code:
Code:
- GetRandomPlayer(0) = Random Player
- GetRandomPlayer(1) = Random in Short-Range
- GetRandomPlayer(2) = Random in Mid-Range
- GetRandomPlayer(3) = Random in Long-Range
- GetRandomPlayer(4) = Random with Mana
- GetRandomPlayer(5) = Random with Rage
- GetRandomPlayer(6) = Random With Energy
- GetRandomPlayer(7) = Random NOT Main-Tank
- GetMainTank()
- GetClosestPlayer()
Code:
Code:
function Test_OnCombat
Unit:SendChatMessage (12, 0, "Die all!")
Unit:RegisterEvent ("Test_ShadowBolt", 10000, 10)
end
Code:
function Test_ShadowBolt (pUnit, Event)
pUnit:CastSpellOnTarget (11661, pUnit:GetRandomPlayer(0))
And thats it for spells that aren't AOE or a buff
PART 3.5: MAKING AN NPC CAST AN AOE OR A BUFF
Very very simple. Just do what you did in part 3 although when you reach the part which is:
Code:
Code:
function Test_ShadowBolt (pUnit, Event)
pUnit:FullCastSpellOnTarget (11661, pUnit:GetRandomPlayer(0))
Just delete the
Code:
and the
Code:
Code:
pUnit:GetRandomPlayer(0)) or whatever you put there
PART 4: CHECK METHOD
At first this may seem a bit complex but after a few times you should get it right. Its called the check method. The check method is used to make the npc check its health or mana % every so often and then do something. So lets start by puting this into your script:
Code:
Code:
function NpcName_Check (pUnit, Event)
Now if you want it to check its health % then put:
Code:
Code:
if pUnit:GetHealthPct()
or for mana
Code:
Code:
if pUnit:GetManaPct()
for this I will be using health. So I want it to check to see if the npc's health % is above 50 so I will put this in:
Code:
So for me it will now look like this:
Code:
Code:
function Test_Check (pUnit, Event)
if pUnit:GetHealthPct() < 50 then
Now lets add a spell and some text. To add a spell or text just put this
Code:
Code:
pUnit:SendChatMessage (type, language,"some text"
and for a spell just put
Code:
Code:
pUnit:CastSpellOnTarget(spellid, pUnit:GetInfo)
Just like before.
Now if you want to have more than one check function than you need the have:
Code:
and for the second would be:
Code:
and so on. Now you need to register it under OnCombat. So go back to your OnCombat function and at the end (before the word end) put:
Code:
Code:
Unit:RegisterEvent("NpcName_Check", timeinmiliseconds, howmanytimes)
Don't forget to register it again if you have more than one.
At the moment my script looks like this:
Code:
Code:
function Test_CheckA (pUnit, Event)
if pUnit:GetHealthPct() < 50 then
pUnit:SendChatMessage (12, 0, "Stop!")
pUnit:CastSpellOnTarget (26989, pUnit:GetMainTank())
end
function Test_CheckB (pUnit, Event)
if pUnit:GetHealthPct() < 10 then
pUnit:CastSpell (17928)
end
end
function Test_OnCombat
Unit:SendChatMessage (12, 0, "Die all!")
Unit:RegisterEvent ("Test_ShadowBolt", 10000, 10)
Unit:RegisterEvent ("Test_CheckA", 30000, 20)
Unit:RegisterEvent ("Test_CheckB", 35000, 10)
end
function Test_ShadowBolt (pUnit, Event)
pUnit:CastSpellOnTarget (11661, pUnit:GetRandomPlayer(0))
Now lets move on.
PART 5: MAKING AN NPC SUMMON ANOTHER NPC
There are two ways to do this. One is the more simpler way where the npc will summon them to its exact location, and the other which is harder (don't really recommend it) is where you manualy set you the npc's summoning location.
SIMPLE METHOD:
Ok, this is the simple method and is mostly used by starters. As explained before, this will summon the creature to the exact location of our npc. Ok so what we have to do is add this to our script (under everything)
Code:
Code:
function NpcName_Summon (pUnit, Event)
x = pUnit:GetX();
y = pUnit:GetY();
z = pUnit:GetZ();
o = pUnit:GetO();
pUnit:SpawnCreature (Creatureid, x, y, z, o, factionid, durationInMiliseconds);
end
So as usuall the npc name you should know by now. The creature id is the id of the creature you are going to spawn. Now leave:
Code:
as it is because this is the simple method. When you make the creature that you are going to spawn make sure you take down the faction id because it needs to be the same.
And the duration is kind of self explanitory.
So mine looks like:
Code:
Code:
function Test_Summon (pUnit, Event)
x = pUnit:GetX();
y = pUnit:GetY();
z = pUnit:GetZ();
o = pUnit:GetO();
pUnit:SpawnCreature (1000001, x, y, z, o, 14, 360000);
end
Now its time to register it so go back to OnCombat and under your last register just put:
Code:
Code:
Unit:RegisterEvent("NpcName_Summon", timeinmiliseconds, howmanytimes)
You can summon more than one npc at one time. So now mine script looks like:
Code:
Code:
function Test_CheckA (pUnit, Event)
if pUnit:GetHealthPct() < 50 then
pUnit:SendChatMessage (12, 0, "Stop!"
pUnit:CastSpellOnTarget (26989, pUnit:GetMainTank())
end
function Test_CheckB (pUnit, Event)
if pUnit:GetHealthPct() < 10 then
pUnit:CastSpell (17928)
end
end
function Test_OnCombat
Unit:SendChatMessage (12, 0, "Die all!")
Unit:RegisterEvent ("Test_ShadowBolt", 10000, 10)
Unit:RegisterEvent ("Test_CheckA", 30000, 20)
Unit:RegisterEvent ("Test_CheckB", 35000, 10)
Unit:RegisterEvent ("Test_Summon", 50000, 6)
end
function Test_ShadowBolt (pUnit, Event)
pUnit:CastSpellOnTarget (11661, pUnit:GetRandomPlayer(0))
end
function Test_Summon (pUnit, Event)
x = pUnit:GetX();
y = pUnit:GetY();
z = pUnit:GetZ();
o = pUnit:GetO();
pUnit:SpawnCreature (1000001, x, y, z, o, 14, 360000);
pUnit:SpawnCreature (1000002, x, y, z, o, 14, 360000);
pUnit:SpawnCreature (1000003, x, y, z, o, 14, 360000);
end
ADVANCED METHOD:
So you want your npc to summon somthing but not at his/hers/its exact location? Well then you will be needing to use this method. In this method you must go in-game to the location you want your npc to summon your creatures and type .gps . Now you must write down the x, y, z and o numbers. Now open your script and put down this:
Code:
Code:
function NpcName_Summon (pUnit, Event)
pUnit:SpawnCreature (Creatureid, xid, yid, zid, oid, factionid, durationInMiliseconds);
So for the x id it would be the number you got when you typed in .gps next to the x. And the y id would be next to y when you typed in gps ect. Once you filled that out just fill in the faction and the duration just like in the simple method. Now you need to register it just like you did inn the simle method. So mine looks like:
Code:
Code:
function Test_SummonB (pUnit, Event)
pUnit:SpawnCreature (1000004, 331.963989, 109.736969, 9.615998, 0.652178, 14, 360000);
So now my entire script looks like:
Code:
Code:
function Test_CheckA (pUnit, Event)
if pUnit:GetHealthPct() < 50 then
pUnit:SendChatMessage (12, 0, "Stop!"
pUnit:CastSpellOnTarget (26989, pUnit:GetMainTank())
end
function Test_CheckB (pUnit, Event)
if pUnit:GetHealthPct() < 10 then
pUnit:CastSpell (17928)
end
end
function Test_OnCombat
Unit:SendChatMessage (12, 0, "Die all!")
Unit:RegisterEvent ("Test_ShadowBolt", 10000, 10)
Unit:RegisterEvent ("Test_CheckA", 30000, 20)
Unit:RegisterEvent ("Test_CheckB", 35000, 10)
Unit:RegisterEvent ("Test_SummonA", 50000, 6)
Unit:RegisterEvent ("Test_SummonB", 50000, 6)
end
function Test_ShadowBolt (pUnit, Event)
pUnit:CastSpellOnTarget (11661, pUnit:GetRandomPlayer(0))
end
function Test_SummonA (pUnit, Event)
x = pUnit:GetX();
y = pUnit:GetY();
z = pUnit:GetZ();
o = pUnit:GetO();
pUnit:SpawnCreature (1000001, x, y, z, o, 14, 360000);
pUnit:SpawnCreature (1000002, x, y, z, o, 14, 360000);
pUnit:SpawnCreature (1000003, x, y, z, o, 14, 360000);
end
function Test_SummonB (pUnit, Event)
pUnit:SpawnCreature (1000004, 331.963989, 109.736969, 9.615998, 0.652178, 14, 360000);
And thats all for summoning!
PART 6: MAKING AN NPC CHANGE ITS SCALE
This is pretty straight forward. Simply add this to your script:
Code:
Code:
function NpcName_Scale (pUnit, Event)
pUnit:SetScale (ScaleNumber)
end
So for me I will put:
Code:
function Test_Scale (pUnit, Event)
pUnit:SetScale (3)
end
Now as usual we need to register it under OnCombat, so once again:
Code:
Code:
Unit:RegisterEvent ("NpcName_Scale", timeinmiliseconds, howmanytimes)
Now my script looks like
Code:
Code:
function Test_CheckA (pUnit, Event)
if pUnit:GetHealthPct() < 50 then
pUnit:SendChatMessage (12, 0, "Stop!"
pUnit:CastSpellOnTarget (26989, pUnit:GetMainTank())
end
function Test_CheckB (pUnit, Event)
if pUnit:GetHealthPct() < 10 then
pUnit:CastSpell (17928)
end
end
function Test_OnCombat
Unit:SendChatMessage (12, 0, "Die all!")
Unit:RegisterEvent ("Test_ShadowBolt", 10000, 10)
Unit:RegisterEvent ("Test_CheckA", 30000, 20)
Unit:RegisterEvent ("Test_CheckB", 35000, 10)
Unit:RegisterEvent ("Test_SummonA", 50000, 6)
Unit:RegisterEvent ("Test_SummonB", 50000, 6)
Unit:RegisterEvent ("Test_SetScale", 30000, 10)
end
function Test_ShadowBolt (pUnit, Event)
pUnit:CastSpellOnTarget (11661, pUnit:GetRandomPlayer(0))
end
function Test_SummonA (pUnit, Event)
x = pUnit:GetX();
y = pUnit:GetY();
z = pUnit:GetZ();
o = pUnit:GetO();
pUnit:SpawnCreature (1000001, x, y, z, o, 14, 360000);
pUnit:SpawnCreature (1000002, x, y, z, o, 14, 360000);
pUnit:SpawnCreature (1000003, x, y, z, o, 14, 360000);
end
function Test_SummonB (pUnit, Event)
pUnit:SpawnCreature (1000004, 331.963989, 109.736969, 9.615998, 0.652178, 14, 360000);
end
function Test_Scale (pUnit, Event)
pUnit:SetScale (3)
end
Now to move on.
PART 7: MALING THE NPC CHANGE ITS MODEL
Another pretty straight forward command. So we are going to add this to our script:
Code:
Code:
function NpcName_Model (pUnit, Event)
pUnit:SetModel (Displayid)
end
Code:
So just to make something clear, the display id is NOT the npc's entry id. Ok mine looks like this:
Code:
function Test_Model (pUnit, Event)
pUnit:SetModel (31135)
end
And yet again its time to register the event. Soooooo go back to OnCombat and put:
Code:
Code:
Unit:RegisterEvent ("NpcName_SetModel", timeinmiliseconds, howmanytimes)
'
And once again i will show you what mine looks like:
Code:
Code:
function Test_CheckA (pUnit, Event)
if pUnit:GetHealthPct() < 50 then
pUnit:SendChatMessage (12, 0, "Stop!"
pUnit:CastSpellOnTarget (26989, pUnit:GetMainTank())
end
function Test_CheckB (pUnit, Event)
if pUnit:GetHealthPct() < 10 then
pUnit:CastSpell (17928)
end
end
function Test_OnCombat
Unit:SendChatMessage (12, 0, "Die all!")
Unit:RegisterEvent ("Test_ShadowBolt", 10000, 10)
Unit:RegisterEvent ("Test_CheckA", 30000, 20)
Unit:RegisterEvent ("Test_CheckB", 35000, 10)
Unit:RegisterEvent ("Test_SummonA", 50000, 6)
Unit:RegisterEvent ("Test_SummonB", 50000, 6)
Unit:RegisterEvent ("Test_SetScale", 30000, 10)
Unit:RegisterEvent ("Test_SetModel", 60000, 3)
end
function Test_ShadowBolt (pUnit, Event)
pUnit:CastSpellOnTarget (11661, pUnit:GetRandomPlayer(0))
end
function Test_SummonA (pUnit, Event)
x = pUnit:GetX();
y = pUnit:GetY();
z = pUnit:GetZ();
o = pUnit:GetO();
pUnit:SpawnCreature (1000001, x, y, z, o, 14, 360000);
pUnit:SpawnCreature (1000002, x, y, z, o, 14, 360000);
pUnit:SpawnCreature (1000003, x, y, z, o, 14, 360000);
end
function Test_SummonB (pUnit, Event)
pUnit:SpawnCreature (1000004, 331.963989, 109.736969, 9.615998, 0.652178, 14, 360000);
end
function Test_Scale (pUnit, Event)
pUnit:SetScale (3)
end
function Test_Model (pUnit, Event)
pUnit:SetModel (31135)
end
NEXT!
PART 8: ADDING THE REST
Ok so we are basicly finished with our ENEMY MOB SECTION, NOT THE COMPLETE SECTION OF LUA. So at the bottom of every thing add:
Code:
Code:
function NpcName_OnDied (Unit, Event)
Unit:RemoveEvents()
end
function NpcName_OnKilledTarget (Unit, Event)
end
function NpcName_OnLeaveCombat (Unit, Event)
Unit:RemoveEvents()
end
You can add anything to these by registering them under one of these. Now under that put:
Code:
Code:
RegisterUnitEvent(entryidofthenpc, 1, "NpcName_OnCombat")
RegisterUnitEvent(entryidofthenpc, 2, "NpcName_OnLeaveCombat")
RegisterUnitEvent(entryidofthenpc, 3, "NpcName_OnKilledTarget")
RegisterUnitEvent(entryidofthenpc, 4, "NpcName_OnDied")
So now we are done with the mob/boss section!! And now my script looks like:
Code:
Code:
function Test_CheckA (pUnit, Event)
if pUnit:GetHealthPct() < 50 then
pUnit:SendChatMessage (12, 0, "Stop!"
pUnit:CastSpellOnTarget (26989, pUnit:GetMainTank())
end
function Test_CheckB (pUnit, Event)
if pUnit:GetHealthPct() < 10 then
pUnit:CastSpell (17928)
end
end
function Test_OnCombat
Unit:SendChatMessage (12, 0, "Die all!")
Unit:RegisterEvent ("Test_ShadowBolt", 10000, 10)
Unit:RegisterEvent ("Test_CheckA", 30000, 20)
Unit:RegisterEvent ("Test_CheckB", 35000, 10)
Unit:RegisterEvent ("Test_SummonA", 50000, 6)
Unit:RegisterEvent ("Test_SummonB", 50000, 6)
Unit:RegisterEvent ("Test_SetScale", 30000, 10)
Unit:RegisterEvent ("Test_SetModel", 60000, 3)
end
function Test_ShadowBolt (pUnit, Event)
pUnit:CastSpellOnTarget (11661, pUnit:GetRandomPlayer(0))
end
function Test_SummonA (pUnit, Event)
x = pUnit:GetX();
y = pUnit:GetY();
z = pUnit:GetZ();
o = pUnit:GetO();
pUnit:SpawnCreature (1000001, x, y, z, o, 14, 360000);
pUnit:SpawnCreature (1000002, x, y, z, o, 14, 360000);
pUnit:SpawnCreature (1000003, x, y, z, o, 14, 360000);
end
function Test_SummonB (pUnit, Event)
pUnit:SpawnCreature (1000004, 331.963989, 109.736969, 9.615998, 0.652178, 14, 360000);
end
function Test_Scale (pUnit, Event)
pUnit:SetScale (3)
end
function Test_Model (pUnit, Event)
pUnit:SetModel (31135)
end
function Test_OnDied (Unit, Event)
Unit:RemoveEvents()
end
function Test_OnKilledTarget (Unit, Event)
end
function Test_OnLeaveCombat(Unit, Event)
Unit:RemoveEvents()
end
RegisterUnitEvent(3000000, 1, "Test_OnCombat")
RegisterUnitEvent(3000000, 2, "Test_OnLeaveCombat")
RegisterUnitEvent(3000000, 3, "Test_OnKilledTarget")
RegisterUnitEvent(3000000, 4, "Test_OnDied")
Don't think thats it though!!! There are still two more parts for friendly npc's!