Skip to content

Commit

Permalink
feat: usedItem event
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Dec 30, 2023
1 parent 355c0b8 commit ca904c3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,18 @@ local function useItem(data, cb)
end
end

if result then
TriggerEvent('ox_inventory:usedItem', slotData.name, slotData.slot, next(slotData.metadata) and slotData.metadata)
end

Wait(500)
usingItem = false
end

AddEventHandler('ox_inventory:usedItem', function(name, slot, metadata)
TriggerServerEvent('ox_inventory:usedItemInternal', slot)
end)

AddEventHandler('ox_inventory:item', useItem)
exports('useItem', useItem)

Expand Down
20 changes: 20 additions & 0 deletions server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,25 @@ lib.callback.register('ox_inventory:getInventory', function(source, id)
}
end)

RegisterNetEvent('ox_inventory:usedItemInternal', function(slot)
local inventory = Inventory(source)

if not inventory then return end

local item = inventory.usingItem

if not item or item.slot ~= slot then
---@todo
DropPlayer(inventory.id, 'sussy')

return
end

TriggerEvent('ox_inventory:usedItem', item.name, item.slot, next(item.metadata) and item.metadata)

inventory.usingItem = nil
end)

---@param source number
---@param itemName string
---@param slot number?
Expand Down Expand Up @@ -344,6 +363,7 @@ lib.callback.register('ox_inventory:useItem', function(source, itemName, slot, m
end

data.consume = consume
inventory.usingItem = data

---@type boolean
local success = lib.callback.await('ox_inventory:usingItem', source, data)
Expand Down

0 comments on commit ca904c3

Please sign in to comment.