Introduction
If you knew any C languages before reading this guide then you'd probably have it easier learning, since Lua is like a simplified C language.
In this guide you will learn the basics on how to make a boss script, i will follow up with other guides on how to make other things.
Functions
Every event in a Lua script is called a function.
A function looks like the following:
Function obviousley tells the engine that what we are creating now is a function.Code:function FUNCTION_NAME(indexes) //insert stuff here end
A function can be called anything, but try to make it a good name so that you or other developers can navigate in the script easier.
Indexes is what is included in the script. In a normal boss fight you just put pUnit and event.
pUnit = playerUnit = The Boss.
Event is selfexplainable.
Unlike the C languages Lua does not use brackets. instead you put 'end' when a function endes.
Here's a example of a little part of a boss script:
The only thing that you should be unfamiliar with in this function is;Code:function Boss_Say(pUnit, event) pUnit:SendChatMessage(12, 0, "I say something") end
and i will now explain what this is.Code:pUnit:SendChatMessage(12, 0, "I say something")
To make a boss do something you need to add something like the above.
To tell the engine that you want the boss to do something you write pUnit:SomethingCoolHere.
As i said before; in this script pUnit = the boss.
Now, SendChatMessage should be easy to understand.
We want to send a chat message in the world, to make it even more simple; we want the boss to say something.
Now in the paranthesis you see the following:
Let's rewrite this so that its easier to understand.Code:12, 0, "I say something"
There's different flags for HowToSayIt.Code:HowToSayIt, WhatLanguage, "What to say"
The following can replace 12 in how to say it;
In WhatLanguage we have used the Universal type, which means that every creature and player can understand it.Code:Value : Description -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
Now here's what we can replace WhatLanguage with:
"I say something" should be fell explainable; you input in quotes what you want the creature(in this case our boss) to say.Code:Value : Description 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
You're almost done with your first function.
For the function to work we also need to add this:
This should be very selfexplainable. If it isnt to you; then dont worry, ill walk you through it.Code:RegisterUnitEvent(BOSSID, 1, "Boss_Say")
RegisterUnitEvent means that were registering a event containing a Unit. A unit is the same thing as a creature.
BOSSID is replaced with the Bosses ID, which can be found in your database in the creatures table under the entryid column.
1 is a flag, which says that the Boss should say this when he enters combat.
Flags:
"Boss_Say" must be the same as the function name or the function wont register. Which means that the function will never exist.Code:CREATURE_EVENT_ON_ENTER_COMBAT = 1, CREATURE_EVENT_ON_LEAVE_COMBAT = 2, CREATURE_EVENT_ON_TARGET_DIED = 3, CREATURE_EVENT_ON_DIED = 4, CREATURE_EVENT_ON_TARGET_PARRIED = 5, CREATURE_EVENT_ON_TARGET_DODGED = 6, CREATURE_EVENT_ON_TARGET_BLOCKED = 7, CREATURE_EVENT_ON_TARGET_CRIT_HIT = 8, CREATURE_EVENT_ON_PARRY = 9, CREATURE_EVENT_ON_DODGED = 10, CREATURE_EVENT_ON_BLOCKED = 11, CREATURE_EVENT_ON_CRIT_HIT = 12, CREATURE_EVENT_ON_HIT = 13, CREATURE_EVENT_ON_ASSIST_TARGET_DIED = 14, CREATURE_EVENT_ON_FEAR = 15, CREATURE_EVENT_ON_FLEE = 16, CREATURE_EVENT_ON_CALL_FOR_HELP = 17, CREATURE_EVENT_ON_LOAD = 18, CREATURE_EVENT_ON_REACH_WP = 19, CREATURE_EVENT_ON_LOOT_TAKEN = 20, CREATURE_EVENT_ON_AIUPDATE = 21, CREATURE_EVENT_ON_EMOTE = 22,
So, your script should now look something like this:
If you'd put this in a file and save it as script.lua then it would work perfectly.Code:function Boss_Say(pUnit, event) pUnit:SendChatMessage(12, 0, "I say something") end RegisterUnitEvent(1337, 1, "Boss_Say")
Although once again; you need to have a creature with the entry id of 1337 in this case.
More on functions
In this part i will teach you how to register a new function within another function, this is most commonly used in what's called phase fights.
It's basically a boss fight that just registers functions after functions and when the boss is below X HP then it registers another function. Even though i hate these boss fights i am stilll going to learn you how to make one.
Here's a example of a typical phase fight:
------------------------------Code:local tank = pUnit:GetMainTank() --Here we define that "tank" is the same as pUnit:GetMainTank() local plr = pUnit:GetRandomPlayer(0) --Here we define that "plr" is the same as pUnit:GetRandomPlayer(0) function BossOnCombat(pUnit, Event) pUnit:Root() --Roots the Boss so that he cant move while hes speaking. pUnit:SetCombatCapable(1) --Makes the Boss unable to fight since i dont want him to fight the players while hes speaking. pUnit:SendChatMessage(14, 0, "There's no point in trying to defeat me!") --The Boss yells pUnit:RegisterEvent("BossLieksToSpeak", 2000, 0) --Register a new event end function BossLieksToSpeak(pUnit, Event) pUnit:SendChatMessage(14, 0, "You wont get through here.") pUnit:RegisterEvent("PrepareToFight", 2000, 0) pUnit:RegisterEvent("LetsFite", 2100, 0) end function PrepareToFight(pUnit, Event) pUnit:UnRoot() --Unroots the boss. pUnit:SetCombatCapable(0) --Makes the boss able to fight again. end function LetsFite(pUnit, Event) local choice = math.random(1, 3) --Chooses a random number between 1 and 3. if choice == 1 then --If the random number is 1 pUnit:FullCastSpellOnTarget(40932, tank) end if choice == 2 then --If the random number is 2 pUnit:FullCastSpell(60019) end if choice == 3 then --If the random number is 3 pUnit:FullCastSpellOnTarget(69528, plr) end if pUnit:GetHealthPct() <= 50 then --If the boss' health is below 50% then register a new phase. pUnit:RegisterEvent("NewPhase", 2000, 0) end end function NewPhase(pUnit, Event) pUnit:Kill() --The Boss Kills itself. end
Variations
There are different ways to make your Boss fights more variated.
For example:
The options are only limited to your imagination.Code:if pUnit:GetHealthPct() == math.random(40,60)
If you think that your script file is too big then you can seperate it into 2 files.
By simply adding:
in script file number 1.Code:include( 'scriptnumbertwo.lua' )
A smart thing to do is to vary your if's.
Like so:
This if variation is kinda pointless, but its just a demonstrationCode:if pUnit:GetHealthPct() == math.random(40,60) || pUnit:GetHealthPcty() == math.random(20, 39) then![]()

![[Lua] Beginners Guide](https://www.ownedcore.com/forums/../images/ba/3034.png)
![CoreCoins [Lua] Beginners Guide](https://www.ownedcore.com/forums/images/styles/OwnedCoreFX/addimg/wicc.png)





Reply With Quote





hsnap:


oIt();. (Oh yes, I know I did a semi-colon there. Lua allows for semi-colons just as C++ and C# do.)