CoreInv Fully Supported

This commit is contained in:
Jim Shield
2024-01-22 16:55:58 +00:00
committed by GitHub
parent f1ff06c098
commit d17a1da5b2
2 changed files with 48 additions and 44 deletions

View File

@@ -244,8 +244,7 @@ function hasItem(items, amount, src) local amount = amount and amount or 1
foundInv = CoreInv foundInv = CoreInv
if src then if src then
if GetResourceState(QBExport):find("start") or GetResourceState(QBXExport):find("start") then if GetResourceState(QBExport):find("start") or GetResourceState(QBXExport):find("start") then
local Player = Core.Functions.GetPlayer(src) grabInv = Core.Functions.GetPlayer(src).PlayerData.items
grabInv = Player.PlayerData.inventory
elseif GetResourceState(ESXExport):find("start") then elseif GetResourceState(ESXExport):find("start") then
local Player = ESX.GetPlayerFromId(src) local Player = ESX.GetPlayerFromId(src)
grabInv = Player.getInventory(false) grabInv = Player.getInventory(false)
@@ -254,6 +253,7 @@ function hasItem(items, amount, src) local amount = amount and amount or 1
local p = promise.new() local p = promise.new()
Core.Functions.TriggerCallback('core_inventory:server:getInventory', function(cb) p:resolve(cb) end) Core.Functions.TriggerCallback('core_inventory:server:getInventory', function(cb) p:resolve(cb) end)
local result = Citizen.Await(p) local result = Citizen.Await(p)
if type(result) == "string" then result = json.decode(result) end
grabInv = result grabInv = result
end end
@@ -314,16 +314,23 @@ end
function getStash(stashName) function getStash(stashName)
local stashItems, items = {}, {} local stashItems, items = {}, {}
if GetResourceState(OXInv):find("start") then if GetResourceState(OXInv):find("start") then
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7ox_inventory") end if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..OXInv) end
stashItems = exports[OXInv]:Inventory(stashName).items stashItems = exports[OXInv]:Inventory(stashName).items
elseif GetResourceState(QSInv):find("start") then elseif GetResourceState(QSInv):find("start") then
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7qs-inventory") end if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..QSInv) end
stashItems = exports[QSInv]:GetStashItems(stashName) stashItems = exports[QSInv]:GetStashItems(stashName)
elseif GetResourceState(CoreInv):find("start") then
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..CoreInv) end
stashItems = exports[CoreInv]:getInventory(stashName)
elseif GetResourceState(CodeMInv):find("start") then elseif GetResourceState(CodeMInv):find("start") then
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7qs-inventory") end if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..CodeMInv) end
stashItems = exports[CodeMInv]:GetInventoryItems('Stash', stashName) stashItems = exports[CodeMInv]:GetInventoryItems('Stash', stashName)
elseif GetResourceState(QBInv):find("start") then elseif GetResourceState(QBInv):find("start") then
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7qb-inventory") end if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..QBInv) end
local result = MySQL.scalar.await('SELECT items FROM stashitems WHERE stash = ?', { stashName }) local result = MySQL.scalar.await('SELECT items FROM stashitems WHERE stash = ?', { stashName })
if result then stashItems = json.decode(result) end if result then stashItems = json.decode(result) end
end end
@@ -331,18 +338,18 @@ function getStash(stashName)
for _, item in pairs(stashItems) do for _, item in pairs(stashItems) do
local itemInfo = Items[item.name:lower()] local itemInfo = Items[item.name:lower()]
if itemInfo then if itemInfo then
items[item.slot] = { items[#items+1] = {
name = itemInfo["name"], name = itemInfo["name"] ~= nil and itemInfo["slot"] or nil,
amount = tonumber(item.amount) or tonumber(item.count), amount = tonumber(item.amount) or tonumber(item.count),
info = item.info ~= nil and item.info or "", info = item.info ~= nil and item.info or "",
label = itemInfo["label"], label = itemInfo["label"] ~= nil and itemInfo["slot"] or nil,
description = itemInfo["description"] ~= nil and itemInfo["description"] or "", description = itemInfo["description"] ~= nil and itemInfo["description"] or "",
weight = itemInfo["weight"], weight = itemInfo["weight"] ~= nil and itemInfo["slot"] or nil,
type = itemInfo["type"], type = itemInfo["type"] ~= nil and itemInfo["slot"] or nil,
unique = itemInfo["unique"], unique = itemInfo["unique"] ~= nil and itemInfo["slot"] or nil,
useable = itemInfo["useable"], useable = itemInfo["useable"] ~= nil and itemInfo["slot"] or nil,
image = itemInfo["image"], image = itemInfo["image"] ~= nil and itemInfo["slot"] or nil,
slot = item.slot, slot = itemInfo["slot"] ~= nil and itemInfo["slot"] or nil,
} }
end end
end end
@@ -358,23 +365,30 @@ function stashRemoveItem(stashItems, stashName, items) local amount = amount and
if Config.System.Debug then print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..OXInv, k, v) end if Config.System.Debug then print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..OXInv, k, v) end
end end
elseif GetResourceState(QSInv):find("start") then elseif GetResourceState(QSInv):find("start") then
for k, v in pairs(items) do for k, v in pairs(items) do
for l in pairs(stashItems) do for l in pairs(stashItems) do
if stashItems[l].name == k then if stashItems[l].name == k then
if (stashItems[l].amount - v) <= 0 then if (stashItems[l].amount - v) <= 0 then
if Config.System.Debug then if Config.System.Debug then
print("^6Bridge^7: ^2None of this item left in stash ^3Stash^7", k, v) print("^6Bridge^7: ^2None of this item left in stash ^3Stash^7", k, v)
end
stashItems[l] = nil
else
if Config.System.Debug then
print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..QBInv, k, v)
end
exports[QSInv]:RemoveItemIntoStash(stashName, k, v, l)
end end
stashItems[l] = nil
else
if Config.System.Debug then
print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..QBInv, k, v)
end
exports[QSInv]:RemoveItemIntoStash(stashName, k, v, l)
end end
end end
end end
elseif GetResourceState(CoreInv):find("start") then
for k, v in pairs(items) do
exports[CoreInv]:removeItemExact(stashName, k, v)
if Config.System.Debug then print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..CoreInv, k, v) end
end end
elseif GetResourceState(CodeMInv):find("start") then elseif GetResourceState(CodeMInv):find("start") then
for k, v in pairs(items) do for k, v in pairs(items) do
for l in pairs(stashItems) do for l in pairs(stashItems) do

View File

@@ -591,16 +591,11 @@ RegisterNetEvent(GetCurrentResourceName()..":server:toggleItem", function(give,
if Config.System.Debug then if Config.System.Debug then
print("^6Bridge^7: ^3"..addremove.."^7[^6"..QSInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7") print("^6Bridge^7: ^3"..addremove.."^7[^6"..QSInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7")
end end
elseif GetResourceState(CoreInv):find("start") then elseif GetResourceState(CoreInv):find("start") then
local id = ""
if GetResourceState(QBExport):find("start") then if GetResourceState(QBExport):find("start") then
local Player = Core.Functions.GetPlayer(src) Core.Functions.GetPlayer(src).Functions.RemoveItem(item, amount, nil)
id = Player.PlayerData.citizenid
Player.Functions.RemoveItem(item, amount, nil)
elseif GetResourceState(ESXExport):find("start") then elseif GetResourceState(ESXExport):find("start") then
id = ESX.GetPlayerFromId(src).identifier:gsub(":", "") ESX.GetPlayerFromId(src).removeInventoryItem(item, count)
Player = ESX.GetPlayerFromId(src)
Player.removeInventoryItem(item, count)
end end
if Config.System.Debug then if Config.System.Debug then
print("^6Bridge^7: ^3"..addremove.."^7[^6"..CoreInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7") print("^6Bridge^7: ^3"..addremove.."^7[^6"..CoreInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7")
@@ -640,17 +635,12 @@ RegisterNetEvent(GetCurrentResourceName()..":server:toggleItem", function(give,
print("^6Bridge^7: ^3"..addremove.."^7[^6"..QSInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7") print("^6Bridge^7: ^3"..addremove.."^7[^6"..QSInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7")
end end
elseif GetResourceState(CoreInv):find("start") then elseif GetResourceState(CoreInv):find("start") then
local id = "" if GetResourceState(QBExport):find("start") or GetResourceState(QBXExport):find("start") then
if GetResourceState(QBExport):find("start") then Core.Functions.GetPlayer(src).Functions.AddItem(item, amount, nil, nil)
local Player = Core.Functions.GetPlayer(src)
id = Player.PlayerData.citizenid
Player.Functions.AddItem(item, amount, nil, nil)
elseif GetResourceState(ESXExport):find("start") then elseif GetResourceState(ESXExport):find("start") then
id = ESX.GetPlayerFromId(src).identifier:gsub(":", "") ESX.GetPlayerFromId(src).addInventoryItem(item, amount)
Player = ESX.GetPlayerFromId(src)
Player.addInventoryItem(item, amount)
end end
if Config.System.Debug then if Config.System.Debug then
print("^6Bridge^7: ^3"..addremove.."^7[^6"..CoreInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7") print("^6Bridge^7: ^3"..addremove.."^7[^6"..CoreInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7")
end end
elseif GetResourceState(CodeMInv):find("start") then elseif GetResourceState(CodeMInv):find("start") then