2025-03-08 13:44:05 +00:00
|
|
|
-------------------------------------------------------------
|
|
|
|
|
-- Item Availability & Inventory Retrieval
|
|
|
|
|
-------------------------------------------------------------
|
|
|
|
|
---
|
|
|
|
|
--- Locks or unlocks the player's inventory.
|
|
|
|
|
--- Freezes/unfreezes the player's position, sets inventory busy state, and toggles hotbar usage.
|
|
|
|
|
---
|
|
|
|
|
--- @param toggle boolean True to lock inventory; false to unlock.
|
|
|
|
|
---
|
|
|
|
|
--- @usage
|
|
|
|
|
--- ```lua
|
|
|
|
|
--- lockInv(true) -- Lock inventory.
|
|
|
|
|
--- lockInv(false) -- Unlock inventory.
|
|
|
|
|
--- ```
|
|
|
|
|
function lockInv(toggle)
|
|
|
|
|
FreezeEntityPosition(PlayerPedId(), toggle)
|
|
|
|
|
LocalPlayer.state:set("inv_busy", toggle, true)
|
2025-05-06 00:17:07 +01:00
|
|
|
LocalPlayer.state:set("invBusy", toggle, true)
|
2025-03-08 13:44:05 +00:00
|
|
|
TriggerEvent('inventory:client:busy:status', toggle)
|
|
|
|
|
TriggerEvent('canUseInventoryAndHotbar:toggle', not toggle)
|
|
|
|
|
end
|
|
|
|
|
--- Checks if a player has the specified items in their inventory.
|
|
|
|
|
---
|
|
|
|
|
--- Verifies whether the required quantities are present. Returns a boolean and a table of details.
|
|
|
|
|
---
|
|
|
|
|
--- @param items string|table A single item name or table with required amounts.
|
|
|
|
|
--- @param amount number The required quantity (default 1).
|
|
|
|
|
--- @param src number|nil Player source ID (defaults to caller).
|
|
|
|
|
--- @return boolean boolean True if all items are available; otherwise, false.
|
|
|
|
|
--- @return table|nil table Table detailing counts for each item.
|
|
|
|
|
---
|
|
|
|
|
---@usage
|
|
|
|
|
--- ```lua
|
|
|
|
|
--- local hasAll, details = hasItem({"health_potion", "mana_potion"}, 2, playerId)
|
|
|
|
|
--- if hasAll then
|
|
|
|
|
--- -- Proceed with action
|
|
|
|
|
--- else
|
|
|
|
|
--- -- Inform the player about missing items
|
|
|
|
|
--- end
|
|
|
|
|
--- ```
|
|
|
|
|
function hasItem(items, amount, src)
|
|
|
|
|
local amount = amount and amount or 1
|
|
|
|
|
local grabInv, foundInv = getPlayerInv(src)
|
|
|
|
|
if type(items) ~= "table" then items = { [items] = amount and amount or 1, } end
|
|
|
|
|
|
|
|
|
|
if grabInv then
|
|
|
|
|
local hasTable = {}
|
|
|
|
|
for item, amt in pairs(items) do
|
|
|
|
|
if not Items[item] then print("^4ERROR^7: ^2Script can't find ingredient item in Shared Items - ^1"..item.."^7") end
|
|
|
|
|
|
|
|
|
|
local count = 0
|
|
|
|
|
for _, itemData in pairs(grabInv) do
|
2025-06-13 23:25:32 +01:00
|
|
|
--jsonPrint(itemData)
|
2025-03-08 13:44:05 +00:00
|
|
|
if itemData and itemData.name == item then
|
2025-05-15 19:55:14 +01:00
|
|
|
count += (itemData.amount or itemData.count or 1)
|
2025-03-08 13:44:05 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
foundInv = foundInv:gsub("%-", "^7-^6"):gsub("%_", "^7_^6")
|
|
|
|
|
local foundMessage = "^6Bridge^7: ^3hasItem^7[^6"..foundInv.."^7]: "..tostring(item).." ^3"..count.."^7/^3"..amt
|
|
|
|
|
if count >= amt then foundMessage = foundMessage.." ^5FOUND^7" else foundMessage = foundMessage .." ^1NOT FOUND^7" end
|
|
|
|
|
debugPrint(foundMessage)
|
|
|
|
|
hasTable[item] = { hasItem = count >= amt, count = count }
|
|
|
|
|
end
|
2025-03-26 21:43:48 +00:00
|
|
|
for k, v in pairs(hasTable) do
|
|
|
|
|
if not v.hasItem then
|
|
|
|
|
return false, hasTable
|
|
|
|
|
end
|
|
|
|
|
end
|
2025-03-08 13:44:05 +00:00
|
|
|
return true, hasTable
|
|
|
|
|
end
|
2025-05-14 23:38:34 +01:00
|
|
|
-- if can't find inventory, return false
|
|
|
|
|
print("^1Error^7: ^1Can't find players inventory for some reason")
|
|
|
|
|
return false, {}
|
2025-03-08 13:44:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--- Retrieves a player's inventory based on the active inventory system.
|
|
|
|
|
---
|
|
|
|
|
--- @param src number|nil The player source ID (if nil, retrieves current player's inventory).
|
|
|
|
|
--- @return table|nil table The inventory items.
|
|
|
|
|
--- @return string|nil string The name of the inventory system.
|
|
|
|
|
---
|
|
|
|
|
---@usage
|
|
|
|
|
--- ```lua
|
|
|
|
|
--- local inventory, system = getPlayerInv(playerId)
|
|
|
|
|
--- if inventory then
|
|
|
|
|
--- -- Process inventory
|
|
|
|
|
--- end
|
|
|
|
|
--- ```
|
|
|
|
|
function getPlayerInv(src)
|
|
|
|
|
local grabInv = nil
|
|
|
|
|
local foundInv = ""
|
|
|
|
|
|
|
|
|
|
if isStarted(OXInv) then
|
|
|
|
|
foundInv = OXInv
|
2025-04-01 14:15:50 +01:00
|
|
|
if src then
|
|
|
|
|
grabInv = exports[OXInv]:GetInventoryItems(src)
|
|
|
|
|
else
|
|
|
|
|
grabInv = exports[OXInv]:GetPlayerItems()
|
|
|
|
|
end
|
2025-03-08 13:44:05 +00:00
|
|
|
|
|
|
|
|
elseif isStarted(QSInv) then
|
|
|
|
|
foundInv = QSInv
|
2025-04-01 14:15:50 +01:00
|
|
|
if src then
|
|
|
|
|
grabInv = exports[QSInv]:GetInventory(src)
|
|
|
|
|
else
|
2025-05-15 19:59:51 +01:00
|
|
|
grabInv = exports[QSInv]:getUserInventory()
|
2025-04-01 14:15:50 +01:00
|
|
|
end
|
2025-03-08 13:44:05 +00:00
|
|
|
|
|
|
|
|
elseif isStarted(OrigenInv) then
|
|
|
|
|
foundInv = OrigenInv
|
2025-04-01 14:15:50 +01:00
|
|
|
if src then
|
|
|
|
|
grabInv = exports[OrigenInv]:getInventory(src)
|
|
|
|
|
else
|
2025-07-24 21:49:37 +01:00
|
|
|
grabInv = exports[OrigenInv]:GetInventory()
|
2025-04-01 14:15:50 +01:00
|
|
|
end
|
2025-03-08 13:44:05 +00:00
|
|
|
|
|
|
|
|
elseif isStarted(CoreInv) then
|
|
|
|
|
foundInv = CoreInv
|
2025-04-01 14:15:50 +01:00
|
|
|
if src then
|
|
|
|
|
grabInv = exports[CoreInv]:getInventory(src)
|
|
|
|
|
else
|
|
|
|
|
grabInv = exports[CoreInv]:getInventory()
|
|
|
|
|
end
|
2025-03-08 13:44:05 +00:00
|
|
|
|
|
|
|
|
elseif isStarted(CodeMInv) then
|
|
|
|
|
foundInv = CodeMInv
|
2025-04-01 14:15:50 +01:00
|
|
|
if src then
|
2025-04-30 17:54:04 +01:00
|
|
|
grabInv = exports[CodeMInv]:GetInventory(getPlayer(src).citizenId, src)
|
2025-04-01 14:15:50 +01:00
|
|
|
else
|
2025-04-29 19:55:09 +01:00
|
|
|
grabInv = exports[CodeMInv]:getUserInventory()
|
2025-04-01 14:15:50 +01:00
|
|
|
end
|
2025-03-08 13:44:05 +00:00
|
|
|
|
2025-04-30 17:53:26 +01:00
|
|
|
elseif isStarted(TgiannInv) then
|
|
|
|
|
foundInv = TgiannInv
|
|
|
|
|
if src then
|
|
|
|
|
grabInv = exports[TgiannInv]:GetPlayerItems(src)
|
|
|
|
|
else
|
|
|
|
|
grabInv = exports[TgiannInv]:GetPlayerItems()
|
|
|
|
|
end
|
|
|
|
|
|
2025-06-13 23:25:32 +01:00
|
|
|
elseif isStarted(JPRInv) then
|
|
|
|
|
foundInv = JPRInv
|
|
|
|
|
if src then
|
|
|
|
|
grabInv = Core.Functions.GetPlayer(src).PlayerData.items
|
|
|
|
|
else
|
|
|
|
|
grabInv = Core.Functions.GetPlayerData().items
|
|
|
|
|
end
|
|
|
|
|
|
2025-03-08 13:44:05 +00:00
|
|
|
elseif isStarted(QBInv) then
|
|
|
|
|
foundInv = QBInv
|
2025-04-01 14:15:50 +01:00
|
|
|
if src then
|
|
|
|
|
grabInv = Core.Functions.GetPlayer(src).PlayerData.items
|
|
|
|
|
else
|
|
|
|
|
grabInv = Core.Functions.GetPlayerData().items
|
|
|
|
|
end
|
2025-03-08 13:44:05 +00:00
|
|
|
|
|
|
|
|
elseif isStarted(PSInv) then
|
|
|
|
|
foundInv = PSInv
|
2025-06-13 23:25:32 +01:00
|
|
|
if src then
|
|
|
|
|
grabInv = Core.Functions.GetPlayer(src).PlayerData.items
|
|
|
|
|
else
|
|
|
|
|
grabInv = Core.Functions.GetPlayerData().items
|
|
|
|
|
end
|
2025-03-08 13:44:05 +00:00
|
|
|
|
|
|
|
|
elseif ESX and isStarted(ESXExport) then
|
|
|
|
|
foundInv = ESX
|
|
|
|
|
if src then
|
|
|
|
|
local xPlayer = ESX.GetPlayerFromId(src)
|
|
|
|
|
grabInv = xPlayer.inventory
|
|
|
|
|
else
|
|
|
|
|
local xPlayer = ESX.GetPlayerData() -- Client side, if available
|
|
|
|
|
grabInv = xPlayer.inventory
|
|
|
|
|
end
|
|
|
|
|
|
2025-04-07 20:52:59 +01:00
|
|
|
elseif isStarted(RSGInv) then
|
|
|
|
|
foundInv = RSGInv
|
|
|
|
|
if src then
|
|
|
|
|
grabInv = Core.Functions.GetPlayer(src).PlayerData.items
|
|
|
|
|
else
|
|
|
|
|
grabInv = Core.Functions.GetPlayerData().items
|
|
|
|
|
end
|
|
|
|
|
|
2025-03-08 13:44:05 +00:00
|
|
|
else
|
|
|
|
|
print("^4ERROR^7: ^2No Inventory detected ^7- ^2Check ^3starter^1.^2lua^7")
|
|
|
|
|
end
|
|
|
|
|
return grabInv, foundInv
|
2025-05-06 00:17:07 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function isInventoryOpen()
|
|
|
|
|
|
2025-06-04 13:53:49 +01:00
|
|
|
return IsNuiFocused()
|
2025-05-06 00:17:07 +01:00
|
|
|
|
2025-05-07 12:58:39 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-------------------------------------------------------------
|
|
|
|
|
-- Item Image Retrieval
|
|
|
|
|
-------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
--- Retrieves the NUI link for an item's image from the active inventory system.
|
|
|
|
|
---
|
|
|
|
|
--- @param item string The item name.
|
|
|
|
|
--- @return string string A `nui://` link to the item's image, or an empty string if not found.
|
|
|
|
|
---
|
|
|
|
|
--- @usage
|
|
|
|
|
--- ```lua
|
|
|
|
|
--- local imageLink = invImg("health_potion")
|
|
|
|
|
--- if imageLink ~= "" then print(imageLink) end
|
|
|
|
|
--- ```
|
|
|
|
|
function invImg(item)
|
|
|
|
|
local imgLink = ""
|
|
|
|
|
if item ~= "" and Items[item] then
|
|
|
|
|
if isStarted(OXInv) then
|
|
|
|
|
imgLink = "nui://"..OXInv.."/web/images/"..(Items[item].image or "")
|
|
|
|
|
|
|
|
|
|
elseif isStarted(QSInv) then
|
|
|
|
|
imgLink = "nui://"..QSInv.."/html/images/"..(Items[item].image or "")
|
|
|
|
|
|
|
|
|
|
elseif isStarted(CoreInv) then
|
|
|
|
|
imgLink = "nui://"..CoreInv.."/html/img/"..(Items[item].image or "")
|
|
|
|
|
|
|
|
|
|
elseif isStarted(CodeMInv) then
|
|
|
|
|
imgLink = "nui://"..CodeMInv.."/html/itemimages/"..(Items[item].image or "")
|
|
|
|
|
|
|
|
|
|
elseif isStarted(OrigenInv) then
|
|
|
|
|
imgLink = "nui://"..OrigenInv.."/html/img/"..(Items[item].image or "")
|
|
|
|
|
|
2025-06-13 23:25:32 +01:00
|
|
|
elseif isStarted(JPRInv) then
|
|
|
|
|
imgLink = "nui://"..JPRInv.."/html/images/"..(Items[item].image or "")
|
|
|
|
|
|
2025-05-07 12:58:39 +01:00
|
|
|
elseif isStarted(QBInv) then
|
|
|
|
|
imgLink = "nui://"..QBInv.."/html/images/"..(Items[item].image or "")
|
|
|
|
|
|
|
|
|
|
elseif isStarted(PSInv) then
|
|
|
|
|
imgLink = "nui://"..PSInv.."/html/images/"..(Items[item].image or "")
|
2025-07-27 20:00:42 +01:00
|
|
|
|
2025-05-07 12:58:39 +01:00
|
|
|
elseif isStarted(TgiannInv) then
|
|
|
|
|
imgLink = "nui://inventory_images/images/"..(Items[item].image or "")
|
|
|
|
|
|
|
|
|
|
elseif isStarted(RSGInv) then
|
|
|
|
|
imgLink = "nui://"..RSGInv.."/html/images/"..(Items[item].image or "")
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
print("^4ERROR^7: ^2No Inventory detected for invImg - Check starter.lua")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return imgLink
|
2025-03-08 13:44:05 +00:00
|
|
|
end
|