This is a guide on understanding and applying the LUA coding language adapted for WoW. This guide is just covering the basics of LUA and you will actually learn the code if you follow this guide correctly.
Table of Contents:
I. What Is LUA?
II. How do I start?
III. Unit Commands
IV. How To Use Your Script
I. What Is LUA?
LUA is a code used for many different things. It, for one, is used in the scripting of World of Warcraft addons, which we all love. It is also used for something else that applies directly to Emulator servers, scripting our creatures. You may ask, this must be hard to learn? Well its not. I learned within a week and got good at it while I was a noob. LUA is a basically a unspoken requirement for being a
Contributer and above, or knowing some scripting language. So you might as well learn now.
II. How do I start?
You start by following these few basic steps to LUA coding.
First, when you start EVERY script your first line needs to look something like this:
Code:function NPCname_Phaseorfunction (pUnit, Event)
Second, you must always have some content to go with it. Thats what the first line does, prepare for your "work" part. Follow the example:
- The function command must always start each section of your script.
- The NPCname_Phaseorfunction must always be there also. You may change this to whatever you like maybe. MurlocBoss_Entercombat. The first part generally is the name of the creature, and the second part is generally what or when it is happening.
- The (pUnit, Event) must always be there and will never change.
function NPCname_Phaseorfunction (pUnit, Event)
pUnit:SendChatMessage(Type, Language, "Message")Third, you must follow up all your scripts with the word "end". Follow the example:
- The pUnit: must always be there if it is a unit command. I will explain these later. It is also formal to indent your pUnit lines.
- The SendChatMessage is the unit command. This is just an example and I will show you later. It should have NO spaces and should always follow the colon.
- The (Type, Language, "Message") part is just an example. It should describe the command you wish to do (SendChatMessage in this case). There shouldn't be any spaces between the unit command and the description.
The final component to understanding LUA is the RegisterUnitEvent (NPCid, When, "UpperExplain") command. This signals the end of your units. Look at this example:function NPCname_Phaseorfunction (pUnit, Event)
pUnit:SendChatMessage(Type, Language, "Message")
end
You know what the number in the "when" part is by picking the time that it occurs based off these numbers.function NPCname_Phaseorfunction (pUnit, Event)
pUnit:SendChatMessage(Type, Language, "Message")
end
RegisterUnitEvent (10000, 1, "NPCname_Phaseorfunction")
So if you wanted it to happen after he died put the number 4 in the second blank of the parenthesis.1 = Enter Combat
2 = Leave Combat
3 = Killed Target
4 = Died
5 = AI Tick
6 = Spawn
7 = Gossip Talk
8 = Reach Waypoint
9 = On Leave Limbo
10 = Player Enters Range
Then, for the "Stuff" part, put what you put on the first line (the words) with the _ in them. make sure its in quotation marks.
Thats all you need to know for the basics of writing LUA for your creature.
III. Unit Commands
This is the part that you actually stop get to add stuff to your LUA script. I'm going to give examples of useful unit commands that most people will use. Remember to put the pUnit before these.
:SendChatMessage(Type, Language, "Message")
Self explanitory; it makes the NPC talk.
For type put one of these numbers:
For language put one of these numbers:-1 = ADDON
0 = SAY
1 = PARTY
2 = RAID
3 = GUILD
4 = OFFICER
5 = YELL
6 = WHISPER
7 = WHISPER_INFORM
8 = EMOTE
9 = TEXT_EMOTE
10 = SYSTEM
11 = MONSTER_SAY
12 = MONSTER_YELL
13 = MONSTER_WHISPER
14 = CHANNEL
16 = CHANNEL_JOIN
17 = CHANNEL_LEAVE
18 = CHANNEL_LIST
19 = CHANNEL_NOTICE
20 = CHANNEL_NOTICE_USER
21 = AFK
22 = DND
23 = COMBAT_LOG
24 = IGNORED
25 = SKILL
32 = LOOT
83 = BATTLEGROUND_EVENT
87 = RAIDLEADER
88 = RAIDWARNING
For the last part put your message, make sure that its in "" (parenthesis).0 = UNIVERSAL
1 = ORCISH
2 = DARNASSIAN
3 = TAURAHE
6 = DWARVISH
7 = COMMON
8 = DEMONIC
9 = TITAN
10 = THELASSIAN
11 = DRACONIC
12 = KALIMAG
13 = GNOMISH
14 = TROLL
33 = GUTTERSPEAK
35 = DRAENEI
:CastSpell(ID)
This one is easy to understand. Simply put the spell id in for the spell ID number. This can be found using WoWhead, Thottbot, or any WoW database website.
:SpawnGameObject(entryID, x, y, z, o, duration)
This one is also pretty self-explanitory. You MUST have an SQL file for the gameobject you want to spawn. So put the ID of the gameobject first, then the coordinates for the location you want it to spawn using the .gps command. For duration, remember its in milliseconds. Example: 10 seconds = 10000.
:SpawnCreature(entryID, x, y, z, o, faction, duration)
This one is the exact same as the one above, exept your spawning a creature. Make sure the SQL is already made for it. Use the faction NUMBER for the faction part. There are too many to list here, so just search for a Faction ID thread.
:Emote(Id)
This command is currently not working in Ascent. I will let you know when it is. Simply put the emote id for the id part. You can search for a thread on this also.
:AddItem(itemID, count)
For this, you must have the item already made through SQL and it be in your database. Put the ID for that id part, put the number you wish to give the player in the count part.
:SetScale(Number)
Simply put the number that you want to multipy the creatures size by. Default is 1.
:SetModel(DisID)
For this, you need a display ID of a creature you want this creature to morph to. Its basically .morph exept on a creature.
:LearnSpell(ID)
This one is easy. Put the spell ID you want to teach the player, not NPC, in this ID slot.
:PlaySoundToSet(ID)
This command plays a sound to the sourrounding area. To find the id, search for Sound ID List.
IV: How to use your script
Now you must save your script. Save it as Boss_CreatureName.lua is the tipical setup. Place in your scripts folder with has other LUA files in it. Make sure your compile/repack has LUA enabled and that its enabled in your ascent-world. Also, make sure there is a LUA dll in your script_bin folder. Now restart your server and have fun!
Hope this guide helped many of you struggling with understanding LUA. If you have suggestions/feedback PLEASE leave them. Have fun and enjoy!
-Eagle