There are a LOT of lua guides out there right now, but I’ve tried to create a guide that would let you start as a beginner, and by the end you would have some skills in lua and be able to continue to figure more things out for yourself. First we are starting with boss scripts, after boss scripts comes gossip, and after gossip comes item/gobject gossip. Then after that I will give some nifty tips and some more advanced ideas. .
Boss Scripts
1. Creating Your First Script!
1.1 Making your NPC talk
1.2 Making your NPC cast spells
1.3 Making your NPC spawn other NPCs
2. Creating Phases
2.1 Using pUnit:RegisterEvent to create phases
2.2 Using ‘if’ statements to your advantage
2.3 Removing events with pUnit:RemoveEvent()
3. Variables <3 You
3.1 Local =
3.2 Using variables to change things up
3.3 Variables and math.random
NPC Gossip Scripts
1. Creating A Basic Gossip Menu
[1.1 Making Your NPC broadcast a message
1.2 Making your NPC teleport a player
1.3 Making your NPC morph a player
1.4 Making your NPC buff a player
2. Making Gossip Scripts Fit With Boss Scripts
2.1 Gossip NPC spawning other NPC’s
2.2 Gossip NPC starting an event
Item Gossip Scripts
1. Setting Up An Item Gossip Script
1.1 Creating a warp stone
1.2 Creating an information stone
1.3 Creating a wishing stone
----------------------------------------------------------------------------------------------------------------------------------------------------
1. Creating Your First Script!
1.1 Making your NPC talk.
I personally think that making an NPC talk is the easiest thing to
script, and it gives us the ability to provide a good starting point when it comes to creating events and that sort of thing. So right here I will introduce you to the structure of every lua script. Some things may be different depending on the script, but generally this is how they will all start.
Code:
function BossName_OnCombat(pUnit, event)
Now this is telling you what the boss will do when he enters combat. So let’s state what we want the boss to do when he enters combat. We will make him say, “My first lua boss script.” So we need to add this to our script.
Code:
pUnit:SendChatMessage(14, 0, “My first lua boss script.”)
Let me explain. This is saying the NPC is going to send a chat message in ‘Monster Yell’ (That’s what the 14 is saying), and he is saying “My first lua boss script.” It is really that simple. Now there are a lot of things that can be used instead of 14. I normally use one of the following:
Code:
12 – Monster Say
13 – Monster Whisper
14 – Monster Yell
42 – Announce (Similar to a raid announcement)
The 0 in the script tells us what language the monster should speak in. Here is a list of possible languages.
Code:
0 – Universal
1 – Orcish
2 - Darnassian
3 - Tauren
6 – Dwarven
7 – Common
8 – Demonic
9 – Titan Language
13 – Gnomish
14 – Troll
33 – Gutterspeak
35 – Draenie language
Now all you need to do is to end your script. This is always done with an ‘end’ in lua. So just throw an end at the end of the script and you are almost done. Your script should look something like this:
Code:
function BossName_OnCombat(pUnit, event)
pUnit:SendChatMessage(14, 0, “My first lua boss script!”)
end
Now we need to register the event. Registering an event in lua looks like this:
Code:
RegisterUnitEvent(NPCID, When To Register It, “function name”)
So your registration should look like this:
Code:
RegisterUnitEvent(YOUR NPC ID, 1, “BossName_OnCombat”)
I’m going to go over what that ‘1’ means in the RegisterUnitEvent. The 1 is saying that you should register the event when the NPC enters combat. Here are the options that you can put there:
Code:
1 – Enter Combat
2 – Leave Combat
3 – Killed Target
4 – When NPC dies
6 – When NPC spawns
7 – Gossip Talk
8 – Reach Waypoint
10 – When player enters range
So now your final script should look like this:
Code:
Function BossName_OnCombat(pUnit, event)
pUnit:SendChatMessage(14, 0, “My first lua boss script.”)
end
RegisterUnitEvent(YOURNPCID, 1, “BossName_OnCombat”)
Congratulations! You have completed your first boss script!
1.2 Making Your NPC Cast Spells
Making your NPC cast spells is really what makes your boss script into an actual fight that players want to enjoy. WoWhead is your #1 source for finding spells/spell id’s, so use it whenever you need. So now that you have the basic structure for a script down we can begin making the boss cast spells. This can be done in many ways, I advise using FullCastSpellOnTarget. I will talk about the other ways at the end of the guide. So let’s get started. We will start with the same setup as before.
Code:
Function BossName_OnCombat(pUnit, event)
Now this is where things are changed up. We are now going to use this:
Code:
pUnit:FullCastSpellOnTarget(SPELLID, TARGET)
Now for the spell ID look at WoWhead, but for the target you can use this list:
Code:
pUnit:GetRandomPlayer(0) – Will make your NPC target a completely random player
pUnit:GetRandomPlayer(1) – Will make your NPC target a random player in short range
pUnit:GetRandomPlayer(2) – Will make your NPC target a random player in medium range
pUnit:GetRandomPlayer(3) – Will make your NPC target a random player in long range
pUnit:GetRandomPlayer(4) – Will make your NPC target a random player with mana
pUnit:GetRandomPlayer(5) – Will make your NPC target a random player with rage
pUnit:GetRandomPlayer(6) – Will make your NPC target a random player with energy
pUnit:GetRandomPlayer(7) – Will make your NPC target a random player outside of the main tank
pUnit:GetMainTank() – Makes your NPC target the main tank
pUnit:GetClosestPlayer() – Makes your NPC target the closest player
So you can replace TARGET with any of those above. In this guide we are going to have your NPC cast Fireball (Spellid 42833) on the main tank. So it should look like this
Code:
pUnit:FullCastSpellOnTarget(42833, pUnit:GetMainTank())
Now for putting it all together and registering the event.
Code:
function BossName_OnCombat(pUnit, event)
pUnit:FullCastSpellOnTarget(42833, pUnit:GetMainTank())
end
RegisterUnitEvent(YOURNPCID, 1, “BossName_OnCombat”)
You have successfully made your boss cast a spell!
1.3 Making your NPC spawn other NPC’s
Making your NPC spawn other NPC’s is really just as simple as everything else we have done. Spawning NPC’s is really a fun way to make a boss fight more interesting. So let’s get started. First we need to start by looking at what we will use to spawn NPCs. For this guide we will use this:
Code:
pUnit:SpawnCreature(NPCID, X, Y, Z)
Simple enough right? Spawns an NPC with the id you listed at the x, y, and z coordinates you specified. Now you will have to get your own coordinates in-game as I won’t provide you with any for the guide. The easiest way to do that is to use the .gps command in-game and copy down the x, y, and z coords. Just like with all our other scripts this will be inside the BossName_OnCombat and will be registered just like the others. So throw in your coordinates and bam. Your script should look something like this:
Code:
function BossName_OnCombat(pUnit, event)
pUnit:SpawnCreature(NPCID, X, Y, Z)
end
RegisterUnitEvent(YOURBOSSNPCID, 1, “BossName_OnCombat”)
There you have it. Your boss will now spawn an NPC at those coordinates when you attack him!
2. Creating Phases
2.1 pUnit:RegisterEvent()
PUnit:RegisterEvent() is a very important tool in a good lua scripters arsenal.
Registering events this way makes it so that you can make the boss do far more than you could if you just used ‘RegisterUnitEvent’. Using ‘pUnit:RegisterEvent()’ provides us with a quick and easy way to do fun stuff. So here we go. Registering events always looks like this:
Code:
pUnit:RegisterEvent(“EventName”, Interval of Time, # of times you want the event to occur in the specified time)
So just like before we will add that to our OnCombat function. Just remember that all time in lua is in milliseconds. 1000 is actually 1 second. Just a reminder for all of you. . So this is an idea of what your script could look like:
Code:
function BossName_OnCombat(pUnit, event)
pUnit:RegisterEvent(“FirstRegisteredEvent”, 10000, 1)
end
Now when registering events like this you don’t have to register it again with the ‘RegisterUnitEvent’, but you do need to register the original event, which in this case is the ‘BossName_OnCombat’, but before we do that we should say what our ‘FirstRegisteredEvent’ is going to do. I’m going to make mine say something interesting.
Code:
function FirstRegisteredEvent(pUnit, event)
pUnit:SendChatMessage(14, 0, “Something interesting!”)
end
Now we can add this to our original script, and then use ‘RegisterUnitEvent’ for our original OnCombat function. Once you have done that your script is finished, and you have successfully created a new event.
Hope you enjoy what I have so far! The rest is coming shortly! Just need to figure out how to word it properly If you have any advice please tell me so I can add it to the guide.