How to : Basic Gossip NPC menu

These ads disappear when you log in.

Results 1 to 11 of 11
  1. #1
    Warriar's Avatar Sergeant Major
    Reputation
    31
    Join Date
    May 2009
    Posts
    149
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)

    How to : Basic Gossip NPC

    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

    Code:
    else
    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.
    Last edited by Warriar; 12-28-2016 at 02:24 AM.

    These ads disappear when you log in.

  2. #2
    RyeRye's Avatar Contributor
    Reputation
    240
    Join Date
    Aug 2008
    Posts
    993
    Thanks G/R
    0/1
    Trade Feedback
    2 (100%)
    Very very nice guide. +Repx3
    Check out my powerleveling thread here
    Need $250, Have $0


  3. #3
    Warriar's Avatar Sergeant Major
    Reputation
    31
    Join Date
    May 2009
    Posts
    149
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Thanks, Did it during history class ;D

  4. #4
    mager1794's Avatar Lieutenant Commander
    Reputation
    356
    Join Date
    Feb 2008
    Posts
    703
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Looks nice. and very helpful to any newcomers +Rep
    Lunar Gaming - Reaching For The Stars

  5. #5
    Warriar's Avatar Sergeant Major
    Reputation
    31
    Join Date
    May 2009
    Posts
    149
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Thanks mager

  6. #6
    Dynashock's Avatar Contributor

    Reputation
    176
    Join Date
    Nov 2007
    Posts
    203
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    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.
    Just doing a quick comment on that one. The intid of the menu doesn't have to be unique; sometimes you want multiple menus linked to one intid so you can call the same statements from different menu items. You also forgot to explain what the 3rd number (the one for the codebox) means, it would be nice for newcomers to expand on that one, for it can be quite powerful if used properly.

    Nonetheless, not a bad guide, have some rep.

  7. #7
    psychobandit's Avatar Knight-Lieutenant
    Reputation
    14
    Join Date
    Jun 2007
    Posts
    226
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Originally Posted by Dynashock View Post
    Just doing a quick comment on that one. The intid of the menu doesn't have to be unique; sometimes you want multiple menus linked to one intid so you can call the same statements from different menu items. You also forgot to explain what the 3rd number (the one for the codebox) means, it would be nice for newcomers to expand on that one, for it can be quite powerful if used properly.

    Nonetheless, not a bad guide, have some rep.
    So what IS the 3rd number for? All the Arc wiki says is: "0 is the "extra" entry. You can check the core for more info on this, but unless you know how to use it, it's best to leave this at 0.". There is no explanation in the core either. So???
    .
    .
    .

  8. #8
    Dynashock's Avatar Contributor

    Reputation
    176
    Join Date
    Nov 2007
    Posts
    203
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Originally Posted by psychobandit View Post
    So what IS the 3rd number for? All the Arc wiki says is: "0 is the "extra" entry. You can check the core for more info on this, but unless you know how to use it, it's best to leave this at 0.". There is no explanation in the core either. So???
    .
    .
    .
    The "extra" 0 zero makes a codebox pop up asking for entry if you change it to 1. Did you notice the parameter 'code' in the following function:
    Code:
    function Teleporter_OnSelect(Unit, Event, player, id, intid, code, pMisc)
    If the player enters something in that codebox that just popped up, that which he entered in will be assigned to the variable code in string format. (even if you enter a number, use tonumber(code) to get the number back) You can then use the variable code for various stuff, such as running a DB query, turning in the specified amount of tokens for gold or a password.

    A little example (not the full script, but lines I would add or change with the current posted script) with a little number guessing game:
    Code:
    local NumberToGuess = math.random(1, 100) -- assign a random number between 1 and 100 to variable NumberToGuess
    
    Unit:GossipMenuAddItem(0, "Guess the number!, 4, 1) -- the 1 makes the codebox pop up
    
    if (intid == 4) then
        if tonumber(code) == NumberToGuess then -- remember that code was in stringformat? need to convert it to a number to compare it with the number from NumberToGuess
            player:SendBroadcastMessage("You guessed right!") -- fancy message if correct
            NumberToGuess = math.random(1, 100) -- assign a new value to the number to guess as it's been guessed
            player:GossipComplete() -- close the gossip
        else
            player:SendBroadcastMessage("You guess wrong.") -- error message
            player:GossipComplete() -- close gossip
        end -- 1 end for the if tonumber(code)... statement
    end -- 1 end for the if (intid... statement
    If you want the script to be "failproof" such as someone entering a character instead of a number you could add a nil check to the current check statement. It would look like this then:
    Code:
    if tonumber(code) ~= nil and tonumber(code) == NumberToGuess then
    Because if Lua tries to convert a string (that's also one character!) to a number with tonumber it will return nil. It'll only return a number succesfully if the input really is a number.

  9. #9
    psychobandit's Avatar Knight-Lieutenant
    Reputation
    14
    Join Date
    Jun 2007
    Posts
    226
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Perfect! Thank you, It's nice to know what that damn number is for


    *edit* +Rep

    .
    .
    .
    Last edited by psychobandit; 12-31-2009 at 07:57 PM. Reason: Had to make sure rep worked

  10. #10
    Warriar's Avatar Sergeant Major
    Reputation
    31
    Join Date
    May 2009
    Posts
    149
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Yeah i just recently figured out on my quiz npc I was makin that I could have one intid for multiple menus, thanks ;p

  11. #11
    Skreem's Avatar Sergeant
    Reputation
    17
    Join Date
    Apr 2007
    Posts
    63
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Nice... bump

Similar Threads

  1. [Trinity] How to make a gossip npc that opens vendors?
    By Nokia123 in forum WoW EMU Questions & Requests
    Replies: 4
    Last Post: 06-06-2012, 07:09 AM
  2. How to get a NPC's Displayid and Gameobject's Spawn ID (ingame)
    By taryon in forum World of Warcraft Emulator Servers
    Replies: 4
    Last Post: 03-28-2008, 04:15 PM
  3. {PICS}How to make a NPC Have Armor or a Weapon
    By Dragonscale in forum WoW EMU Guides & Tutorials
    Replies: 20
    Last Post: 12-29-2007, 05:34 AM
  4. How to create custom NPC's the easy way!Works for all versions!
    By MissMurder in forum WoW EMU Guides & Tutorials
    Replies: 2
    Last Post: 12-05-2007, 08:06 PM
  5. How do I make npcs?
    By noobert in forum World of Warcraft Emulator Servers
    Replies: 8
    Last Post: 09-04-2007, 02:38 PM
All times are GMT -5. The time now is 05:18 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved. Digital Point modules: Sphinx-based search