Advertisement
Rochet2

Untitled

Jul 11th, 2014
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.44 KB | None | 0 0
  1. local NPCID = 24380
  2. local intidspace = 10
  3. local minlen = 3
  4.  
  5. ---Rochet2 Edition
  6.  
  7. local function FindAndDisplayItems(pUnit, player, namepart)
  8.     local Q = WorldDBQuery('SELECT entry, name1 FROM items WHERE name1 LIKE "%'..namepart..'%" LIMIT 30')
  9.     -- Item search, limit to max 30
  10.     if (not Q) then -- check query
  11.         return false
  12.     end
  13.     pUnit:GossipCreateMenu(100, player, 0)
  14.     pUnit:GossipMenuAddItem(0, "Find item", 1, 1, "Insert item name part") --addds a search button on top of the menu
  15.     repeat
  16.         local entry = Q:GetColumn(0):GetULong()
  17.         local name = Q:GetColumn(1):GetString()
  18.         pUnit:GossipMenuAddItem(4, name, entry+intidspace, 0)
  19.     until not Q:NextRow()
  20.     pUnit:GossipSendMenu(player)
  21.     return true
  22. end
  23.  
  24. local function OnGossipHello(pUnit, event, player)
  25.     if (player:IsGm() == true) then
  26.         pUnit:GossipCreateMenu(100, player, 0)
  27.         pUnit:GossipMenuAddItem(0, "Find item", 1, 1, "Insert item name part")
  28.         pUnit:GossipMenuAddItem(5, "[Exit Menu]", 0, 0)
  29.         pUnit:GossipSendMenu(player)
  30.     elseif (player:IsGm() == false) then
  31.         player:SendAreaTriggerMessage("You don't have access to this NPC!")
  32.         player:GossipComplete()
  33.     else
  34.         player:SendBroadcastMessage("[Server Notification][ERROR-MSG:307] Ranking check issue, report to a GM.")
  35.         player:GossipComplete()
  36.     end
  37. end
  38.  
  39. local function OnGossipSelect(pUnit, event, player, id, intid, code)
  40.     if (initd == 0) then
  41.         player:GossipComplete()
  42.         return
  43.     end
  44.  
  45.     if (intid == 1) then
  46.         if (code) then
  47.             local namepart = code:gsub('\\',''):gsub('"', '')
  48.             if (namepart:len() < minlen) then
  49.                 player:SendBroadcastMessage("[Server Notification] must be at least "..minlen.." characters long.")
  50.             else
  51.                 if (FindAndDisplayItems(pUnit, player, namepart)) then
  52.                     return -- Showing a submenu, so don't show main menu.
  53.                 else
  54.                     player:SendBroadcastMessage("[Server Notification] No results found.")
  55.                 end
  56.             end
  57.         end
  58.     end
  59.    
  60.     if (intid >= intidspace) then
  61.         local entry = intid-intidspace
  62.         player:SendBroadcastMessage("The item entry was " .. entry)
  63.     end
  64.    
  65.     OnGossipHello(pUnit, event, player)
  66. end
  67.  
  68. RegisterUnitGossipEvent(NPCID, 1, OnGossipHello)
  69. RegisterUnitGossipEvent(NPCID, 2, OnGossipSelect)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement