Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- local function FindAndDisplayItems(namepart)
- local Q = WorldDBQuery('SELECT entry, name FROM items WHERE name LIKE "%'..namepart..'%" LIMIT 30') -- Search for the item, limit results to max 30
- if(not Q) then -- check query
- return false
- end
- unit:GossipCreateMenu(100, pPlayer, 0)
- unit:GossipMenuAddItem(0, "Find item", 1, 1, "Insert item name part") -- Add search button to top of menu
- repeat -- Loop the results of the query and add as many options as needed
- local entry = Q:GetColumn(0):GetULong()
- local name = Q:GetColumn(1):GetString()
- unit:GossipMenuAddItem(4, name, entry + intidspace, 0)
- until not result:NextRow()
- unit:GossipSendMenu(pPlayer)
- return true
- end
- local function OnGossipHello(unit, event, player)
- unit:GossipCreateMenu(100, pPlayer, 0)
- unit:GossipMenuAddItem(0, "Find item", 1, 1, "Insert item name part")
- unit:GossipMenuAddItem(7, "Nevermind..", 0, 0)
- unit:GossipSendMenu(pPlayer)
- end
- local function OnGossipSelect(unit, event, player, id, intid, code)
- if(intid == 0) then
- player:GossipComplete()
- return -- Dont show main menu
- end
- if(intid == 1) then
- if(code) then
- local namepart = code:gsub('\\', ''):gsub('"', '\\"') -- Dont allow backslash, Convert all quotes to escaped quotes (try avoid SQL injection)
- local minlen = 3
- if(namepart:len() < minlen) then
- player:SendAreaTriggerMessage("The name part must be at least "..minlen.." characters long")
- else
- if(FindAndDisplayItems(namepart)) then
- return -- Showing a submenu, so dont show main menu
- else
- player:SendAreaTriggerMessage("No results found")
- end
- end
- end
- end
- -- Clicked an item button
- if(intid >= intidspace) then
- player:SendAreaTriggerMessage("Clicked option for item entry "..(intid-intidspace))
- end
- OnGossipHello(unit, event, player) -- Show main menu again
- end
- RegisterUnitGossipEvent(123, 1, OnGossipHello)
- RegisterUnitGossipEvent(123, 2, OnGossipSelect)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement