Hello!
It's time for my first guide evooor o.O
I've been looking around and I didn't find any guides regarind this subject. So I thought I would make an easy guide on how to apply some Gossip Lua on an item!
(NOTE: This guide is easy, for the average Lua scripter. Not a Newbie guide. Before you do this I suggest you make sure that you know how to work with Lua Gossip Menus first as it's not that different from that)
Let's get started.
First we set up our usual menu, when working with Gossip scripts (But adds a few modifications!):
Code:
function Item_Trigger(item, event, player)
Item_menu(item, player)
end
function Item_menu(item, player)
if (player:IsInCombat() == true) then
player:SendAreaTriggerMessage("I wont work before you get out of combat, silly!")
player:SendBroadcastMessage("I wont work before you get out of combat, silly!")
else
item:GossipCreateMenu(XXX, player, 0)
item:GossipMenuAddItem(Y, "Mall", 1, 0)
item:GossipMenuAddItem(Y, "Heal me!", 2, 0)
item:GossipMenuAddItem(Y, "Remove Ressurection Sickness!", 3, 0)
item:GossipSendMenu(player)
end
end
Ok, lets break it down.
Code:
function Item_Trigger(item, event, player)
Item_menu(item, player)
end
When making Lua Scripts for Items which includes Gossip this function is essential. It defines that we want a menu to show up, as if you were talking with an NPC! Remember we work with items here so we wont use pUnit or Unit. We use item. (item, player)
Code:
function Item_menu(item, player)
if (player:IsInCombat() == true) then
player:SendAreaTriggerMessage("I wont work before you get out of combat, silly!")
player:SendBroadcastMessage("I wont work before you get out of combat, silly!")
else
This function above should be pretty obvious. It checks if the player is in combat, and if he/she is then it wont work and give him or her the message that it wont work before he or she gets out of combat.
Code:
item:GossipCreateMenu(XXX, player, 0)
item:GossipMenuAddItem(Y, "Mall", 1, 0)
item:GossipMenuAddItem(Y, "Heal me!", 2, 0)
item:GossipMenuAddItem(Y, "Remove Ressurection Sickness!", 3, 0)
item:GossipSendMenu(player)
end
end
So now we have the all familiar Gossip Menu, but with a twist. We use item:Gossip instead of pUnit- or Unit:Gossip, since it's an item and not a unit. The red X's is just the number that has to be unique on every single Gossip Script you ever make that is put into the same Script Folder. The red Y's is just Icons. I don't have a list for that.
So the "body" of our Gossip Menu is now created. Now we have to "Linkt" those options to actions.
Code:
function OnSelect(item, event, player, id, intid, code)
Now we need the function above. A Gossip always got at least two functions to register. This is no different. There is one difference tho. I am sure you can spot it.
Code:
function OnSelect(item, event, player, id, intid, code)
if (intid == 1) then
player:Teleport(mapid,x,y,z,o)
See. Here we don't need the item to do it for us. We continue.
Code:
function OnSelect(item, event, player, id, intid, code)
if (intid == 1) then
player:Teleport(mapid,x,y,z,o)
else
if (intid == 2) then
player:CastSpell(1908) -- Uber Heal Over time
else
if (intid == 3) then
player:LearnSpell(15007) -- Learns Ressurection Sickness
player:UnlearnSpell(15007) -- Unlearns Ressurection Sickness
player:SendAreaTriggerMessage("Good as new!")
player:SendBroadcastMessage("Good as new!")
end
Now we are almost done. We just need the last two functions that will register this.
Code:
RegisterItemGossipEvent(ITEM ID,1,"Item_Trigger")
RegisterItemGossipEvent(ITEM ID,2,"OnSelect")
Remember that we have to use RegisterItemGossipEvent since this is not a Unit. The 1 is OnTalk (Which basically is pressing the item in this case) and 2 is OnSelect. Which is when we choose one of the stated options.
The Result should look like this:
Code:
function Item_Trigger(item, event, player)
Item_menu(item, player)
end
function Item_menu(item, player)
if (player:IsInCombat() == true) then
player:SendAreaTriggerMessage("I wont work before you get out of combat, silly!")
player:SendBroadcastMessage("I wont work before you get out of combat, silly!")
else
item:GossipCreateMenu(XXX, player, 0)
item:GossipMenuAddItem(Y, "Mall", 1, 0)
item:GossipMenuAddItem(Y, "Heal me!", 2, 0)
item:GossipMenuAddItem(Y, "Remove Ressurection Sickness!", 3, 0)
item:GossipSendMenu(player)
end
end
function OnSelect(item, event, player, id, intid, code)
if (intid == 1) then
player:Teleport(mapid,x,y,z,o)
else
if (intid == 2) then
player:CastSpell(1908) -- Uber Heal Over time
else
if (intid == 3) then
player:LearnSpell(15007) -- Learns Ressurection Sickness
player:UnlearnSpell(15007) -- Unlearns Ressurection Sickness
player:SendAreaTriggerMessage("Good as new!")
player:SendBroadcastMessage("Good as new!")
end
RegisterItemGossipEvent(ITEM ID,1,"Item_Trigger")
RegisterItemGossipEvent(ITEM ID,2,"OnSelect")
Now all you need to do, is having an item which can be right-clicked already. Else it wont work. Look around in your Database and check for like...Polar Bear Pet or something. Check what type or class the item is, and see if you can get the same right click function.
I hope this can be used!