Skip to content

Commit

Permalink
refactor(server): remove ox_inventory dependency. added esx/qb suppor…
Browse files Browse the repository at this point in the history
…t directly
  • Loading branch information
Demigod committed Aug 21, 2023
1 parent 7701870 commit 960fe43
Showing 1 changed file with 46 additions and 3 deletions.
49 changes: 46 additions & 3 deletions server/server.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
local frameWork =
GetResourceState("es_extended") == "started" and 'esx'
or
GetResourceState("qb-core") == "started" and 'qb'

local core =
(Bridge.frameWork == "esx" and exports["es_extended"]:getSharedObject())
or
(Bridge.frameWork == "qb" and exports["qb-core"]:GetCoreObject())

local ox_inventory = exports.ox_inventory

local POOL_SIZE = 100

local function tableConcat(t1, t2)
Expand All @@ -15,6 +27,38 @@ local function shuffle(tbl)
return tbl
end

local function getPlayer(src)
if not core then return end

if frameWork == "esx" then
return core.GetPlayerFromId(src)
elseif frameWork == "qb" then
return core.Functions.GetPlayer(src)
end
end

local function giveItem(src, item, amount, metadata)
if GetResourceState("ox_inventory") == "started" then
if ox_inventory:CanCarryItem(src, item, amount, metadata) then
return ox_inventory:AddItem(src, item, amount, metadata)
else
local dropId = ox_inventory:CreateDropFromPlayer(src)
ox_inventory:AddItem(dropId, item, amount, metadata)
end
return
end

local Player = getPlayer(src)

if not Player then return end

if frameWork == "esx" then
Player.addInventoryItem(item, amount, metadata or {})
elseif frameWork == "qb" then
Player.Functions.AddItem(item, amount, false, metadata or {})
end
end

local function generateLootPoolFromCase(case)
local pool = {}
local desiredCounts = {
Expand Down Expand Up @@ -79,12 +123,11 @@ RegisterNetEvent('demi_lootbox:getQueuedItem', function()
if not playerLootQueue[source] then
print("^1 ==================================================================================================")
print(('^1 [WARNING]: POSSIBLE CHEATER. Player Source %s triggered lootbox get item event while not in queue')
:format(source))
:format(source))
print('^1 =================================================================================================')
print(('^1 PLAYERS IDENTIFIERS = %s'):format(json.encode(GetPlayerIdentifiers(source), { indent = true })))
print('^1 =================================================================================================')
return
end

exports.ox_inventory:AddItem(source, playerLootQueue[source].name, playerLootQueue[source].amount)
giveItem(source, playerLootQueue[source].name, playerLootQueue[source].amount)
end)

0 comments on commit 960fe43

Please sign in to comment.