Lua, a case sensitive language used for many things. I will be teaching you how to script a Gossip NPC in Lua. Lets start
I will try to explain things in simplest terms, I'm gunna make sure everything in this guide is understandable so you will be able to make a gossip npc with ease.
Teleporter -
Code:
--[[
You can put anything you want here! It will NOT affect the script, it may go on for as long as you, just make sure to close it at the end !
--]]
Code:
local Teleporter_ID = IDhere.
function Teleporter_OnTalk(Unit, Event, Player)
Unit:GossipCreateMenu(100, player, 0)
Hold up, Before I continue let me explain those two things.
Code:
function Teleporter_OnTalk(Unit, Event, Player)
A function is basically what helps the script … well …. function! It's the skeleton of the script, without it, the script will be unable to function
Code:
Unit:GossipCreateMenu(100, player, 0)
This basically creates the menu for the player, thus, you will be able to add items to menu such as Take me to the mall … ETC.
Let's Continue
Code:
local Teleporter_ID = IDhere.
function Teleporter_OnTalk(Unit, Event, Player)
Unit:GossipCreateMenu(100, player, 0)
Unit:GossipMenuAddItem(0, "Take me to the mall.", 1, 0)
Unit:GossipMenuAddItem(0, "Remove my Rez Sickness", 2, 0)
Unit:GossipMenuAddItem(0, "Nevermind, I don't want to talk to you, 3, 0)
Unit:GossipSendMenu(player)
end
Give me time to explain,
Code:
Unit:GossipMenuAddItem(0, "Take me to the mall.", 1, 0)
This adds the item to the menu, Take me to the mall.
If the player right clicks the NPC this will come up, however, if you click it nothing will happen … yet
The 0 before the text is the logo beside the text.
Id's for different logos :
0 = Chat bubble
1 = Bag
2 = Wings
3 = Book
4 = Cog/Gear
5 = Cog/Gear
6 = Bag with coin
7 = Chat bubble with "..." (took this list off neglected ;D)
The 1 after the text is the INTID the INTID is very important. You must use a unique INTID every time you add another item. The INTID is used to make your item do the specified thing. You'll understand later if you don't right now.
Code:
Unit:GossipSendMenu(player)
This is basically sending the menu to the player so he sees it, Easy stuff.
Let's Continue.
Code:
local Teleporter_ID = IDhere.
function Teleporter_OnTalk(Unit, Event, Player)
Unit:GossipCreateMenu(100, player, 0)
Unit:GossipMenuAddItem(0, "Take me to the mall.", 1, 0)
Unit:GossipMenuAddItem(0, "Remove my Rez Sickness", 2, 0)
Unit:GossipMenuAddItem(0, "Nevermind, I don't want to talk to you, 3, 0)
Unit:GossipSendMenu(player)
end
function Teleporter_OnSelect(Unit, Event, player, id, intid, code, pMisc)
You have to add a whole new function for the item on the teleporter to do something, It's simple.
Lets continue on, This is where it may get confusing.
Code:
local Teleporter_ID = IDhere.
function Teleporter_OnTalk(Unit, Event, Player)
Unit:GossipCreateMenu(100, player, 0)
Unit:GossipMenuAddItem(0, "Take me to the mall.", 1, 0)
Unit:GossipMenuAddItem(0, "Remove my Rez Sickness", 2, 0)
Unit:GossipMenuAddItem(0, "Nevermind, I don't want to talk to you, 3, 0)
Unit:GossipSendMenu(player)
end
function Teleporter_OnSelect(Unit, Event, player, id, intid, code, pMisc)
if (intid == 1) then
player:Teleport(MAPID, x, y, z)
Unit:GossipComplete()
end
Alright, Lets break this down.
Code:
if (intid == 1) then
Remember the 1 you put infront of Take me to the mall?, That matches the intid to that. There both the same, The intid of the mall and the intid here, so this function must teleport to person to the mall.
Code:
player:Teleport(MAPID, x, y, z)
Once the player clicks the item, if the intid's match then the player gets teleported to the specified coordinates and the gossip is completed and the player is teleported successfully
Code:
Unit:GossipComplete()
Basically completes the gossip so the teleporter stops talking to you, Don't forget it
Now then, heres the script so far.
Code:
local Teleporter_ID = IDhere.
function Teleporter_OnTalk(Unit, Event, Player)
Unit:GossipCreateMenu(100, player, 0)
Unit:GossipMenuAddItem(0, "Take me to the mall.", 1, 0)
Unit:GossipMenuAddItem(0, "Remove my Rez Sickness", 2, 0)
Unit:GossipMenuAddItem(0, "Nevermind, I don't want to talk to you, 3, 0)
Unit:GossipSendMenu(player)
end
function Teleporter_OnSelect(Unit, Event, player, id, intid, code, pMisc)
if (intid == 1) then
player:Teleport(MAPID, x, y, z)
Unit:GossipComplete()
end
Lets make it so it takes off the resurrection sickness!
Think … What was the intid on the resurrection sickness? think …. think … 2!
So lets add this to our script
Code:
if (intid == 2) then
if (player:HasAura(15007) == true) then
player:SendBroadcastMessage("Your Resurrection Sickness has been Removed!")
player:RemoveAura(15007)
Unit:GossipComplete()
else
player:SendBroadcastMessage("Stop lying! You don't have resurrection sickness!")
Unit:GossipComplete()
end
end
end
Kk, Time to explain this, it's not that hard once you understand it.
Code:
if (intid == 2) then
This part you already know, the intid is 2, same thing at the Remove my Rez Sickness!
Code:
if (player:HasAura(15007) == true) then
This part is stating, IF the player has the aura 15007, which is resurrection sickness, is true, aka he has it, THEN
Code:
player:SendBroadcastMessage("Your Resurrection Sickness has been Removed!")
player:RemoveAura(15007)
It sends a message to the player saying Your resurrection sickness has been removed
and it also removes it. Easy stuff
This is saying if it does not follow the specifications, aka the player clicks the option to remove resurrection sickness but does not have it
it will
Code:
player:SendBroadcastMessage("Stop lying! You don't have resurrection sickness!")
Send a message to the player telling him he does not have it.
And the usual, Unit:GossipComplete() so the gossip is completed once you click the option.
Why the three ends?
The If needs an end
the ELSE needs an end
and the chunk of the script needs an end
thus resulting in three ends.
Now for the last part, the Nevermind part, It's very easy.
Code:
if (intid == 3) then
Unit:GossipComplete()
end
That is VERY easy, I don't even need to explain it, I will a bit though, Once you click the Nevermind option it will simply end gossip, Easy stuff.
What your script should look like.
Code:
local Teleporter_ID = IDhere.
function Teleporter_OnTalk(Unit, Event, Player)
Unit:GossipCreateMenu(100, player, 0)
Unit:GossipMenuAddItem(0, "Take me to the mall.", 1, 0)
Unit:GossipMenuAddItem(0, "Remove my Rez Sickness", 2, 0)
Unit:GossipMenuAddItem(0, "Nevermind, I don't want to talk to you, 3, 0)
Unit:GossipSendMenu(player)
end
function Teleporter_OnSelect(Unit, Event, player, id, intid, code, pMisc)
if (intid == 1) then
player:Teleport(MAPID, x, y, z)
Unit:GossipComplete()
end
if (intid == 2) then
if (player:HasAura(15007) == true) then
player:SendBroadcastMessage("Your Resurrection Sickness has been Removed!")
player:RemoveAura(15007)
Unit:GossipComplete()
else
player:SendBroadcastMessage("Stop lying! You don't have resurrection sickness!")
Unit:GossipComplete()
end
end
end
if (intid == 3) then
Unit:GossipComplete()
end
Mkay… Now how will the Lua know which NPC to put this on to? This is where RegisterUnitGossipEvent's come into play.
Code:
RegisterUnitGossipEvent(Teleporter_ID, 1, "Teleporter_OnTalk)
RegisterUnitGossipEvent(Teleporter_ID, 2, "Teleporter_OnSelect)
You put Teleporter_ID, You LEAVE that there because at the top you have
local Teleporter_ID = Insert Your Teleporter ID here so you can use it throughout the script without actually putting the id in, you can just put Teleporter_ID.
Hoooray, Your done! Should look like this
Code:
local Teleporter_ID = IDhere.
function Teleporter_OnTalk(Unit, Event, Player)
Unit:GossipCreateMenu(100, player, 0)
Unit:GossipMenuAddItem(0, "Take me to the mall.", 1, 0)
Unit:GossipMenuAddItem(0, "Remove my Rez Sickness", 2, 0)
Unit:GossipMenuAddItem(0, "Nevermind, I don't want to talk to you, 3, 0)
Unit:GossipSendMenu(player)
end
function Teleporter_OnSelect(Unit, Event, player, id, intid, code, pMisc)
if (intid == 1) then
player:Teleport(MAPID, x, y, z)
Unit:GossipComplete()
end
if (intid == 2) then
if (player:HasAura(15007) == true) then
player:SendBroadcastMessage("Your Resurrection Sickness has been Removed!")
player:RemoveAura(15007)
Unit:GossipComplete()
else
player:SendBroadcastMessage("Stop lying! You don't have resurrection sickness!")
Unit:GossipComplete()
end
end
end
if (intid == 3) then
Unit:GossipComplete()
end
RegisterUnitGossipEvent(Teleporter_ID, 1, "Teleporter_OnTalk)
RegisterUnitGossipEvent(Teleporter_ID, 2, "Teleporter_OnSelect)
Now that you know how to make one, Let's try a BUFF npc, Some different Unit Commands.
So, We start off
Code:
local Buff_NPC = Buff NPC Id here, Easy stuff, no need to explain.
function BuffNPC_OnTalk(Unit, Event, Player)
Unit:GossipCreateMenu(100, player, 0)
Unit:GossipMenuAddItem(0, "Buff Meh", 1)
Unit:GossipMenuAddItem(0, "I don't need buffs, 2)
Unit:GossipSendMenu(player)
end
That's the first part, It's real easy, You should know it all, Remember, you need unique intid's etc… Easy easy stuff.
Lets start the next part!
Code:
function BuffNPC_OnSelect(Unit, Event, player, id, intid, code, pMisc)
if (intid == 1) then
player:CastSpell(Insert the buff ID here)
player:CastSpell(Insert the buff ID here)
player:CastSpell(Insert the buff ID here)
player:CastSpell(Insert the buff ID here) -- put as many as you want, just make sure you have the right ids. I won't add the ids here cause I'm too lazy and I don't have internet where I am right now making this guide, In history class. So yeah
player:SendBroadcastMessage("You have been buffed!")
Unit:GossipComplete()
end
end
Alright, Let me explain, You should understand most of it other than the player:CastSpell part, That's a Unit command, You put player:CastSpell(ID) the player will then cast the spell of that ID on himself, So you can put a buff id there, the player will then cast a buff on himself. Once thats done with it will send him a message saying You've been buffed.
Lets continue, The easy part.
Code:
function BuffNPC_OnSelect(Unit, Event, player, id, intid, code, pMisc)
if (intid == 1) then
player:CastSpell(Insert the buff ID here)
player:CastSpell(Insert the buff ID here)
player:CastSpell(Insert the buff ID here)
player:CastSpell(Insert the buff ID here) -- put as many as you want, just make sure you have the right ids. I won't add the ids here cause I'm too lazy and I don't have internet where I am right now making this guide, In history class. So yeah
player:SendBroadcastMessage("You have been buffed!")
Unit:GossipComplete()
end
if (intid == 2) then
Unit:GossipComplete()
player:SendBroadcastMEssage("FIEN, DONT TAKE EPIC BUFFS")
end
RegisterUnitGossipEvent(Buff_NPC, 1, "BuffNPC_OnTalk)
RegisterUnitGossipEvent(Buff_NPC, 2, "BuffNPC_OnSelect)
You've made your second gossip NPC now, Are you getting it? You should be, I would do another example but …. I don't really want to, You should now successfully know how to use Unit commands, It shouldn't be hard.
Go to arcemu.info for Unit Commands, there really helpful.
Use those wisely, A gossip NPC has no limits (theoretically speaking)
Now then, You have fun and I hope you have learned something from this guide.