Mager1794's LUA Script Tutorial
Chapter 1 Beging LUA
Intro
Supplies
What is LUA
What is it for
Chapter 2 A First Look at LUA Script
My First Script
Described
It Wont Work
Chapter 3 Peeking at the Registers
What it does
How to do it
Explained alot!
Chapter 4 Script an AI
Whats an AI
Making the script(in detail)
Chapter 1
Intro
Hi There im Mager1794 you might now me from assisting you in Emulator discusion or one
of my past guides. Well here i am making another guide to help you master LUA as fast
as possible follow this guide and you'll be good enough to call yourself a dev in no time
maybe you will be contributing to MMowned who knows now lets begin
Supplies
All you trully need is a World of warcraft server with LUA enabled and a notepad
you could also use a one of the few LUA compilers but it wont matter anyway just
make sure you save as name.LUA files
What is LUA
LUA is a extremely basic programming language that is created through C++ the functions
in LUA will react with the C++ to create the script that you are writing its
pretty much an easy version of C++
What is it for
LUA can be used for many different things for one say you have an addon?? that is made
with LUA and some XML i believe also a great thing about LUA is scripting bosses quest
event and more the powers of lua are limitless if your DLL file is made for it : )
Chapter 2
My First Script
lets begin writing our very first script now with most programming languages they always do
the little hello world thing and i dont like to be the one to break traditions so..
lets begin
[please type this rather than copy& paste from personal expieriance i feel it helps the
language sink in a little better]
Code:
function firstscript_OnCombat(pUnit, Event)
pUnit:SendChatMessage(14, 0, "Hello World")
end
end
Described
now lets break it down a bit
function
firstscript_OnEnterCombat(pUnit, Event)
pUnit:SendChatMessage(14, 0, "Hello World")
end
end
excellent now its broken down... wait thats no help
here we go
function - its the starting command for mostly every script you will ever write with out you
just have a notpad with a weird file extension
firstscript_OnEnterCombat(pUnit, Event) - its the name of the your function
(except the pUnit, Event part) the OnEnterCombat and Event work together to create the
function to happen on a certain event in this case it is on entering combat
pUnit:SendChatMessage(14. 0, "Hello World") - its your command in this function cause it to
speak the 14 is how it will be said(yell, whisper, broadcast etc) the 0 is the language
which will be your common langauge to use cause all races can understand it and the "Hello World"
is the message to be stated
end
end - there just ending the function kinda obvious
It Wont Work
Well if you already know a little about LUA then you should know why its not working
the function isn't registered yet all you have is a function no mob set for it or nothing
so we have to register it im not gonna go into it cuase that is gonna be the next chapter
but
Code:
RegisterUnitEvent(123456,1,"firstscript_OnEnterCombat:)
Chapter 3 : Peeking at the Registers
What it does
The Registers of course keep track of all the money we get from people at our
convienient store... wait...this is LUA right ooops
The Registers are what enable us to have the functions declared onto
mobs and NPC etc for now im just going to show RegisterUnitEvent but later
in the guide there will be more so be ready
How to do it
its really simple type this with me
"R" "e" "g" "i" "s" "t" "e" "r"
then erase and type
RegisterUnitEvent(
thats the basic function for the registering a unit
but for it to work you need (npc spawn ID,EventNumber,"Name_Event")
let me help you figure this stuff out
Explained Alot
EVENTNUMBER!!! *GASP*
ZOMG!! WHATS THAT
well its the number for the event
here is what i know (theres probably more)
1 - EnterCombat = It Sets the function off when it enter combat
2 - LeaveCombat = Its Set off the function when it leave combat
3 - KillTarget = Sets the function off whne it kill the target
4 - Died = Sets the function off when it dies
5 - AItick = Sets off the function when its AI (pretty much any spell used) ticks
6 - Spawn = Sets off the function on spawn
7 - Gossip = Sets the function off on gossip which is when you speak to it
8 - Waypoint = Sets off when a waypoint is reached
9 - leavelimbo = I believe its on the targets revival
10 - playerenter= When the player enters the targets area
now just insert the NPC Spawn ID and the event name and wha lah you got a
function and its registered
Chapter 4 Scripting an AI
What is AI?
AI stand for Artificial Intelligence now im not saying that i teach you this and you can
go program a robot with it or something becuase well we all know that only SectorSevens
that awesome lol. But you can program your bosses/mobs etc. with it whats the fun of a
fight if all they do is attack wheres the excitement ill tell you where on my server
with fully scripted instances its unfair for you so heres your shot to have you instances
script
Making the script(in detail)
Lets begin with a normal function
Code:
function mob_spell(unit)
notice how i used non of the identifiers from the previous chapter why is that..
its because this a pretty much a phase and i wont register it with RegisterUnitEvent
it will be done with RegisterEvent (we'll get there dont worry)
now after we do that lets make him speak with it so add
Code:
function mob_spell(unit)
Unit:SendChatMessage(12,0,"Eat the Fire")
ok so now we have him talking a fire so we dont want him to do frost or shadow or something
so always watch for that now lets make him cast the spell
Code:
function mob_spell(unit)
Unit:SendChatMessage(12,0,"Eat the Fire")
Unit:CastSpell(40255)
great that is done lets just add the end
Code:
function mob_spell(unit)
Unit:SendChatMessage(12,0,"Eat the Fire")
Unit:CastSpell(40255)
end
great were finished now were just making a mob script here so im having only one spell
but you can put as many as you wish (practice as much as you want)
ok so we have that now lets just make a simple OnCombatScript
Code:
function mob_OnEnterCombat(unit, event)
ok so we have that set up now here is where we shall register the spell
Code:
function mob_OnEnterCombat(unit, event)
Unit:RegisterEvent("function name",how often it will be done, 0)
ok so we have that now change the function name to
mob_spell
and the how often we want to be 7 seconds and since its in miliseconds just add 3 0's to
the end of it
and there ya have it its registered
now just add a SendChatMessage if you want and your done
Heres a Full Script (of that mob) Example
Code:
function mob_spell(unit)
Unit:SendChatMessage(12,0,"Eat the Fire")
Unit:CastSpell(40255)
end
function mob_OnEnterCombat(unit, event)
Unit:RegisterEvent("mob_spell",7000, 0)
end
thats all i have for now i will update this guide even more til im finally finished
leave you thoughts plz its 3 am so im goin to bed ill get some more in tommorow