Lukkit
  • Home
  • Getting Started
    • Installing Lukkit
    • Your First Plugin
    • Packing and Publishing
  • Storage
    • The StorageObject
    • Example
  • Commands
    • Command Options
    • Command Event
    • Examples
  • Gui
    • Create a simple inv
    • Create an advanced inv
    • Run function if an inventory item has been clicked
  • Events
    • Examples
    • Event List
      • Block
      • Enchantment
      • Entity
      • Hanging
      • Inventory
      • Player
      • Server
      • Vehicle
      • Weather
      • World
  • Globals
    • Global Functions
    • Global Variables
      • Plugin
      • Logging
      • Utilities
  • Wrappers
  • Examples
    • Discord Webhooks (http)
    • Toggle Fly
    • Hello, world!
Powered by GitBook
On this page
  1. Gui

Run function if an inventory item has been clicked

Run a function if an inventory item has been clicked

plugin.registerEvent("InventoryClickEvent", function(e)
  -- Get info
  local player = e:getWhoClicked()
  local inventoryName = e:getView():getTitle()

  -- Test if the clicked slot is not empty
  if e:getCurrentItem() then
     if e:getCurrentItem():getItemMeta() then
        if e:getCurrentItem():getItemMeta():getDisplayName() then
           -- Get item text
           local clickedItemName = e:getCurrentItem():getItemMeta():getDisplayName()
           -- Test if open inv has contains the name
           if string.find(inventoryName, "This is the inventory title") then
              if string.find(clickedItemName, "WoW crazy item") then
                  -- Here comes your code if the generated item with this name is clicked
              end
              -- Disable dragging or dropping item to this inv
              e:setCancelled(true)
           end
        end
     end
  end
end)
PreviousCreate an advanced invNextEvents

Last updated 3 years ago

You need to register the event InventoryClickEvent with to test the clicked item in inventory

plugin.registerEvent(event: string, callback: function)