Lukkit
Search…
Run function if an inventory item has been clicked

Run a function if an inventory item has been clicked

1
plugin.registerEvent("InventoryClickEvent", function(e)
2
-- Get info
3
local player = e:getWhoClicked()
4
local inventoryName = e:getView():getTitle()
5
6
-- Test if the clicked slot is not empty
7
if e:getCurrentItem() then
8
if e:getCurrentItem():getItemMeta() then
9
if e:getCurrentItem():getItemMeta():getDisplayName() then
10
-- Get item text
11
local clickedItemName = e:getCurrentItem():getItemMeta():getDisplayName()
12
-- Test if open inv has contains the name
13
if string.find(inventoryName, "This is the inventory title") then
14
if string.find(clickedItemName, "WoW crazy item") then
15
-- Here comes your code if the generated item with this name is clicked
16
end
17
-- Disable dragging or dropping item to this inv
18
e:setCancelled(true)
19
end
20
end
21
end
22
end
23
end)
Copied!
You need to register the event InventoryClickEvent with plugin.registerEvent(event: string, callback: function) to test the clicked item in inventory
Last modified 6mo ago
Copy link