[Guide] Scripting Items In LUA menu

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    Scubast3ve's Avatar Member
    Reputation
    55
    Join Date
    Apr 2009
    Posts
    125
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Guide] Scripting Items In LUA

    Hey guys when i first started LUA i couldnt find any guides for scripting items so ill give you all a quick but detailed run through on some of the commands specific to this


    To begin the first 2 things you will need to know is how to define a function and how to register that function:

    Code:
    function Item_OnUse(Item,Event,player)
    This creates a function called "Item_OnUse", the three names within the brackets "Item", "Event" and "player" are all variables which the data from which ever unit uses that function. "Item" stores the unit data, "Event" stores the event data and player stores the account data as to which player used the item.

    All functions must end in

    Code:
    end
    Now this function does nothing in this state because nothing is calling it. So here here is how to register that function so that your core knows what to do:

    Code:
    RegisterItemGossipEvent(125667, 1, "Item_OnUse")
    Now in this line of code the core is told that when the item 125667 is clicked the function "Item_OnUse" is called.

    So to brake down each peice:
    RegisterItemGossipEvent = A command that tells the core that an item is controlled in the function specified, and it is being used for making a menu
    125667 = The itemid of the item being used.
    1 = The way in which the object is being interacted with, 1 states the item has been clicked
    "Item_OnUse" = The function being called.

    Now we know how to begin a function and register it lets try adding a menu to the item.

    The first line we will be using looks like this
    Code:
    item:GossipCreateMenu(100, player, 0)
    This line of code creates a menu it does not dislpay anything but stores data when items are added to the menu.

    To brake down the data:
    item = the variable which was defined before
    GossipCreateMenu = A command defining what the item should do, in the case it add a new menu into memory
    100 = the menus id
    player = the variable which we defined before
    0 = a value that should always be 0

    Now that we can create menus why not add lines to them:
    Code:
    item:GossipMenuAddItem(0, "My First Menu Item", 1, 0)
    This peice of code adds a line to the menu.

    To brake down each peice:
    item = the variable which was defined before
    GossipMenuAddItem = A command which adds a line to the menu which we have already created
    0 = the picture used before the text of the menu item, 0 is a speech bubble
    "My First Menu Item" = The words that will be displayed for the menu
    1 = The menu item id (if the item is clicked the value 1 is stored in a variable called "intid")
    0 = a value that should stay at 0

    Now that we have a menu with an item in it we can display the contents of that item to the player:
    Code:
    item:GossipSendMenu(player)
    This sends what we have now made to the player..

    To brake down each peice
    item = the variable which was defined before
    GossipSendMenu = This peice of code tells the core to send the menu and its items to the player defined
    player = the variable which we defined before

    So now you should have a peice of code that looks like this
    Code:
    function Item_OnUse(Item,Event,player)
    item:GossipCreateMenu(100, player, 0)
    item:GossipMenuAddItem(0, "My First Menu Item", 1, 0)
    item:GossipSendMenu(player)
    end
    
    RegisterItemGossipEvent(125667, 1, "Item_OnUse")
    This is the structure that all your lua should take now i will point out a few things on the structure.

    A function always needs to be registered to have any effect on the item it is being scripted for. You always write what you want to happen inside a function. You must always end a function with end. Inside a function commands are executed from top to bottom so you cannot have a item:GossipSendMenu(player) before a item:GossipCreateMenu(100, player, 0) because you will get no result.

    Now we have made an item in a menu and displayed to the player we must make something happen when a user clicks an item.

    Will will need to register a new event for this:

    Code:
    RegisterItemGossipEvent(125667, 2, "Item_OnUse")
    As you can see it is very similar to the first register but as you can see there is a 2 where the 1 used to be.

    The 2 is in place of the one because this is now a new state, the user has clicked an item in the menu and we want something to happen. So 2 just tells the core where to go once an item has been clicked.

    Now where to go:

    Code:
    function Item_OnSelect(item,Event,Player)
    By now you should know what each of these does so i wont bother explaining but just as a reference the line "Item_OnSelect" could be anything like "Myitem_WhenYouClick" the name isnt important. you must make sure the name is that same in the register aswell.

    First we must define which item has been clicked
    Code:
    if intid == 1 then
    this is made simple because like i told you earlier the number 1 was stored in a variable called intid when clicked so here we are using that functionality to figure out which item has been selected. All ifs must also end in an end

    Now we need it to do something:
    Code:
    player:SendAreaTriggerMessage("You did it!")
    This tells the player to send themselves a message up the top of their screen saying "You did it!" in red.

    To brake this down:

    player = a variable defined in the function.
    SendAreaTriggerMessage = a peice of code that tells the player to display a message saying what ever has been defined.
    "You did it!" = this is what is supposed to be displayed at the top of the players screen.

    Now that we have defined that your script should look like:

    Code:
    function Item_OnUse(Item,Event,player)
    item:GossipCreateMenu(100, player, 0)
    item:GossipMenuAddItem(0, "My First Menu Item", 1, 0)
    item:GossipSendMenu(player)
    end
    
    function Item_OnSelect(item,Event,Player)
    if intid == 1 then
    player:SendAreaTriggerMessage("You did it!")
    end
    end
    
    RegisterItemGossipEvent(125667, 1, "Item_OnUse")
    RegisterItemGossipEvent(125667, 2, "Item_OnUse")
    Now you have a fully functioning menu with an output. But because there is only one item on the menu it will skip the menu and jump into the next function.

    If you would like to see the menu try adding a few items to it and giving a few more results i will add one for you.

    Code:
    function Item_OnUse(Item,Event,player)
    item:GossipCreateMenu(100, player, 0)
    item:GossipMenuAddItem(0, "Make my model change please", 1, 0)
    item:GossipMenuAddItem(0, "Give me an item please", 2, 0)
    item:GossipSendMenu(player)
    end
    
    function Item_OnSelect(item,Event,Player)
    if intid == 1 then
    player:SetModel(367)
    end
    if intid == 2 then
    player:AddItem(27978)
    end
    end
    
    RegisterItemGossipEvent(125667, 1, "Item_OnUse")
    RegisterItemGossipEvent(125667, 2, "Item_OnUse")
    I hope this guide is helpful as it is my first ever ^^ oh and ive been doing lua for 6 days now <3. I would also like to know how i can imporve the way i structured the tutorial so if u guys could help me out that would be great.

    Any questions please post em as i would love to help you guys out

    Last edited by Scubast3ve; 04-24-2009 at 01:08 AM.

    [Guide] Scripting Items In LUA
  2. #2
    HellCat23's Avatar Member
    Reputation
    1
    Join Date
    Apr 2009
    Posts
    2
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Epic guide. FINALLY i have found one, I've been looking for a LUA guide for aaaggggeeessss!!!

  3. #3
    1ns0mnia's Avatar Active Member
    Reputation
    67
    Join Date
    Nov 2007
    Posts
    428
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice one, i like it

    --reccomend in a release of mine soon

  4. #4
    Ground Zero's Avatar ★ Elder ★
    Reputation
    1132
    Join Date
    Aug 2008
    Posts
    3,504
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice LUA Guide, +3

  5. #5
    Scubast3ve's Avatar Member
    Reputation
    55
    Join Date
    Apr 2009
    Posts
    125
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great to see you guys taking interest in this ^^
    Don't Forget To Give Rep To People Who Help You.

  6. #6
    sasoritail's Avatar Contributor
    Reputation
    161
    Join Date
    Sep 2008
    Posts
    655
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice! +Rep
    It's been a while

  7. #7
    y2kss66's Avatar Member
    Reputation
    104
    Join Date
    Jan 2008
    Posts
    778
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nice guide +repz

  8. #8
    Claiver's Avatar Member
    Reputation
    138
    Join Date
    Mar 2009
    Posts
    217
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you would only like 1 menu item and nothing more, but you can't, then simply add an easy work-around which looks something like this:
    Code:
    OnTrigger:
    Item:GossipMenuAddItem(0, "Good Bye",1000, 0)
    
    OnUse:
    if (intid == 1000) then
      Player:SendAreaTriggerMessage("")
      Player:GossipComplete()
    end
    xx.Claiver

  9. #9
    spacecowboy's Avatar Member
    Reputation
    10
    Join Date
    Feb 2007
    Posts
    59
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What do I do with the script once I have written it?
    Last edited by spacecowboy; 05-04-2009 at 03:03 PM.

  10. #10
    Padawan5's Avatar Member
    Reputation
    1
    Join Date
    May 2009
    Posts
    47
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice Guide, Helped a lot, for Item scriptinig....

    Are you ScubaSteve from Warcraft 3 who was sick at WW1?

  11. #11
    atomicstorm's Avatar Member
    Reputation
    1
    Join Date
    Apr 2009
    Posts
    1
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the Guide.
    Last edited by atomicstorm; 05-06-2009 at 12:21 PM.

  12. #12
    blizzlock's Avatar Member
    Reputation
    9
    Join Date
    Jan 2008
    Posts
    71
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice tutorial, +REP X2

  13. #13
    kreegoth's Avatar Contributor
    Reputation
    122
    Join Date
    Jun 2008
    Posts
    810
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ive written alot of Creature encounters in LUA and portals and such have had no issues with it.. For some reason i cannot get the item scripting to work for me at all.. Any idea what ive done wrong?

    Code:
    function Item_OnUse(Item,Event,player)
    item:GossipCreateMenu(100, player, 0)
    item:GossipMenuAddItem(0, "Bring me to the Bomb Site", 1, 0)
    item:GossipSendMenu(player)
    end
    
    function Item_OnSelect(item,Event,Player)
    if intid == 1 then
    player:Teleport (1, -3113.75, 839.355, 91.6668)
    end
    end
    
    RegisterItemGossipEvent(118728, 1, "Item_OnUse")
    RegisterItemGossipEvent(118728, 2, "Item_OnUse")

  14. #14
    Death_Master's Avatar Member
    Reputation
    4
    Join Date
    Mar 2009
    Posts
    27
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    make sure the item that you make the script for has a use function on it like the hearthstone

  15. #15
    kreegoth's Avatar Contributor
    Reputation
    122
    Join Date
    Jun 2008
    Posts
    810
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm Where do i set that? If its a custom item what field do i need to fill that in?

Page 1 of 2 12 LastLast

Similar Threads

  1. [Lua Script] Item Requests
    By Sirgee in forum WoW EMU Questions & Requests
    Replies: 2
    Last Post: 06-18-2012, 04:56 PM
  2. What is wrong with this item teleportation Lua script ?
    By Wheeze201 in forum WoW EMU Questions & Requests
    Replies: 6
    Last Post: 08-13-2009, 08:50 AM
  3. [GUIDE] How to activate LUA scripts
    By ~SaiLyn~ in forum WoW EMU Guides & Tutorials
    Replies: 3
    Last Post: 12-25-2007, 11:52 AM
  4. [GUIDE] - Scripting for Antrix, Making Mobs Talk, Cast Spells, etc
    By Greed in forum WoW EMU Guides & Tutorials
    Replies: 6
    Last Post: 12-10-2007, 07:51 PM
  5. [Guide]-finding items and getting NPC ID's-
    By fireguild1 in forum WoW EMU Guides & Tutorials
    Replies: 2
    Last Post: 11-05-2007, 09:59 PM
All times are GMT -5. The time now is 05:52 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search