I have noticed alot of LUA scripting guides out there. Well I tried all of them and never got it until I took a example and built off of that. I'm making this guide for people that were just like me, just can't figure scripting out.
Understanding LUA -
LUA is a type of a file (.lua) obviously. There are three parts to a LUA scripting
- Function - Function is basically the headline of the script you are going to make.
- Event - The actual event is what you want the mob to do. Each time you want
a different even you must use a different function and registration. - Registering - When you register the function.
Note: Make sure you end every function with
Now that you understand LUA we will put our schema to the test!
Note: Everything in red will be edited to your preferences.
Step 1 - Creating a function (see above for definition).
Open notepad. (Start, All programs, Accessories, Notepad). We will be using notepad to edit all of our scripts.
Copy the following script intro your notepad.
Code:
function Phase_1(pUnit, Event)
As said before everything in red will be edited to our preferences. So that is the starting of every script that is telling the registration what to register.
You can make it what ever you want. DO NOT USE THE SAME FUNCTION NAME FOR ANY SCRIPT! If you do use the same one it will run the wrong script. I generally use Phase_(random number that is easy to remember).
Note: Make sure you end every function with
Step 2 - Advance Commands (Example - if pUnit:GetHealthPct() < 90 then)
These commands are for making the functions to start at a certain heath %.
They also include what the mob you are scripting to target. I will have a list of all commands at the bottom of the page to save room.
For example if you want the mob to do the function at 90% the code would be
Code:
if pUnit:GetHealthPct() < 90 then
Note: I always put the following code after the code above.
The GetHealthPct you can change that to other advance commands I have at the bottom of the page.
Step 3 - The Event (see above for definition).
This is the actual "body" of the function. The event determines what you want the mob to do with that function. I will have a list at the end of this post with alot of commands you can do with this I will go into some detail now.
If you want the mob to cast a spell at that phase you would use -
Code:
pUnit:CastSpell(SPELL ID HERE)
You change the red park in brackets to the spell id you want. (You can wow head or thottbot.
If you want the mob to say something in that phase you would use -
Code:
pUnit:SendChatMessage (Type, Language, "What you want mob to say.")
Again, I will have a list of all the codes at the bottom of the post.
Step 4 - Registering the function (see above for definition).
This is the part were u tell the mob what you want it to do. I will have a list of them at the bottom of the post.
Here is a example of registering the function we just made.
Code:
pUnit:RegisterEvent("Name of the function you are registering",Time in milliseconds, How many times usually 0)
You put this at the bottom of your script or in the phase.
Step 4 - Registering the mob.
This is the part were you tell the script what mob to edit. The code for this is...
Code:
RegisterUnitEvent(NPC ID, 1, "Name of function")
Step 6 - Adding this script to your server.
On notepad go to File, Save As, save it in your C:\AC Web Ultimate Repack\Ascent\scripts folder as .lua MAKE SURE YOU SAVE AS ALL FILE TYPES!
Congratulations you have just completed a script. Here is a example of a full script.
Code:
function Phase_1(pUnit, Event)
if pUnit:GetHealthPct() < 95 then
pUnit:RemoveEvents();
pUnit:CastSpell(40737)
pUnit:RegisterEvent("Phase_224",1000, 0) - NOTE: ONLY IF YOU ARE GOING TO HAVE ANOTHER FUNCTION AFTER THIS YOU WOULD USE THAT TO REGISTER THE NEXT FUNCTION. -Delete this
end
end
function Warrior_start1(pUnit, Event)
pUnit:RegisterEvent("Phase_114",1000, 0)
pUnit:SendChatMessage (11, 0, ", you will not live to see the light of day!")
end
RegisterUnitEvent(11529, 1, "Warrior_start1")
This script will have mob number 11529 cast spell 40737 at 95% and also make the mob say $N, you will not live to see the light of day! when he enters combat. The last registration is usually registering ones like entercombat or death.
As I promised a list of commands -
Advance commands -
- pUnit:GetName()
- pUnit:GetX()
- pUnit:GetY()
- pUnit:GetZ()
- pUnit:GetO()
- pUnit:IsPlayer() then
- pUnit:IsCreature() then
- pUnit:HasFinishedQuest(questID) then
- pUnit:GetItemCount(itemID) < # then
- pUnit:GetHealthPct() <% then
- pUnit:GetUnitBySqlId(sqlID)then
- pUnit:GetClosestPlayer() then
- pUnit:GetRandomPlayer(flags)
- pUnit:GetRandomFriend()
- pUnit:GetMainTank()
- pUnit:GetAddTank()
- pUnit:GetTauntedBy()
- pUnit:GetSoulLinkedWith()
Event Commands - (Not all commands search for more).
- pUnit:SendChatMessage(type, language, "message")
- pUnit:MoveTo(x, y, z, o)
- pUnit:FullCastSpell(spellID)
- pUnit:SpawnGameObject(entryID, x, y, z, o, duration)
- pUnit:SpawnCreature(entryID, x, y, z, o, faction, duration)
- pUnit:CastSpell(spellID)
- pUnit:PlaySoundToSet(soundID)
- pUnit:SetMovementType(movementType)
- pUnit:SetHealthPct(value)
- pUnit:SetNPCFlags(flags)
- pUnit:SetModel(modelID)
- pUnit:SetScale(scale)
- pUnit:SetFaction(factionID)
Language Code -
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<Talk>-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 = SKILL32 = LOOT
83 = BATTLEGROUND_EVENT
87 = RAIDLEADER
88 = RAIDWARNING
Thank you reading my guide and I hope that it helps everybody that reads it.
If you need to contact me you can either send me a P.M. or send me a message at aim or msn... Aim - Bapesyo14 Msn - [email protected]
Thanks again,
Bapes