Latest revision as of 23:24, 3 May 2011
The purpose of this page is to demonstrate how you would achieve the same functionality you had on the old Lua Engine in the new Luabridge interpreter.
Starting revision 4106, the gossip menu system was re-written to be stack based and more efficient. This however caused the syntax of manipulating the menus to change. So, let's drive right into it and demonstrate the new code to construct menus:
function OnHello(_object, _, _player) -- The _object argument points to the creature/item/gameobject we are creating this menu for and the _player argument is of course the player to send the menu to. local menu = GossipMenu(_object, <textid>, <language> ) --[[ Notice how we construct a menu with syntax similar to C++ constructors. The constructor argument signature is (Object , Text Id of the Menu, player language). We are already familiar with the 1st two arguments but the last argument is used for quest items. It determines which language to look up localized quest text(wow supports different languages). You can use 0 for this variable most of the time if you don't plan adding quests to the menu. If you are going to be adding quests, then you initialize this variable with _player:GetSession().language. ]] -- Adding menu items is very straight forward and still similar. -- The only difference is that we invoke the methods on the menu we created earlier rather than the _object argument. -- Observe : menu:AddItem( <icon_type>, <string describing the option> , <item_id>, <ask for code box> ) menu:AddItem(0, "Hello there", 1) menu:AddItem(0, "Reply", 2) -- <icon_type> is simply just that, refer to the core in /src/arcemu-world/Gossip.h for an enumeration of proper values. -- <string describing the option> is simply what you want to appear on the menu beside the icon. -- <item_id> is what you will distinguish this option by. -- <ask for code box> is a boolean value, if true, it presents the player with a code box to input extra information. -- Now you simply do this for all the items you wish to place on the menu and send it to a player using this : menu:Send(_player) -- Very simple and very straight forward. -- For some options, you would like to have a box message & gold value dialog box created by the client similar to the Dual Talent dialog box offered by class trainers. --For this, we use AddMenuItem() method. menu:AddMenuItem( <icon_type>, <string describing the option> , <item_id>, <required_money>, <box_message>, <ask for code box> ) -- <required_money> argument is what you want the client to show to the player. It does not automatically subtract it from the player when they accept it. You have to add code for that. -- <box_message> is the text you want to appear at the top of the dialog box. end function OnSelectOption(_object, evt, player, id, code) if(id == 1) then //oh, they clicked 'Hello There' option elseif(id == 2) then //oh they clicked 'Reply' option. end end RegisterUnitGossipEvent(...,1,OnHello) RegisterUnitGossipEvent(...,2,OnSelectOption)
Adding of custom quests to these menu via Lua is currently not supported.
Conditional Script Loading based on Map IDs(using new header syntax)
Assuming you've already read about the changes in luabridge, you know that all created VMs automatically load all .lua scripts . We saw this wasn't always a desired effect, so there is a painless way to remedy this by placing this piece of code anywhere in the .lua file.
<mapN> is simply the map id in which you want the script to be loaded in. You can specify several maps(comma separated), but you need atleast 1 map listed for it to be considered. You can't leave it blank to prevent the script from getting loaded(that will cause all the VMs to load it)
That's all there is to it. Much short and sweeter than writing loader scripts :P