
Results 1 to 6 of 6
-->
-->
Threaded View
-->
-
17-09-09, 01:48 PM #1
[Tutorial] Lua Scripting (Big explained)
Greetings everyone and welcome to the basic Lua Scripting tutorial for World of Warcraft. With this tutorial I will clearly and step for step learn you about the basics of a boss encounter. Make sure you are reading this tutorial step by step if you are a beginner
Introducion
1. Lua
2. Events
3. Spells
4. Phases
5. Extra additions
LUA
Lua is a great program for much games like World of Warcraft. The main thing to learn Lua is because it's one of the most used languages and one of the easiest to understand in games. With Lua you will get a great rank in developing at servers with a high community.
EVENTS
The Events are the ones who start a script. The most used Events are OnCombat, OnLeaveCombat, OnKilledTarget and OnDeath. I will clearly explain those basic Events to you and how to use them.
2.1. OnCombat
2.2. OnLeaveCombat
2.3. OnKilledTarget
2.4. OnDeath
OnCombat
OnCombat means when the player enters the in-combat range of the boss. When the player enters combat with the boss, then the script basicly starts. Here is an example how an OnCombat phase should look like with no events.
Code:function Boss_OnCombat(pUnit, Event) end
function, the functions tell the script what to do.
Boss, this is the name of my boss, I have called him Boss because there isn't a better name for this tutorial. You can replace this name with your own name, Boss doesn't have anything to deal with what kind of boss it is.
OnCombat, this is the name of the function, at this point, the funcion is the OnCombat Event.
(pUnit, Event), I haven't put these things seperate because they are a must at every function. pUnit means the NPC, this doesn't mean you have to change pUnit into the name of your NPC, another thing about pUnit is that it doesn't have to be pUnit everytime. You can change pUnit in another name too. The only rule about this is that you can't have two names like pUnit and Unit, remind yourself on that. And Event is the Event, meaning with 'Event is the Event' is because the Event is OnCombat.
end, this means the end of the function. You only have to put one end because it ends on one function, will explain later about this at Phases.
Now we all had these explainations, we are going to make some changes in the OnCombat phase.
With these changes I mean that we are going to let the NPC talk when a player enters in-combat range, watch what I'm going to change.
Code:function Boss_OnCombat(pUnit, Event) pUnit:SendChatMessage(14, 0, "Welcome to my lair!") end
pUnit, here is pUnit again, pUnit is always used for things like this, and to cast spells, but I'm coming back on that later.
SendChatMessage, this will let the NPC send a chat message which the players can read
(14, 0, "Welcome to my lair!") I haven't put these things separate because they are all together. The number 14 means that he yells the chat message, the number 0 means that it is universial so that everyone can understand it. The text "Welcome to my lair!" is the text the NPC yells in universial, make sure you are putting it between "".
I'm going to show you some other languages and about in what sort of type he can say it:
How he can say it:
Code:12 –- Means that the NPC says something 13 –- Means that the NPC whispers something 14 -- Means that the NPC yells something
Code:0 -- Universal, means everyone can understand it 1 -- Orcish 2 -- Darnassian 3 -- Tauron 6 -- Dwarfs 7 -- Common 8 -- Demonic 9 -- Titan 13 -- Gnomish 14 -- Trolls 33 -- Gutterspeak 35 -- Draenei
OnLeaveCombat
This is the OnLeaveCombat Event. The OnLeaveCombat Event is when the boss leaves combat with his opponents. You can have text with this too, but there is something else added to it also.
Code:function Boss_OnLeaveCombat(pUnit, Event) pUnit:SendChatMessage(14, 0, "You are to scared for my powers?!") pUnit:RemoveEvents() end
Now we are moving on the the next event.
OnKilledTarget
The OnKilledTarget event is not hard at all. You don't need to have pUnit:RemoveEvents() at this event. The reason why? I'll explain, when the boss kills an enemy, the script continues. If you put RemoveEvents() at is, he will start from the beginning. We don't want that ofcourse.
Code:function Boss_OnKilledTarget(pUnit, Event) end
Code:function Boss_OnKilledTarget(pUnit, Event) pUnit:CastSpell(36300) end
Code:function Boss_OnKilledTarget(pUnit, Event) pUnit:SendChatMessage(14, 0, "Your worthless blood feeds me!") pUnit:CastSpell(36300) end
OnDeath
The OnDeath event is just as easy as the others. You need to have pUnit:RemoveEvents() too and ofcourse, chatmessages are always welcome.
Code:function Boss_OnDeath(pUnit, Event) pUnit:SendChatMessage(14, 0, "That's impossible! Nooo!") pUnit:RemoveEvents() end
Ok! This were the explainations about all the basic Events in a boss encounter. How to put them in a script? I'll show you!
Code:function Boss_OnCombat(pUnit, Event) pUnit:SendChatMessage(14, 0, "Welcome to my lair!") end function Boss_OnLeaveCombat(pUnit, Event) pUnit:SendChatMessage(14, 0, "You are to scared for my powers?!") pUnit:RemoveEvents() end function Boss_OnKilledTarget(pUnit, Event) pUnit:SendChatMessage(14, 0, "Your worthless blood feeds me!") pUnit:CastSpell(36300) end function Boss_OnDeath(pUnit, Event) pUnit:SendChatMessage(14, 0, "That's impossible! Nooo!") pUnit:RemoveEvents() end
Code:RegisterUnitEvent(EntryID, 1, "Boss_OnCombat") RegisterUnitEvent(EntryID, 2, "Boss_OnLeaveCombat") RegisterUnitEvent(EntryID, 3, "Boss_OnKilledTarget") RegisterUnitEvent(EntryID, 4, "Boss_OnDeath")
RegisterUnitEvent, means that it registers the kind of event.
EntryID, here you need to put the EntryID of your NPC.
1, this shows what type of event it is. 1 means that it's the OnCombat event. 2 means OnLeaveCombat, 3, means OnKilledTarget and 4 means OnDeath. Those are basics, do not mess with these numbers, just put them at the right place.
"Boss_OnCombat", this is the name of the event, if you got another name on the OnCombat event, you need to change to name of it in the registering part too.
How do I put the registering part in the script? Simple, I'll show you!
Code:function Boss_OnCombat(pUnit, Event) pUnit:SendChatMessage(14, 0, "Welcome to my lair!") end function Boss_OnLeaveCombat(pUnit, Event) pUnit:SendChatMessage(14, 0, "You are to scared for my powers?!") pUnit:RemoveEvents() end function Boss_OnKilledTarget(pUnit, Event) pUnit:SendChatMessage(14, 0, "Your worthless blood feeds me!") pUnit:CastSpell(36300) end function Boss_OnDeath(pUnit, Event) pUnit:SendChatMessage(14, 0, "That's impossible! Nooo!") pUnit:RemoveEvents() end RegisterUnitEvent(EntryID, 1, "Boss_OnCombat") RegisterUnitEvent(EntryID, 2, "Boss_OnLeaveCombat") RegisterUnitEvent(EntryID, 3, "Boss_OnKilledTarget") RegisterUnitEvent
** Next part SPELLS **