In this guide i'll show you to do most things with LUA. Ill be showing you how to:
----------
0. Getting sun++ Lua Engine (Only if you allready compiled your core)
1. Script Custom Mobs
1.1 Say something
1.2 Cast spells
1.3 Summon other mobs
1.4 Make phases (Change its scale, displayid Etc includet)
2. Script GO's
2.1 Portal
3. Script a Global NPC
3.1 Teleporter NPC
3.2 Buffer
3.3 Healer
3.4 Morpher
4. Script a Lua item (Credits: Roguezor - Kinda looked into his guide and rewrote)
4.1 Warpstone (Under construction)
----------
Ill be keeping this guide updated!
Ok, now, let's start!
0.
Ok, here i will give the credits to Cele! And give you the link to his great guide on how to get Sun++:
How To Patch Sun++ For Arcemu
Note: It would be a realy good idea if you get Sun++ since this will give you way more options than with ArcEmu's original one!
And now, let's continue to the "Real" Lua scripting:
1.
1.1
When you script a mob your script should look like this:
Code:
Code:
function Nameofthefunction(Unit, Event)
end
Now let's pretend that my NPC is called "Evilguy" and this script is supposed to make him do something on combat!
Then the script should look like this:
Code:
Code:
function Evilguy_OnCombat(Unit, Event)
end
Red: As you see this is the name of my NPC
Blue: This is OnCombat
Note: Nameofthefunction could be anything meaning that this could ex be: "Iamsocool" - it doesen't realy matter! To make it easier for you i think should do like me: "YourNpcNamegoesHere_OnCombat"
Now, let's continue:
To make the Npc something say when you approach it we will use this code:
Code:
Code:
Unit:SendChatMessage(12, 0, "Here you write what ever you want your NPC to say")
Red: 12 means that when you approach your npc the npc will "SAY" not yell or whisper.
Here are some codes you can choose as well:
Code:
12 – npc say
13 – npc whisper
14 - npc yell
Blue: This is for the language, 0 means "universal" which all races can understand!
Here are some language codes you can choose as well:
Code:
Code:
0 = Universal
1 = Orcish
2 = Darnassian
3 = Tauron
6 = Dwarfs
7 = Common
8 = Demonic
9 = Titans
13 = Gnomish
14 = Troll language
33 = Gutterspeak
35 = Dranie or whatever the **** that is
Now, let's add the function to my script:
Code:
Code:
function Evilguy_OnCombat(Unit, Event)
Unit:SendChatMessage(14, 0, "I Will Kill You!")
end
Now this makes my NPC yell "I will kill you!" in Universal - meaning that everybody can understand it
Now we need to register the function.
Hit enter two times and write in this:
Code:
Code:
RegisterUnitEvent(YourNpcSpawnIDGoesHere, 1, "Nameofthefunction")
Red: This is the name of the function, mine was "Evilguy_OnCombat"
Blue: 1 is the code for, that this function will register on combat!
Here are some other options you can use:
Code:
Code:
1 = Enter combat
2 = Leave combat
3 = Killed target
4 = When Npc is dead
6 = Spawn
7 = Gossip talk
8 = Reach waypoint
10 = When player enters range
Let's pretend that my Npc's spawn ID is "9995", and now let's look at the whole script:
Code:
Code:
function Evilguy_OnCombat(Unit, Event)
Unit:SendChatMessage(14, 0, "I Will Kill You!")
end
RegisterUnitEvent(9995, 1, "Evilguy_OnCombat")
Here is something you wanna add to your script as well:
Code:
f
Code:
unction Evilguy_OnLeaveCombat(Unit, Event)
Unit:RemoveEvents()
end
function Evilguy_OnKilledTarget(Unit, Event)
end
function Evilguy_OnDied(Unit, Event)
Unit:RemoveEvents()
end
Red: This pretty much talks for it self, anyway! Let's pretend that you made this realy huge boss scripts, with lots of phases and stuff like that. Then when your NPC got killed or left combat, ofc you want your NPC to get back to normal size and normel DisplayID. Therefore this "RemoveEvents"
Blue: This is when your NPC kills a target. You can ex make your NPC yell "Hahaha, i told you!"!
And then to register theese functions:
Code:
Code:
RegisterUnitEvent(YourNpcSpawnIDGoesHere, 2, "_OnLeaveCombat")
RegisterUnitEvent(YourNpcSpawnIDGoesHere, 3, "_OnKilledTarget")
RegisterUnitEvent(YourNpcSpawnIDGoesHere, 4, "_OnDied")
And now to put all this together in one script:
Code:
Code:
function Evilguy_OnCombat(Unit, Event)
Unit:SendChatMessage(14, 0, "I Will Kill You!")
end
Code:
function Evilguy_OnLeaveCombat(Unit, Event)
Unit:RemoveEvents()
end
function Evilguy_OnKilledTarget(Unit, Event)
end
function Evilguy_OnDied(Unit, Event)
Unit:RemoveEvents()
end
RegisterUnitEvent(9995, 1, "Evilguy_OnCombat")
RegisterUnitEvent(9995, 2, "Evilguy_OnLeaveCombat")
RegisterUnitEvent(9995, 3, "Evilguy_OnKilledTarget")
RegisterUnitEvent(9995, 4, "Evilguy_OnDied")
1.2
Now, just to make a NPC say something is kinda boring, let's add a spell:
To make the NPC cast a spell we will need another function, so just start to write:
Code:
Code:
function Nameofthefunction(Unit, Event)
end
Note: To make it easyer remember i will make the function name to: "Evilguy_Spell1":
Code:
function Evilguy_Spell1(Unit, Event)
end
Code:
Unit:FullCastSpellOnTarget(spellid, Unit:Target)
Target could be some of the following:
Code:
Code:
- GetRandomPlayer(0) = Will make the mob target a random player
- GetRandomPlayer(1) = Target random player in short range
- GetRandomPlayer(2) = Target random player in medium range
- GetRandomPlayer(3) = Target random player in long range
- GetRandomPlayer(4) = Target random player with mana
- GetRandomPlayer(5) = Target random player with rage
- GetRandomPlayer(6) = Target random player with energy
- GetRandomPlayer(7) = Target random player, main tank won't be targeted
- GetMainTank() = Talks for itself
- GetClosestPlayer() = Talks for itself :P
So let's say that my NPC will cast its spell on the main tank, then my script would look like this:
Code:
Code:
function Evilguy_Spell1(Unit, Event)
Unit:FullCastSpellOnTarget(5, Unit:GetMainTank())
end
Red:This spell is Death Touch (Uhh, evil )
And now, we want this to be registeret in combat, therefore we will use this code:
Code:
Code:
Unit:RegisterEvent("nameofthefunction", timeinmiliseconds, howmanytimes)
Now, ill make it look like this:
Code:
Code:
Unit:RegisterEvent("Evilguy_Spell1", 60000, 2)
This will make the NPC cast the spell 2 times during 60 seconds.
Now we want this to be registered OnCombat, so the whole script should now look like this:
Code:
Code:
function Evilguy_OnCombat(Unit, Event)
Unit:SendChatMessage(14, 0, "I Will Kill You!")
Unit:RegisterEvent("Evilguy_Spell1", 60000, 2) <-------- (This is where your supposed to put your "RegisterEvent" when your want it registered on combat)
end
function Evilguy_Spell1(Unit, Event)
Unit:FullCastSpellOnTarget(5, Unit:GetMainTank())
end
function Evilguy_OnLeaveCombat(Unit, Event)
Unit:RemoveEvents()
end
function Evilguy_OnKilledTarget(Unit, Event)
end
function Evilguy_OnDied(Unit, Event)
Unit:RemoveEvents()
end
RegisterUnitEvent(9995, 1, "Evilguy_OnCombat")
RegisterUnitEvent(9995, 2, "Evilguy_OnLeaveCombat")
RegisterUnitEvent(9995, 3, "Evilguy_OnKilledTarget")
RegisterUnitEvent(9995, 4, "Evilguy_OnDied")
1.3
LUA scripting guide! (Part 1.3 - 1.4)
1.4
LUA scripting guide! (Part 1.3 - 1.4)
2.
2.1
Now i will teach you how to script a portal:
The script itself looks like this:
Code:
Code:
function ScriptName(pUnit, Event, pMisc)
pMisc:Teleport(MapID, X-Coord, Y-Coord, Z-Coord)
end
Code:
RegisterGameObjectEvent(GameObjectsENTRYID, 2, "ScriptName")
Now, look at the first line:
Code:
Code:
function ScriptName(pUnit, Event, pMisc)
Red: Replace this with the name of your Script. It could be anything!
EX:
Code:
Code:
function Teleportwhenclicked(pUnit, Event, pMisc)
Now to the next line:
Code:
Code:
pMisc:Teleport(MapID, X-Coord, Y-Coord, Z-Coord)
Now, that pretty much tells what to do itself. Simply replace the MapID, X-Coord, Y-Coord and Z-Coord with your .gps details
Now end it with an:
Code:
And ofc to register the event:
Code:
Code:
RegisterGameObjectEvent(GameObjectsENTRYID, 2, "ScriptName")
Green: Change this into the spawn ID of your gameobject
Red: This should be the same scriptname as the name you chose on the first line
Now mine looks like this:
Code:
function PvPArena2(pUnit, Event, pMisc)
pMisc:Teleport(530, -2009.403320, 6590.512695, 12.360116)
end
RegisterGameObjectEvent(999998, 2, "PvPArena2")
This will teach you how to make a Teleporter NPC
Start with
Code:
Code:
function On_Gossip(unit, event, player)
Under that write:
Code:
Code:
unit:GossipCreateMenu(Any high number, player, 0)
And now we need to write what the options should be, ex:
Code:
Code:
unit:GossipMenuAddItem(0,"Alliance Locations", 0, 0)
What the collors mean:
Red: This is the menu, meaning that when u click this, you will go to a submenu, where you can click ex. "Ironforge", and it will port you to ironforge(i will tell you how to that later in the guide)
Blue: You could call this the menu number, meaning that all menu's(including submenu's) should have a different number. You can't have two menu's having the same number. Then it won't work
Okay then, end this function by writting:
Code:
Code:
unit:GossipSendMenu(player)
end
Here is mine:
Code:
Code:
function On_Gossip(unit, event, player)
unit:GossipCreateMenu(100, player, 0)
unit:GossipMenuAddItem(0,"Alliance Locations", 0, 0)
unit:GossipSendMenu(player)
end
Now to the Submenu's:
Start with:
Code:
Code:
function Gossip_Submenus(unit, event, player, id, intid, code)
And now we will edit the alliance locations, so that it will port us to ex Ironforge:
write this:
Code:
Code:
if(intid == 0) then
(Blue: As you see it's a zero(0). Now, go look at alliance locations. Alliance Locations are having a 0 as the menu number, now what we just wrote, means, that if you press "Alliance Locations" you will be transfered to a submenu, where to options: Darnassus, Ironforge etc etc are.)
Now under this write:
Code:
Code:
unit:GossipCreateMenu(Any high number(Not the same as the first GossipCreateMenu, player, 0)
And now we will start to add the locations, write:
Code:
Code:
unit:GossipMenuAddItem(0,"Darnasuss", 50, 0)
unit:GossipMenuAddItem(0,"Ironforge", 51, 0)
unit:GossipMenuAddItem(0,"Stormwind", 52, 0)
unit:GossipMenuAddItem(0,"Exodar", 53, 0)
unit:GossipSendMenu(player)
end
Now mine looks like this:
Code:
Code:
function On_Gossip(unit, event, player)
unit:GossipCreateMenu(100, player, 0)
unit:GossipMenuAddItem(0,"Alliance Locations", 0, 0)
unit:GossipSendMenu(player)
end
function Gossip_Submenus(unit, event, player, id, intid, code)
if(intid == 0) then
unit:GossipCreateMenu(101, player, 0)
unit:GossipMenuAddItem(0,"Darnasuss", 50, 0)
unit:GossipMenuAddItem(0,"Ironforge", 51, 0)
unit:GossipMenuAddItem(0,"Stormwind", 52, 0)
unit:GossipMenuAddItem(0,"Exodar", 53, 0)
unit:GossipSendMenu(player)
end
Now to make the options port you where you wanna go!
Note: You can see that the menu number of Darnasuss is 50, Ironforge is 51, Stormwind is 52, Exodar is 53.
Now write this:
Code:
Code:
if(intid == 50) then
player:Teleport(1, 9985.907227, 1971.155640, 1326.815674)
end
Blue: 50 is the menu number of Darnassus.
And then you will have to repeat this until all your options will port you where they are supposed to port you!
Finnish everything off with an extra:
Code:
end
And ofc to register the events write:
Code:
Code:
RegisterUnitGossipEvent(Your NPC Spawn ID, 1, "On_Gossip")
RegisterUnitGossipEvent(Your NPC Spawn ID, 2, "Gossip_Submenus")
So now mine looks like this:
Code:
Code:
function On_Gossip(unit, event, player)
unit:GossipCreateMenu(100, player, 0)
unit:GossipMenuAddItem(0,"Alliance Locations", 0, 0)
unit:GossipSendMenu(player)
end
function Gossip_Submenus(unit, event, player, id, intid, code)
if(intid == 0) then
unit:GossipCreateMenu(101, player, 0)
unit:GossipMenuAddItem(0,"Darnasuss", 50, 0)
unit:GossipMenuAddItem(0,"Ironforge", 51, 0)
unit:GossipMenuAddItem(0,"Stormwind", 52, 0)
unit:GossipMenuAddItem(0,"Exodar", 53, 0)
unit:GossipSendMenu(player)
end
if(intid == 50) then
player:Teleport(1, 9985.907227, 1971.155640, 1326.815674)
end
if(intid == 51) then
player:Teleport(0, -5028.265137, -825.976563, 495.301575)
end
if(intid == 52) then
player:Teleport(0, -9100.480469, 406.950745, 92.594185)
end
if(intid == 53) then
player:Teleport(530, -4072.202393, -12014.337891, -1.277277)
end
end
Code:
RegisterUnitGossipEvent(5, 1, "On_Gossip")
RegisterUnitGossipEvent(5, 2, "Gossip_Submenus")
3.2 and 3.3
Making a healer and a buffer is about the same thing, therefore i will mix theese two!
We are also using about the same functions as when you make a warper!
Okay, let's start!
Start with this function:
Code:
Code:
function Buff_Gossip(unit, event, player)
unit:GossipCreateMenu(100, player, 0)
unit:GossipMenuAddItem(0,"Buffs", 0, 0)
unit:GossipMenuAddItem(0,"Heals", 1, 0)
unit:GossipSendMenu(player)
end
Red: Now Buff_Gossip is the function name, but since you allready know what that is
Blue: This is the menu name, this could be anything.
Yellow: This is the menu number. If you follow the guide on how to make a teleporter NPC you should know what this is! (If you didn't follow the guide on how to teleporter NPC you should know that all menu's should have >>>DIFFERENT<< numbers, it's very important that you do not make two menu's with the same menu number)
And now to the submenus:
Code:
Code:
function Buff_Submenus(unit, event, player, id, intid, code)
Now we need to add this line bellow:
Code:
Code:
if(intid == 0) then
Red: As you see, "0" is the number that the menu "Buffs" has as menu number. This means that something happends, when u press "Buffs".
Now let's add, WHAT is supposed to happend when you press "Buffs" (0)
Note: You could make the NPC show you more menu's, so you had different choises on which buff you want, but i will just show you how to make the function buff you. If you followed the guide on how to make a teleporter NPC you should know how to make the function give you more menu's.
To make the NPC buff you (this is also used when you want the NPC to heal you) we will use this line:
Code:
Code:
Unit:FullCastSpellOnTarget(SpellID, player)
Note: I will use "" as my spell ID (Songflower Serenade)
Bellow that add this:
Code:
Code:
player:GossipComplete()
end
Then hit enter two times and register the functions:
Code:
Code:
RegisterUnitGossipEvent(YourNPC'sSpawnID, 1, "Buff_Gossip")
RegisterUnitGossipEvent(YourNPC'sSpawnID, 2, "Buff_Submenus")
Note: I will use 5600 as my NPC's spawn ID!
And now let's put it all together!:
Code:
Code:
function Buff_Gossip(unit, event, player)
unit:GossipCreateMenu(100, player, 0)
unit:GossipMenuAddItem(0,"Buffs", 0, 0)
unit:GossipMenuAddItem(0,"Heals", 1, 0)
unit:GossipSendMenu(player)
end
function Buff_Submenus(unit, event, player, id, intid, code)
if(intid == 0) then
Unit:FullCastSpellOnTarget(20217, player)
player:GossipComplete()
end
Code:
RegisterUnitGossipEvent(5600, 1, "Buff_Gossip")
RegisterUnitGossipEvent(5600, 2, "Buff_Submenus")
To make the NPC cast a healing spell we will use the same function as when you want the NPC to buff you:
Code:
Code:
if(intid == 1) then
Unit:FullCastSpellOnTarget(SpellID, player)
player:GossipComplete()
end
Red: As you see, "1" is the number that the menu "Heals" has as menu number. This means that something happends, when u press "Heals".
Blue: Instead of placing a buff spell ID you just place a healing spell id here! Simpel! Isen't it?
Note: I will use "27136" as my healing spell.
Now let's add this to the script:
Code:
function Buff_Gossip(unit, event, player)
unit:GossipCreateMenu(100, player, 0)
unit:GossipMenuAddItem(0,"Buffs", 0, 0)
unit:GossipMenuAddItem(0,"Heals", 1, 0)
unit:GossipSendMenu(player)
end
function Buff_Submenus(unit, event, player, id, intid, code)
if(intid == 0) then
Unit:FullCastSpellOnTarget(20217, player)
player:GossipComplete()
end
if(intid == 1) then
Unit:FullCastSpellOnTarget(27136, player)
player:GossipComplete()
end
Code:
RegisterUnitGossipEvent(5600, 1, "Buff_Gossip")
RegisterUnitGossipEvent(5600, 2, "Buff_Submenus")
Red: This is were to place the healing function!
3.4
This will show you how to make a morpher:
I will be using the script from before:
Code:
Code:
function Buff_Gossip(unit, event, player)
unit:GossipCreateMenu(100, player, 0)
unit:GossipMenuAddItem(0,"Buffs", 0, 0)
unit:GossipMenuAddItem(0,"Heals", 1, 0)
unit:GossipMenuAddItem(0,"Morph Me", 2, 0)
unit:GossipSendMenu(player)
end
function Buff_Submenus(unit, event, player, id, intid, code)
if(intid == 0) then
Unit:FullCastSpellOnTarget(20217, player)
player:GossipComplete()
end
if(intid == 1) then
Unit:FullCastSpellOnTarget(27136, player)
player:GossipComplete()
end
if(intid == 2) then
player:SetModel(DisplayIDGoesHere)
player:GossipComplete()
end
Code:
RegisterUnitGossipEvent(5600, 1, "Buff_Gossip")
RegisterUnitGossipEvent(5600, 2, "Buff_Submenus")
This is the new menu. As you see this has the number "2" as menu number!
"player:SetModel(DisplayIDGoesHere)" is how the new function looks like. Just place your new displayid in "(DisplayIDGoesHere)" and it will transform you into the new displayid when you press "2"
This will pretty much teach you how to make a morpher.