Advertisement
Rochet2

Example

May 13th, 2014
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.34 KB | None | 0 0
  1. local intidspace = 3 -- To use item entries as intid, we need to protect the normal intids by adding some to the entry and when using the entry, removing the addition
  2.  
  3. local function FindAndDisplayItems(namepart)
  4.     local Q = WorldDBQuery('SELECT entry, name FROM items WHERE name LIKE "%'..namepart..'%" LIMIT 30') -- Search for the item, limit results to max 30
  5.     if(not Q) then -- check query
  6.         return false
  7.     end
  8.     unit:GossipCreateMenu(100, pPlayer, 0)
  9.     unit:GossipMenuAddItem(0, "Find item", 1, 1, "Insert item name part") -- Add search button to top of menu
  10.     repeat -- Loop the results of the query and add as many options as needed
  11.         local entry = Q:GetColumn(0):GetULong()
  12.         local name = Q:GetColumn(1):GetString()
  13.         unit:GossipMenuAddItem(4, name, entry + intidspace, 0)
  14.     until not result:NextRow()
  15.     unit:GossipSendMenu(pPlayer)
  16.     return true
  17. end
  18.  
  19. local function OnGossipHello(unit, event, player)
  20.     unit:GossipCreateMenu(100, pPlayer, 0)
  21.     unit:GossipMenuAddItem(0, "Find item", 1, 1, "Insert item name part")
  22.     unit:GossipMenuAddItem(7, "Nevermind..", 0, 0)
  23.     unit:GossipSendMenu(pPlayer)
  24. end
  25.  
  26. local function OnGossipSelect(unit, event, player, id, intid, code)
  27.     if(intid == 0) then
  28.        player:GossipComplete()
  29.        return -- Dont show main menu
  30.     end
  31.    
  32.     if(intid == 1) then
  33.         if(code) then
  34.             local namepart = code:gsub('\\', ''):gsub('"', '\\"') -- Dont allow backslash, Convert all quotes to escaped quotes (try avoid SQL injection)
  35.             local minlen = 3
  36.             if(namepart:len() < minlen) then
  37.                 player:SendAreaTriggerMessage("The name part must be at least "..minlen.." characters long")
  38.             else
  39.                 if(FindAndDisplayItems(namepart)) then
  40.                     return -- Showing a submenu, so dont show main menu
  41.                 else
  42.                     player:SendAreaTriggerMessage("No results found")
  43.                 end
  44.             end
  45.         end
  46.     end
  47.    
  48.     -- Clicked an item button
  49.     if(intid >= intidspace) then
  50.         player:SendAreaTriggerMessage("Clicked option for item entry "..(intid-intidspace))
  51.     end
  52.    
  53.     OnGossipHello(unit, event, player) -- Show main menu again
  54. end
  55.  
  56. RegisterUnitGossipEvent(123, 1, OnGossipHello)
  57. RegisterUnitGossipEvent(123, 2, OnGossipSelect)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement