[Tutorial: LUA Scripting]
=========================================================
I'm here to teach you about LUA Scripting. LUA is a nice program where you can let NPC's talk and cast spells. I'm going to learn you the basic tactics of LUA Scripting, sit and relax and enjoy the LUA!
First of all, I'm going to show you a basic script.
function phase_1(pUnit, Event)
if pUnit:GetHealthPct() < 72 then
pUnit:RemoveEvents();
pUnit:SendChatMessage(12, 0, "Burning Fire!")
pUnit:FullCastSpellOnTarget(30926)
pUnit:RegisterEvent("phase_2",1000, 0)
end
end
function phase_2(pUnit, Event)
if pUnit:GetHealthPct() < 39 then
pUnit:RemoveEvents();
pUnit:FullCastSpellOnTarget(40877)
end
end
function Mr_Ilk_OnCombat(pUnit, Event)
pUnit:RegisterEvent(“phase_1”,1000, 1)
end
RegisterpUnitEvent(ID, 1, "Mr_Ilk_OnCombat")
function is needed in every script, it tells what you are going to do.
pUnit is a basic name in the script, you can change it in whatever you want but remember to keep with one name.
Event means what it is.
Now I'm going to explain about a basic phase.
This is a basic phase, here are the meanings of the functions.function phase_1(pUnit, Event)
if pUnit:GetHealthPct() < 72 then
pUnit:RemoveEvents();
pUnit:SendChatMessage(12, 0, "Burning Fire!")
pUnit:FullCastSpellOnTarget(30926)
pUnit:RegisterEvent("phase_2",1000, 0)
end
end
function phase_1(pUnit, Event) Means that this is phase_1. You can change it in your own words, like function Cone_of_Fire(pUnit, Event)
if pUnit:GetHealthPct() 72 then Is really simple, if the pUnit (NPC) is on 72%, he will do the phase.
pUnit:RemoveEvents(); Means that the pUnit(NPC) stops casting the spells and stops sending the chat messages. Otherwise he would spawn chat messages and keeps casting spells.
pUnit:SendChatMessage(12, 0, "Burning Fire!") Means that the pUnit(NPC) yells something. 12 and 0 are basic numbers for yelling. 12 = yell, 0 is that everyone understands it. (Further information is at the end of the tutorial)
pUnit:FullCastSpellOnTarget(30926) Means that the pUnit(NPC) casts a spell on the Target. FullCastSpellOnTarget means that he will cast a spell with casting speed on a target. (Further information is at the end of the tutorial)
pUnit:RegisterEvent("phase_2",1000, 0) Means that you will register the event of phase 2. If you don't register the phase, he won't do the phase. 1000 means 1000 milliseconds, so he will register the phase in 10 seconds.
endMeans the end of the phase. Remember, always do an extra end when there is if pUnit:GetHealthPct.
This was a basic phase of Mr Ilk. Lets go on with the events.
There are different events, the most used events are:
OnCombat Means that when the boss or NPC gets in combat with players.
OnLeaveCombat Means that when players are leaving combat with the boss or NPC.
OnKilledTarget Means that when the boss or NPC killed a player.
OnDeath Means that when the boss or NPC died.
Those events are the basic events. One of the most important things are REGISTERING the events, means that events will work. Not using this ability will ruin your hole script.
Now I will show you how it will look like in a script.RegisterUnitEvent (ID, 1, "Mr_Ilk_OnCombat")
RegisterUnitEvent (ID, 2, "Mr_Ilk_OnLeaveCombat")
RegisterUnitEvent (ID, 3, "Mr_Ilk_OnKilledTarget")
RegisterUnitEvent (ID, 4, "Mr_Ilk_OnDeath")
You can let them talk in the events to.function Mr_Ilk_OnCombat(pUnit, Event)
pUnit:RemoveEvents()
end
function Mr_Ilk_OnLeaveCombat(pUnit, Event)
pUnit:RemoveEvents()
end
function Mr_Ilk_OnKilledTarget(pUnit, Event)
pUnit:RemoveEvents()
end
function Mr_Ilk_OnDeath(pUnit, Event)
pUnit:RemoveEvents()
end
You don't need to do all the events in one script. If you don't use the events, you don't need to put them in the script.function Mr_Ilk_OnCombat(pUnit, Event)
pUnit:RemoveEvents()
pUnit:SendChatMessage(12, 0, Haha, here are the weaklings!")
end
If we mix the hole script, we will get this as result.
Here are some more things you could use for scripting.function phase_1(pUnit, Event)
if pUnit:GetHealthPct() < 72 then
pUnit:RemoveEvents();
pUnit:SendChatMessage(12, 0, "Burning Fire!")
pUnit:FullCastSpellOnTarget(30926)
pUnit:RegisterEvent("phase_2",1000, 0)
end
end
function phase_2(pUnit, Event)
if pUnit:GetHealthPct() < 39 then
pUnit:RemoveEvents();
pUnit:FullCastSpellOnTarget(40877)
pUnit:RegisterEvent("phase_3",1000, 0)
end
end
function Mr_Ilk_OnCombat(pUnit, Event)
pUnit:RemoveEvents()
pUnit:SendChatMessage(12, 0, Haha, here are the weaklings!")
pUnit:RegisterEvent(“phase_1”,1000, 1)
end
RegisterpUnitEvent(ID, 1, "Mr_Ilk_OnCombat")
SendChatMessage Events:
11 – npc say
12 – npc yell
13 – npc whisper
Language:
0 = UNIVERSAL
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
RegisterUnitEvents events:
eventtype:
1 = On Combat
2 = On Leave Combat
3 = On Killed Target
4 = On Died
5 = On AI Tick
6 = On Spawn
7 = On Gossip Talk
8 = On Reach Waypoint
9 = On Leave Limbo
10 = On Player Enters Range
Credits:
-[Tutorial: LUA Scripting]
=========================================================
I'm here to teach you about LUA Scripting. LUA is a nice program where you can let NPC's talk and cast spells. I'm going to learn you the basic tactics of LUA Scripting, sit and relax and enjoy the LUA!
First of all, I'm going to show you a basic script.
function phase_1(pUnit, Event)
if pUnit:GetHealthPct() < 72 then
pUnit:RemoveEvents();
pUnit:SendChatMessage(12, 0, "Burning Fire!")
pUnit:FullCastSpellOnTarget(30926)
pUnit:RegisterEvent("phase_2",1000, 0)
end
end
function phase_2(pUnit, Event)
if pUnit:GetHealthPct() < 39 then
pUnit:RemoveEvents();
pUnit:FullCastSpellOnTarget(40877)
end
end
function Mr_Ilk_OnCombat(pUnit, Event)
pUnit:RegisterEvent(“phase_1”,1000, 1)
end
RegisterpUnitEvent(ID, 1, "Mr_Ilk_OnCombat")
function is needed in every script, it tells what you are going to do.
pUnit is a basic name in the script, you can change it in whatever you want but remember to keep with one name.
Event means what it is.
Now I'm going to explain about a basic phase.
This is a basic phase, here are the meanings of the functions.function phase_1(pUnit, Event)
if pUnit:GetHealthPct() < 72 then
pUnit:RemoveEvents();
pUnit:SendChatMessage(12, 0, "Burning Fire!")
pUnit:FullCastSpellOnTarget(30926)
pUnit:RegisterEvent("phase_2",1000, 0)
end
end
function phase_1(pUnit, Event) Means that this is phase_1. You can change it in your own words, like function Cone_of_Fire(pUnit, Event)
if pUnit:GetHealthPct() 72 then Is really simple, if the pUnit (NPC) is on 72%, he will do the phase.
pUnit:RemoveEvents(); Means that the pUnit(NPC) stops casting the spells and stops sending the chat messages. Otherwise he would spawn chat messages and keeps casting spells.
pUnit:SendChatMessage(12, 0, "Burning Fire!") Means that the pUnit(NPC) yells something. 12 and 0 are basic numbers for yelling. 12 = yell, 0 is that everyone understands it. (Further information is at the end of the tutorial)
pUnit:FullCastSpellOnTarget(30926) Means that the pUnit(NPC) casts a spell on the Target. FullCastSpellOnTarget means that he will cast a spell with casting speed on a target. (Further information is at the end of the tutorial)
pUnit:RegisterEvent("phase_2",1000, 0) Means that you will register the event of phase 2. If you don't register the phase, he won't do the phase. 1000 means 1000 milliseconds, so he will register the phase in 10 seconds.
endMeans the end of the phase. Remember, always do an extra end when there is if pUnit:GetHealthPct.
This was a basic phase of Mr Ilk. Lets go on with the events.
There are different events, the most used events are:
OnCombat Means that when the boss or NPC gets in combat with players.
OnLeaveCombat Means that when players are leaving combat with the boss or NPC.
OnKilledTarget Means that when the boss or NPC killed a player.
OnDeath Means that when the boss or NPC died.
Those events are the basic events. One of the most important things are REGISTERING the events, means that events will work. Not using this ability will ruin your hole script.
Now I will show you how it will look like in a script.RegisterUnitEvent (ID, 1, "Mr_Ilk_OnCombat")
RegisterUnitEvent (ID, 2, "Mr_Ilk_OnLeaveCombat")
RegisterUnitEvent (ID, 3, "Mr_Ilk_OnKilledTarget")
RegisterUnitEvent (ID, 4, "Mr_Ilk_OnDeath")
You can let them talk in the events to.function Mr_Ilk_OnCombat(pUnit, Event)
pUnit:RemoveEvents()
end
function Mr_Ilk_OnLeaveCombat(pUnit, Event)
pUnit:RemoveEvents()
end
function Mr_Ilk_OnKilledTarget(pUnit, Event)
pUnit:RemoveEvents()
end
function Mr_Ilk_OnDeath(pUnit, Event)
pUnit:RemoveEvents()
end
You don't need to do all the events in one script. If you don't use the events, you don't need to put them in the script.function Mr_Ilk_OnCombat(pUnit, Event)
pUnit:RemoveEvents()
pUnit:SendChatMessage(12, 0, Haha, here are the weaklings!")
end
If we mix the hole script, we will get this as result.
Here are some more things you could use for scripting.function phase_1(pUnit, Event)
if pUnit:GetHealthPct() < 72 then
pUnit:RemoveEvents();
pUnit:SendChatMessage(12, 0, "Burning Fire!")
pUnit:FullCastSpellOnTarget(30926)
pUnit:RegisterEvent("phase_2",1000, 0)
end
end
function phase_2(pUnit, Event)
if pUnit:GetHealthPct() < 39 then
pUnit:RemoveEvents();
pUnit:FullCastSpellOnTarget(40877)
pUnit:RegisterEvent("phase_3",1000, 0)
end
end
function Mr_Ilk_OnCombat(pUnit, Event)
pUnit:RemoveEvents()
pUnit:SendChatMessage(12, 0, Haha, here are the weaklings!")
pUnit:RegisterEvent(“phase_1”,1000, 1)
end
RegisterpUnitEvent(ID, 1, "Mr_Ilk_OnCombat")
Credits:SendChatMessage Events:
11 – npc say
12 – npc yell
13 – npc whisper
Language:
0 = UNIVERSAL
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
RegisterUnitEvents events:
eventtype:
1 = On Combat
2 = On Leave Combat
3 = On Killed Target
4 = On Died
5 = On AI Tick
6 = On Spawn
7 = On Gossip Talk
8 = On Reach Waypoint
9 = On Leave Limbo
10 = On Player Enters Range
-sjoerdman
I hope you enjoyed and learned about LUA Scripting now.