| | Emulator Server Guides Guides for working with World of Warcraft Emulator servers. Learn how to create a WoW Server here.
[NO QUESTIONS HERE] |  | | 
02-27-2009
|  | Master Sergeant | | | Join Date: Jan 2008 Location: McDonalds.. D:
Posts: 77
Reputation: 30 | | Thekals Lua Tutorial This guide will show you how to do various Things in lua
---------- 1 Scripting NPC's - Say something
- Cast spells
- Summon other mobs
- Make phases (Change its scale, displayid Etc..)
2. Script GOs 3 Teleporter NPC
----------
If well accepted i will keep this updated!
And off we go. A script in lua does something that you cant do with just in game commands.
It is what make boss encounters more then just you walk in and kill them.
Here is what a function looks as a blank slate - With NO data entered into it. Code: function Nameofthefunction(Unit, Event)
end
Lets say my NPC is called Demon. Code: function Demon_OnCombat(Unit, Event)
end
The name of my NPC is now in the script.
Note: Nameofthefunction or Demon_Oncombat actually can be anything. It really helps to keep it organized if you do it this way. NEXT PART!
To make the NPC say something when engaged heres what you do.. Code: Unit:SendChatMessage(12, 0, "Heres where the text goes.")
The 12 in that script. Right at the beginning of the parenthesis, Is how you want the NPC to talk....
Be it... Code: 12 – npc say
13 – npc whisper
14 - npc yell
Universal means anyone can here it.
Heres some other languages. Probably wont be used as much. Code: 0 = Universal
1 = Orcish
2 = Darnassian
3 = Taurahe
6 = Dwarven
7 = Common
8 = Demonic
9 = Titans
13 = Gnomish
14 = Zalandari
33 = Gutterspeak
35 = Draenei
Now we add the Chat on engage to the OnCombat Script Code: function Demon_OnCombat(Unit, Event)
Unit:SendChatMessage(14, 0, "Text goes Here!")
end
And again. The "SendChatMessage" does not have to be those exact words. It just helps to keep things organized for yourself or others reading the script.
To get the script to be able to function you have to Register it.
Registering the Function has to be at least one line below the function itself.
For each function you need to have a Different Register command.
The Register commands do not need a line between them unlike the functions Code: RegisterUnitEvent(NPC-IDHERE, 1, "Function name")
The Function name for example from our earlier script is "Demon_OnCombat
After the ID there is a 1 if you notice. that defines what the "unit" event in the function. This is what makes the functions different.
Here is a list: 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
This is what a Function would look like for
Demon - ID 9995
Script - Activates on combat.
Details - On combat "Demon says "Darkness Reigns!" Code: function Demon_OnCombat(Unit, Event)
Unit:SendChatMessage(14, 0, "Darkness Reigns!")
end
RegisterUnitEvent(9995, 1, "Demon_OnCombat")
here are some different Examples of different Function events. Code: function Demon_OnLeaveCombat(Unit, Event)
Unit:RemoveEvents()
end
function Demon_OnKilledTarget(Unit, Event)
end
function Demon_OnDied(Unit, Event)
Unit:RemoveEvents()
end
They speak for themselves in what they do.
The RemoveEvents are for if the scripts make the NPC change size or Change displayid it will reset it.
To register the last 3 scripts do the next code. Code: RegisterUnitEvent(NPC-IDHERE, 2, "_OnLeaveCombat")
RegisterUnitEvent(NPC-IDHERE, 3, "_OnKilledTarget")
RegisterUnitEvent(NPC-IDHERE, 4, "_OnDied")
Putting it all together with every script we have done so far would look like the following. Code: function Demon_OnCombat(Unit, Event)
Unit:SendChatMessage(14, 0, "I Will Kill You!")
end
function Demon_OnLeaveCombat(Unit, Event)
Unit:RemoveEvents()
end
function Demon_OnKilledTarget(Unit, Event)
end
function Demon_OnDied(Unit, Event)
Unit:RemoveEvents()
end
RegisterUnitEvent(9995, 1, "Demon_OnCombat")
RegisterUnitEvent(9995, 2, "Demon_OnLeaveCombat")
RegisterUnitEvent(9995, 3, "Demon_OnKilledTarget")
RegisterUnitEvent(9995, 4, "Demon_OnDied")
Here is where it gets more in depth by adding spells.
Spells require a different function obviously. Code: function Nameofthefunction(Unit, Event)
end
Back to stage 1. make a Brand New Function like above. Code: function Demon_Spell1(Unit, Event)
end
Code: Unit:FullCastSpellOnTarget(spellid, Unit:Target)
The Target in "Unit:Target" Can be one of the following. 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() = targets Main tank.
- GetClosestPlayer() = Targets whoever is closest.
If - for example the boss was going to attack the closest person Code: function Demon_Spell1(Unit, Event)
Unit:FullCastSpellOnTarget(5, Unit:GetClosestPlayer())
end
In detail - In a certain amount of milliseconds and how many times in that amount of times it is casted. Code: Unit:RegisterEvent("functionname", MIlliseconds, howmanyoftimesinthat time)
Heres what it would look like to let the NPC cast the spell 2 times in a total of 60 seconds Code: Unit:RegisterEvent("Demon_Spell1", 60000, 2)
To make it activate OnCombat (as in when engaged - be it Aggroed or attacked deliberately.) Code: function Demon_OnCombat(Unit, Event)
Unit:SendChatMessage(14, 0, "Darkness Reigns")
function Demon_Spell1(Unit, Event)
Unit:FullCastSpellOnTarget(5, Unit:GetClosestPlayer())
end
function Demon_OnLeaveCombat(Unit, Event)
Unit:RemoveEvents()
end
function Demon_OnKilledTarget(Unit, Event)
end
function Demon_OnDied(Unit, Event)
Unit:RemoveEvents()
end
RegisterUnitEvent(9995, 1, "Demon_OnCombat")
RegisterUnitEvent(9995, 2, "Demon_OnLeaveCombat")
RegisterUnitEvent(9995, 3, "Demon_OnKilledTarget")
RegisterUnitEvent(9995, 4, "Demon_OnDied")
RegisterUnitEvent("Demon_Spell1", 60000, 2)
end
BOSS PHASES!
Boss phase time! Code: function FunctionName(Unit, Event)
if Unit:GetHealthPct() <= X then
end
end
X is where the NPC will check his Health and act according to what we will script.
Gonna use 35%
Now the X is replaced with 35 Code: function Demon_Phase1(Unit, Event)
if Unit:GetHealthPct() <= 35 then
end
end
At 35% we want the Boss to cast a spell. so we do.... Code: Unit:FullCastSpellOnTarget(spellID, Unit:target)
FullCastSpellOnTarget is a command when its a spell with a cast time (not instant =/)
For an Instant Cast use CastSpell command / like so. Code: function Demon_Phase1(Unit, Event)
if Unit:GetHealthPct() <= 35 then
Unit:CastSpell(27082)
end
end
Also You can make him send a message before or after casting the spell. Code: Unit:SendChatMessage(14, 0, "Write whatever you want.")
And now the function should look like this: Code: function Demon_Phase1(Unit, Event)
if Unit:GetHealthPct() <= 35 then
Unit:SendChatMessage(14, 0, "Casting Spell!")
Unit:CastSpell(27082)
end
end
Also - you can make the NPC change Displayid or their scale
Change its scale: Code: Unit:SetScale(scalenumber)
Modify its displayid: Code: Unit:SetModel(displayID)
Lets add it to the previous script. Code: function Demon_Phase1(Unit, Event)
if Unit:GetHealthPct() <= 35 then
Unit:SetModel(145)
Unit:SetScale(2)
Unit:SendChatMessage(14, 0, "Casting Spell!")
Unit:CastSpell(27082)
end
end
The RegisterEvent Looks like this.
Unit:RegisterEvent(" Demon_Phase1", timeinmilliseconds, howmanytimes)
adding it to the script! Code: function Demon_OnCombat(Unit, Event)
Unit:SendChatMessage(14, 0, "Casting Spell!")
Unit:RegisterEvent("Demon_Spell1", 60000, 2)
Unit:RegisterEvent("Demon_Summon", 60000, 2)
Unit:RegisterEvent("Demon_Summon2", 60000, 2)
Unit:RegisterEvent("Demon_Phase1", 5000, 1)
end
function Demon_Phase1(Unit, Event)
if Unit:GetHealthPct() <= 50 then
Unit:SetModel(145)
Unit:SetScale(2)
Unit:SendChatMessage(14, 0, "I shall kill you!")
Unit:CastSpell(27082)
end
end
function Demon_Summon2(Unit, Event)
Unit:SpawnCreature (9994, -8919.73, 47.95, 94.14, 0.48, 14, 60000);
end
function Demon_Summon(Unit, Event)
local x = Unit:GetX();
local y = Unit:GetY();
local z = Unit:GetZ();
local o = Unit:GetO();
Unit:SpawnCreature (9994, x, y, z, o, 14 ,60000);
end
function Demon_Spell1(Unit, Event)
Unit:FullCastSpellOnTarget(5, Unit:GetClosestPlayer())
end
function Demon_OnLeaveCombat(Unit, Event)
Unit:RemoveEvents()
end
function Demon_OnKilledTarget(Unit, Event)
end
function Demon_OnDied(Unit, Event)
Unit:RemoveEvents()
end
RegisterUnitEvent(9995, 1, "Demon_OnCombat")
RegisterUnitEvent(9995, 2, "Demon_OnLeaveCombat")
RegisterUnitEvent(9995, 3, "Demon_OnKilledTarget")
RegisterUnitEvent(9995, 4, "Demon_OnDied")
[/code]
BTW
For the Pink Text - you can use one of these 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() = targets Main tank.
- GetClosestPlayer() = Targets whoever is closest.
PORTAL SCRIPTS Code: function ScriptName(pUnit, Event, pMisc)
pMisc:Teleport(MapID, X-Coord, Y-Coord, Z-Coord)
end
RegisterGameObjectEvent(GameObjectsENTRYID, 2, "ScriptName")
Look at the first line one more time. Code: function ScriptName(pUnit, Event, pMisc)
Name it whatever you want - as previously said.
For example. Code: function TELEPORT(pUnit, Event, pMisc)
The Next line has more in it. So.... Code: pMisc:Teleport(MapID, X-Coord, Y-Coord, Z-Coord)
end
To find the X-Coord, Y-Coord, and the Z-Coord type .gps in game.
Again you need to register it. Code: RegisterGameObjectEvent(GO ID, 2, "ScriptName")
What ever GO id you use for the portal should go here Needs to be what you named the script earlier.
Heres an example of a completed Portal Script. Code: function MALLTele(pUnit, Event, pMisc)
pMisc:Teleport(530, -2009.403320, 6590.512695, 12.360116)
end
RegisterGameObjectEvent(999998, 2, "MALLTele")
Teleporter NPC - How-To
Start with- Code: function On_Gossip(unit, event, player)
Is the beginning of the Function. Code: unit:GossipCreateMenu(High#, player, 0)
Now the chat options need to be defined. Code: unit:GossipMenuAddItem(0,"Horde Cities", 0, 0)
After clicking Horde Cities it heads into a Submenu. Code:
unit:GossipSendMenu(player)
end
Code: function On_Gossip(unit, event, player)
unit:GossipCreateMenu(100, player, 0)
unit:GossipMenuAddItem(0,"Horde Cities", 0, 0)
unit:GossipSendMenu(player)
end
Onto the Sub-Menus. Code: function Gossip_Submenus(unit, event, player, id, intid, code)
And now we will edit the Horde Cities, so that it will port us to Ex: Undercity.
write this: Code: if(intid == 0) then
a Zero means that it opens a Sub menu.
Containing....... Code: unit:GossipCreateMenu(Different then the Gossipmenu one, player, 0)
Now we will start the actual location selections. Code: unit:GossipMenuAddItem(0,"Orgrimmar", 50, 0)
unit:GossipMenuAddItem(0,"Undercity", 51, 0)
unit:GossipMenuAddItem(0,"Thunder Bluff", 52, 0)
unit:GossipMenuAddItem(0,"Silvermoon", 53, 0)
unit:GossipSendMenu(player)
end
Now mine looks like this: 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,"Orgrimmar", 50, 0)
unit:GossipMenuAddItem(0,"Undercity", 51, 0)
unit:GossipMenuAddItem(0,"Thunder Bluff", 52, 0)
unit:GossipMenuAddItem(0,"Silvermoon", 53, 0)
unit:GossipSendMenu(player)
end
Now you put in the info for each selection.
Note: You can see that the menu number of Orgrimmar is 50, Undercity is 51, Thunder Bluff is 52, Silvermoon is 53.
Now write this: Code: if(intid == 50) then
player:Teleport(1, 9985.907227, 1971.155640, 1326.815674)
end
X Y Z
This would go to Orgrimmar
Repeat the above until you have one for each.
To register them.. Code: RegisterUnitGossipEvent(Your NPC Spawn ID, 1, "On_Gossip")
RegisterUnitGossipEvent(Your NPC Spawn ID, 2, "Gossip_Submenus")
Now it looks like.. Code: function On_Gossip(unit, event, player)
unit:GossipCreateMenu(100, player, 0)
unit:GossipMenuAddItem(0,"Horde Cities", 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,"Orgrimmar", 50, 0)
unit:GossipMenuAddItem(0,"Undercity", 51, 0)
unit:GossipMenuAddItem(0,"Thunder Bluff", 52, 0)
unit:GossipMenuAddItem(0,"Silvermoon", 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
RegisterUnitGossipEvent(5, 1, "On_Gossip")
RegisterUnitGossipEvent(5, 2, "Gossip_Submenus")
PS: THE TELEPORTER SCRIPTS OR ANYTHING WITH A COORDINATE ENTRY DOES NOT WORK RIGHT (IE: Doesnt take you to where it says) Just thought u ought to know.
If well Accepted i will update this will more NPCs and More Scripts.
Thanks!
-Thekal
Last edited by Thekal; 02-27-2009 at 10:19 PM.
| Donate to remove ads, get your "DONATOR title, and get access to the MMOwned community's elite Shoutbawx. 
02-27-2009
| | Site n00b.. (A leecher if I've been here for more than a month and can't earn 5 rep) | | | Join Date: Feb 2009
Posts: 1
Reputation: 1 | | wow! thanks man, this really helped! | 
02-27-2009
|  | Site n00b.. (A leecher if I've been here for more than a month and can't earn 5 rep) | | | Join Date: Nov 2007
Posts: 26
Reputation: 3 | | Thanks alot dude!
Real great help! | 
02-27-2009
|  | Contributor | | | Join Date: Jun 2007
Posts: 242
Reputation: 86 Level up: 41%, 477 Points needed |     | | Very nice guide, Thekal.
Good job and
-Tator
__________________ Gold Scammed - 23,000g
Accounts Scammed - 5
Working my way up the ladder! | 
02-27-2009
| | Contributor | | | Join Date: Apr 2008
Posts: 242
Reputation: 94 Level up: 76%, 120 Points needed |  | | well done Thekal | 
02-28-2009
|  | Master Sergeant | | | Join Date: Jan 2008 Location: McDonalds.. D:
Posts: 77
Reputation: 30 | | | Thanks for the nice words guys. I think i might start to add onto it.
Ill add a morpher NPC. | 
02-28-2009
| | Master Sergeant | | | Join Date: Jun 2008
Posts: 105
Reputation: 11 Level up: 68%, 164 Points needed |    | | | Noob question: So Ive got a lua, what do I do to put it ingame?
__________________ Hey whats sup Im a wow addict wanna go out some time? | 
02-28-2009
|  | Contributor | | | Join Date: Sep 2006 Location: in ur cmputer
Posts: 1,434
Reputation: 256 Points: 10,053, Level: 12 | Level up: 22%, 947 Points needed |     | | There's plenty of tutorials like this, in arcemu forums and other :P But nice anyway. +rep | 
02-28-2009
|  | Master Sergeant | | | Join Date: Jan 2008 Location: McDonalds.. D:
Posts: 77
Reputation: 30 | | | Surfsem
In your Scripts Folder for your private server is where you put it.
I can't Go into detail on where your scripts folder because its different for every person. | 
02-28-2009
|  | Master Sergeant | | | Join Date: Sep 2008 Location: London
Posts: 130
Reputation: 13 | | Quote:
Originally Posted by surfsem Noob question: So Ive got a lua, what do I do to put it ingame? | Well if you're using a repack, it should be near the logon and world.exe
Insert the script into your scripts folder, if there is no present scripts folder, creat one. | 
02-28-2009
| | Master Sergeant | | | Join Date: Jun 2008
Posts: 105
Reputation: 11 Level up: 68%, 164 Points needed |    | | Quote:
Originally Posted by josh253 Well if you're using a repack, it should be near the logon and world.exe
Insert the script into your scripts folder, if there is no present scripts folder, creat one. | In my scripts folder, theres 2 more folders, _Arc_lua-scripts and _Sun++LUA Scripts. Which do I put it in?
__________________ Hey whats sup Im a wow addict wanna go out some time? | 
03-01-2009
|  | Contributor | | | Join Date: Aug 2008 Location: USA
Posts: 1,057
Reputation: 213 Level up: 49%, 411 Points needed |     | | | You can put in both, just make sure there are no scripts for the same thing (conflicting scripts).
__________________ To Write Love On Her Arms <3  | 
03-06-2009
|  | Site n00b.. (A leecher if I've been here for more than a month and can't earn 5 rep) | | | Join Date: Sep 2006 Location: The Barrens
Posts: 121
Reputation: 4 | | | Sorry I don't see the "Summon Creature" script part very well explained >.< could you be a little more detailed? Thanks! | 
03-16-2009
| | New User | | | Join Date: Mar 2009 Location: Norway
Posts: 13
Reputation: 1 Level up: 44%, 228 Points needed | | | | I dont freakking get it :S:S Code: function On_Gossip(unit, event, player)
unit:GossipCreateMenu(3544, player, 0)
unit:GossipMenuAddItem(2, "PvP Places", 1, 0)
unit:GossipMenuAddItem(2, "Capital bar", 2, 0)
unit:GossipSendMenu(player)
end
function Gossip_Submenus(unit, event, player, id, intid, code, misc)
if(intid == 0) then
unit:GossipCreateMenu(3543, player, 0)
unit:GossipMenuAddItem(2, "PvP Places", 1, 0)
unit:GossipMenuAddItem(2, "Azeroth Locations", 2, 0)
unit:GossipSendMenu(player)
end
if(intid == 1) then
unit:GossipCreateMenu(3543, player, 0)
unit:GossipMenuAddItem(1, "Diremaul", 300, 0)
unit:GossipMenuAddItem(0, "[Back]", 999, 0)
unit:GossipSendMenu(player)
end
if(intid == 2) then
unit:GossipCreateMenu(3543, player, 0)
unit:GossipMenuAddItem(1, "Capital bar", 301, 0)
unit:GossipMenuAddItem(0, "[Back]", 999, 0)
unit:GossipSendMenu(player)
end
if(intid == 300) then
player:Teleport(1, 16205.507966, 16214.343750, 1.111040)
unit:GossipComplete(player)
end
if(intid == 301) then
player:Teleport(1, -3785.331055, 1092.848999, 131.969467)
unit:GossipComplete(player)
end
end
RegisterUnitGossipEvent(333333, 1, "On_Gossip")
RegisterUnitGossipEvent(333333, 2, "Gossip_Submenus")
  What`s wrong in this one ??  | 
03-17-2009
| | Sergeant | | | Join Date: Feb 2009
Posts: 68
Reputation: 10 Level up: 56%, 177 Points needed | | | This is the most epic guide ever made for LUA 
This surely tought me most of what I know right now |  | |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | All times are GMT -4. The time now is 08:03 AM. |