mirror of
https://github.com/jimathy/jim_bridge.git
synced 2026-08-17 05:56:02 +01:00
Add full support for JPR-Inventory
Thanks to JPR for providing access to make this possible https://jpresources.tebex.io/package/5284060
This commit is contained in:
@@ -20,6 +20,7 @@ local Exports = {
|
|||||||
CodeMInv = "codem-inventory",
|
CodeMInv = "codem-inventory",
|
||||||
OrigenInv = "origen_inventory",
|
OrigenInv = "origen_inventory",
|
||||||
TgiannInv = "tgiann-inventory",
|
TgiannInv = "tgiann-inventory",
|
||||||
|
JPRInv = "jpr-inventory",
|
||||||
|
|
||||||
OXLibExport = "ox_lib",
|
OXLibExport = "ox_lib",
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ OXLibExport, QBXExport, QBExport, ESXExport, OXCoreExport =
|
|||||||
Exports.ESXExport or "",
|
Exports.ESXExport or "",
|
||||||
Exports.OXCoreExport or ""
|
Exports.OXCoreExport or ""
|
||||||
|
|
||||||
OXInv, QBInv, PSInv, QSInv, CoreInv, CodeMInv, OrigenInv, TgiannInv =
|
OXInv, QBInv, PSInv, QSInv, CoreInv, CodeMInv, OrigenInv, TgiannInv, JPRInv =
|
||||||
Exports.OXInv or "",
|
Exports.OXInv or "",
|
||||||
Exports.QBInv or "",
|
Exports.QBInv or "",
|
||||||
Exports.PSInv or "",
|
Exports.PSInv or "",
|
||||||
@@ -18,7 +18,8 @@ OXInv, QBInv, PSInv, QSInv, CoreInv, CodeMInv, OrigenInv, TgiannInv =
|
|||||||
Exports.CoreInv or "",
|
Exports.CoreInv or "",
|
||||||
Exports.CodeMInv or "",
|
Exports.CodeMInv or "",
|
||||||
Exports.OrigenInv or "",
|
Exports.OrigenInv or "",
|
||||||
Exports.TgiannInv or ""
|
Exports.TgiannInv or "",
|
||||||
|
Exports.JPRInv or ""
|
||||||
|
|
||||||
RSGExport, RSGInv = Exports.RSGExport or "", Exports.RSGInv or ""
|
RSGExport, RSGInv = Exports.RSGExport or "", Exports.RSGInv or ""
|
||||||
QBMenuExport = Exports.QBMenuExport or ""
|
QBMenuExport = Exports.QBMenuExport or ""
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ function hasItem(items, amount, src)
|
|||||||
|
|
||||||
local count = 0
|
local count = 0
|
||||||
for _, itemData in pairs(grabInv) do
|
for _, itemData in pairs(grabInv) do
|
||||||
jsonPrint(itemData)
|
--jsonPrint(itemData)
|
||||||
if itemData and itemData.name == item then
|
if itemData and itemData.name == item then
|
||||||
count += (itemData.amount or itemData.count or 1)
|
count += (itemData.amount or itemData.count or 1)
|
||||||
end
|
end
|
||||||
@@ -138,6 +138,14 @@ function getPlayerInv(src)
|
|||||||
grabInv = exports[TgiannInv]:GetPlayerItems()
|
grabInv = exports[TgiannInv]:GetPlayerItems()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
elseif isStarted(JPRInv) then
|
||||||
|
foundInv = JPRInv
|
||||||
|
if src then
|
||||||
|
grabInv = Core.Functions.GetPlayer(src).PlayerData.items
|
||||||
|
else
|
||||||
|
grabInv = Core.Functions.GetPlayerData().items
|
||||||
|
end
|
||||||
|
|
||||||
elseif isStarted(QBInv) then
|
elseif isStarted(QBInv) then
|
||||||
foundInv = QBInv
|
foundInv = QBInv
|
||||||
if src then
|
if src then
|
||||||
@@ -148,8 +156,11 @@ function getPlayerInv(src)
|
|||||||
|
|
||||||
elseif isStarted(PSInv) then
|
elseif isStarted(PSInv) then
|
||||||
foundInv = PSInv
|
foundInv = PSInv
|
||||||
if src then grabInv = Core.Functions.GetPlayer(src).PlayerData.items
|
if src then
|
||||||
else grabInv = Core.Functions.GetPlayerData().items end
|
grabInv = Core.Functions.GetPlayer(src).PlayerData.items
|
||||||
|
else
|
||||||
|
grabInv = Core.Functions.GetPlayerData().items
|
||||||
|
end
|
||||||
|
|
||||||
elseif ESX and isStarted(ESXExport) then
|
elseif ESX and isStarted(ESXExport) then
|
||||||
foundInv = ESX
|
foundInv = ESX
|
||||||
@@ -179,41 +190,6 @@ function isInventoryOpen()
|
|||||||
|
|
||||||
return IsNuiFocused()
|
return IsNuiFocused()
|
||||||
|
|
||||||
--if isStarted(OXInv) then
|
|
||||||
-- return LocalPlayer.state.invBusy
|
|
||||||
|
|
||||||
--elseif isStarted(QSInv) then
|
|
||||||
-- return exports[QSInv]:inInventory()
|
|
||||||
|
|
||||||
--elseif isStarted(OrigenInv) then
|
|
||||||
-- return exports[OrigenInv]:IsInventoryOpen()
|
|
||||||
|
|
||||||
--elseif isStarted(CoreInv) then
|
|
||||||
-- return exports[CoreInv]:isInventoryOpen()
|
|
||||||
|
|
||||||
--elseif isStarted(CodeMInv) then
|
|
||||||
-- return false
|
|
||||||
-- -- CodeM doesn't have a function to check if the inventory is open
|
|
||||||
-- -- No idea what it uses, so it just skips the check
|
|
||||||
|
|
||||||
--elseif isStarted(TgiannInv) then
|
|
||||||
-- return IsNuiFocused()
|
|
||||||
|
|
||||||
--elseif isStarted(QBInv) then
|
|
||||||
-- return LocalPlayer.state.inv_busy
|
|
||||||
|
|
||||||
--elseif isStarted(PSInv) then
|
|
||||||
-- return LocalPlayer.state.inv_busy
|
|
||||||
|
|
||||||
--elseif ESX and isStarted(ESXExport) then
|
|
||||||
-- return false
|
|
||||||
|
|
||||||
--elseif isStarted(RSGInv) then
|
|
||||||
-- return LocalPlayer.state.inv_busy
|
|
||||||
|
|
||||||
--end
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------
|
-------------------------------------------------------------
|
||||||
@@ -248,12 +224,14 @@ function invImg(item)
|
|||||||
elseif isStarted(OrigenInv) then
|
elseif isStarted(OrigenInv) then
|
||||||
imgLink = "nui://"..OrigenInv.."/html/img/"..(Items[item].image or "")
|
imgLink = "nui://"..OrigenInv.."/html/img/"..(Items[item].image or "")
|
||||||
|
|
||||||
|
elseif isStarted(JPRInv) then
|
||||||
|
imgLink = "nui://"..JPRInv.."/html/images/"..(Items[item].image or "")
|
||||||
|
|
||||||
elseif isStarted(QBInv) then
|
elseif isStarted(QBInv) then
|
||||||
imgLink = "nui://"..QBInv.."/html/images/"..(Items[item].image or "")
|
imgLink = "nui://"..QBInv.."/html/images/"..(Items[item].image or "")
|
||||||
|
|
||||||
elseif isStarted(PSInv) then
|
elseif isStarted(PSInv) then
|
||||||
imgLink = "nui://"..PSInv.."/html/images/"..(Items[item].image or "")
|
imgLink = "nui://"..PSInv.."/html/images/"..(Items[item].image or "")
|
||||||
|
|
||||||
elseif isStarted(TgiannInv) then
|
elseif isStarted(TgiannInv) then
|
||||||
imgLink = "nui://inventory_images/images/"..(Items[item].image or "")
|
imgLink = "nui://inventory_images/images/"..(Items[item].image or "")
|
||||||
|
|
||||||
|
|||||||
@@ -186,6 +186,20 @@ RegisterNetEvent(getScript()..":server:toggleItem", function(give, item, amount,
|
|||||||
invName = TgiannInv
|
invName = TgiannInv
|
||||||
exports[TgiannInv]:RemoveItem(src, item, remamount)
|
exports[TgiannInv]:RemoveItem(src, item, remamount)
|
||||||
|
|
||||||
|
elseif isStarted(JPRInv) then
|
||||||
|
invName = JPRInv
|
||||||
|
while remamount > 0 do
|
||||||
|
if Core.Functions.GetPlayer(src).Functions.RemoveItem(item, 1, slot) then
|
||||||
|
remamount -= 1
|
||||||
|
else
|
||||||
|
print("^1Error removing "..item.." Amount left: "..remamount)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if Config.Crafting ~= nil and Config.Crafting.showItemBox then
|
||||||
|
TriggerClientEvent("inventory:client:ItemBox", src, Items[item], "remove", amount or 1)
|
||||||
|
end
|
||||||
|
|
||||||
elseif isStarted(QBInv) then
|
elseif isStarted(QBInv) then
|
||||||
invName = QBInv
|
invName = QBInv
|
||||||
while remamount > 0 do
|
while remamount > 0 do
|
||||||
@@ -270,6 +284,13 @@ RegisterNetEvent(getScript()..":server:toggleItem", function(give, item, amount,
|
|||||||
elseif isStarted(TgiannInv) then invName = TgiannInv
|
elseif isStarted(TgiannInv) then invName = TgiannInv
|
||||||
exports[TgiannInv]:AddItem(src, item, amountToAdd, slot, info)
|
exports[TgiannInv]:AddItem(src, item, amountToAdd, slot, info)
|
||||||
|
|
||||||
|
elseif isStarted(JPRInv) then invName = JPRInv
|
||||||
|
if Core.Functions.GetPlayer(src).Functions.AddItem(item, amountToAdd, nil, info) then
|
||||||
|
if Config.Crafting ~= nil and Config.Crafting.showItemBox then
|
||||||
|
TriggerClientEvent("ps-inventory:client:ItemBox", src, Items[item], "add", amountToAdd)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
elseif isStarted(QBInv) then invName = QBInv
|
elseif isStarted(QBInv) then invName = QBInv
|
||||||
if Core.Functions.GetPlayer(src).Functions.AddItem(item, amountToAdd, nil, info) then
|
if Core.Functions.GetPlayer(src).Functions.AddItem(item, amountToAdd, nil, info) then
|
||||||
TriggerClientEvent((isStarted(QBInv) and QBInvNew and "qb-" or "").."inventory:client:ItemBox", src, Items[item], "add", amountToAdd)
|
TriggerClientEvent((isStarted(QBInv) and QBInvNew and "qb-" or "").."inventory:client:ItemBox", src, Items[item], "add", amountToAdd)
|
||||||
@@ -379,7 +400,7 @@ end
|
|||||||
function getDurability(item)
|
function getDurability(item)
|
||||||
local lowestSlot = 100
|
local lowestSlot = 100
|
||||||
local durability = nil
|
local durability = nil
|
||||||
if isStarted(QBInv) or isStarted(PSInv) or isStarted(RSGInv) then
|
if isStarted(QBInv) or isStarted(PSInv) or isStarted(RSGInv) or isStarted(JPRInv) then
|
||||||
local itemcheck = Core.Functions.GetPlayerData().items
|
local itemcheck = Core.Functions.GetPlayerData().items
|
||||||
for k, v in pairs(itemcheck) do
|
for k, v in pairs(itemcheck) do
|
||||||
if v.name == item then
|
if v.name == item then
|
||||||
@@ -488,7 +509,7 @@ end
|
|||||||
--- ```
|
--- ```
|
||||||
RegisterNetEvent(getScript()..":server:setMetaData", function(data)
|
RegisterNetEvent(getScript()..":server:setMetaData", function(data)
|
||||||
local src = source
|
local src = source
|
||||||
if isStarted(QBInv) or isStarted(PSInv) or isStarted(RSGInv) then
|
if isStarted(QBInv) or isStarted(PSInv) or isStarted(RSGInv) or isStarted(JPRInv) then
|
||||||
debugPrint(src, data.item, 1, data.slot)
|
debugPrint(src, data.item, 1, data.slot)
|
||||||
local Player = Core.Functions.GetPlayer(src)
|
local Player = Core.Functions.GetPlayer(src)
|
||||||
Player.PlayerData.items[data.slot].info = data.metadata
|
Player.PlayerData.items[data.slot].info = data.metadata
|
||||||
@@ -626,6 +647,22 @@ function canCarry(itemTable, src)
|
|||||||
resultTable[k] = exports[TgiannInv]:CanCarryItem(source, k, v)
|
resultTable[k] = exports[TgiannInv]:CanCarryItem(source, k, v)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
elseif isStarted(JPRInv) then
|
||||||
|
local items = getPlayerInv(src)
|
||||||
|
local totalWeight = 0
|
||||||
|
if not items then return false end
|
||||||
|
for _, item in pairs(items) do
|
||||||
|
totalWeight += (item.weight * item.amount)
|
||||||
|
end
|
||||||
|
for k, v in pairs(itemTable) do
|
||||||
|
local itemInfo = Items[k]
|
||||||
|
if not itemInfo then
|
||||||
|
resultTable[k] = true
|
||||||
|
else
|
||||||
|
resultTable[k] = (totalWeight + (itemInfo.weight * v)) <= InventoryWeight
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
elseif isStarted(QBInv) then
|
elseif isStarted(QBInv) then
|
||||||
if QBInvNew then
|
if QBInvNew then
|
||||||
for k, v in pairs(itemTable) do
|
for k, v in pairs(itemTable) do
|
||||||
|
|||||||
@@ -151,6 +151,22 @@ function openStash(data)
|
|||||||
slots = data.slots or 40
|
slots = data.slots or 40
|
||||||
})
|
})
|
||||||
|
|
||||||
|
elseif isStarted(JPRInv) then
|
||||||
|
if QBInvNew then
|
||||||
|
TriggerServerEvent(getScript()..':server:openServerStash', {
|
||||||
|
stashName = data.stash,
|
||||||
|
label = data.label,
|
||||||
|
maxweight = data.maxWeight or 600000,
|
||||||
|
slots = data.slots or 40
|
||||||
|
})
|
||||||
|
else
|
||||||
|
TriggerEvent("inventory:client:SetCurrentStash", data.stash)
|
||||||
|
TriggerServerEvent("inventory:server:OpenInventory", "stash", data.stash, {
|
||||||
|
slots = data.slots or 50,
|
||||||
|
maxWeight = data.maxWeight or 600000
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
elseif isStarted(QBInv) then
|
elseif isStarted(QBInv) then
|
||||||
if QBInvNew then
|
if QBInvNew then
|
||||||
TriggerServerEvent(getScript()..':server:openServerStash', {
|
TriggerServerEvent(getScript()..':server:openServerStash', {
|
||||||
@@ -211,6 +227,9 @@ RegisterNetEvent(getScript()..":server:openServerStash", function(data)
|
|||||||
if isStarted(TgiannInv) then
|
if isStarted(TgiannInv) then
|
||||||
exports[TgiannInv]:OpenInventory(source, 'stash', data.stashName, data)
|
exports[TgiannInv]:OpenInventory(source, 'stash', data.stashName, data)
|
||||||
end
|
end
|
||||||
|
if isStarted(JPRInv) then
|
||||||
|
exports[JPRInv]:OpenInventory(source, data.stashName, data)
|
||||||
|
end
|
||||||
if isStarted(QBInv) then
|
if isStarted(QBInv) then
|
||||||
exports[QBInv]:OpenInventory(source, data.stashName, data)
|
exports[QBInv]:OpenInventory(source, data.stashName, data)
|
||||||
end
|
end
|
||||||
@@ -223,7 +242,18 @@ RegisterNetEvent(getScript()..":server:openServerStash", function(data)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
function clearStash(stashId)
|
function clearStash(stashId)
|
||||||
if isStarted(QBInv) then
|
if isStarted(JPRInv) then
|
||||||
|
debugPrint("^5Bridge^7: ^2Cleared ^3"..JPRInv.."^2 Stash^7", stashId)
|
||||||
|
if QBInvNew then
|
||||||
|
exports[JPRInv]:ClearStash(stashId)
|
||||||
|
else
|
||||||
|
MySQL.Async.insert('INSERT INTO stashitems (stash, items) VALUES (:stash, :items) ON DUPLICATE KEY UPDATE items = :items', {
|
||||||
|
['stash'] = stashId,
|
||||||
|
['items'] = json.encode({})
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif isStarted(QBInv) then
|
||||||
debugPrint("^5Bridge^7: ^2Cleared ^3"..QBInv.."^2 Stash^7", stashId)
|
debugPrint("^5Bridge^7: ^2Cleared ^3"..QBInv.."^2 Stash^7", stashId)
|
||||||
if QBInvNew then
|
if QBInvNew then
|
||||||
exports[QBInv]:ClearStash(stashId)
|
exports[QBInv]:ClearStash(stashId)
|
||||||
@@ -241,7 +271,7 @@ function clearStash(stashId)
|
|||||||
elseif isStarted(PSInv) then
|
elseif isStarted(PSInv) then
|
||||||
debugPrint("^5Bridge^7: ^2Cleared ^3"..PSInv.."^2 Stash^7", stashId)
|
debugPrint("^5Bridge^7: ^2Cleared ^3"..PSInv.."^2 Stash^7", stashId)
|
||||||
if QBInvNew then
|
if QBInvNew then
|
||||||
exports[QBInv]:ClearStash(stashId)
|
exports[PSInv]:ClearStash(stashId)
|
||||||
else
|
else
|
||||||
MySQL.Async.insert('INSERT INTO stashitems (stash, items) VALUES (:stash, :items) ON DUPLICATE KEY UPDATE items = :items', {
|
MySQL.Async.insert('INSERT INTO stashitems (stash, items) VALUES (:stash, :items) ON DUPLICATE KEY UPDATE items = :items', {
|
||||||
['stash'] = stashId,
|
['stash'] = stashId,
|
||||||
@@ -249,6 +279,7 @@ function clearStash(stashId)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
elseif isStarted(QSInv) then
|
elseif isStarted(QSInv) then
|
||||||
debugPrint("^5Bridge^7: ^2Cleared ^3"..QSInv.."^2 Stash^7", stashId)
|
debugPrint("^5Bridge^7: ^2Cleared ^3"..QSInv.."^2 Stash^7", stashId)
|
||||||
exports[QSInv]:ClearOtherInventory('stash', stashId)
|
exports[QSInv]:ClearOtherInventory('stash', stashId)
|
||||||
@@ -331,6 +362,11 @@ function getStash(stashName)
|
|||||||
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
|
||||||
|
|
||||||
|
elseif isStarted(JPRInv) then
|
||||||
|
stashResource = JPRInv
|
||||||
|
local result = MySQL.scalar.await('SELECT items FROM stashitems WHERE stash = ?', { stashName })
|
||||||
|
if result then stashItems = json.decode(result) end
|
||||||
|
|
||||||
elseif isStarted(QBInv) then
|
elseif isStarted(QBInv) then
|
||||||
stashResource = QBInv
|
stashResource = QBInv
|
||||||
if QBInvNew then
|
if QBInvNew then
|
||||||
@@ -449,6 +485,29 @@ function stashRemoveItem(stashItems, stashName, items)
|
|||||||
debugPrint("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..TgiannInv, k, v)
|
debugPrint("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..TgiannInv, k, v)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
elseif isStarted(JPRInv) then
|
||||||
|
if not stashItems or not next(stashItems) then
|
||||||
|
stashItems = getStash(stashName[1])
|
||||||
|
end
|
||||||
|
for k, v in pairs(items) do
|
||||||
|
for l in pairs(stashItems) do
|
||||||
|
if stashItems[l].name == k then
|
||||||
|
if (stashItems[l].amount - v) <= 0 then
|
||||||
|
debugPrint("^6Bridge^7: ^2None of this item left in stash ^3Stash^7", k, v)
|
||||||
|
stashItems[l] = nil
|
||||||
|
else
|
||||||
|
debugPrint("^6Bridge^7: ^2Removing item from ^3Stash^2 with "..JPRInv, k, v)
|
||||||
|
stashItems[l].amount -= v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
debugPrint("^6Bridge^7: ^3saveStash^7: ^2Saving ^3JPR^2 stash '^6"..stashName[1].."^7'")
|
||||||
|
MySQL.Async.insert('INSERT INTO stashitems (stash, items) VALUES (:stash, :items) ON DUPLICATE KEY UPDATE items = :items', {
|
||||||
|
['stash'] = stashName[1],
|
||||||
|
['items'] = json.encode(stashItems)
|
||||||
|
})
|
||||||
|
|
||||||
elseif isStarted(QBInv) then
|
elseif isStarted(QBInv) then
|
||||||
if QBInvNew then
|
if QBInvNew then
|
||||||
for k, v in pairs(items) do
|
for k, v in pairs(items) do
|
||||||
@@ -531,7 +590,7 @@ RegisterNetEvent(getScript()..":server:stashRemoveItem", stashRemoveItem)
|
|||||||
--- local hasAll, details = stashhasItem(currentStashItems, { iron = 2, wood = 5 })
|
--- local hasAll, details = stashhasItem(currentStashItems, { iron = 2, wood = 5 })
|
||||||
--- ```
|
--- ```
|
||||||
function stashhasItem(stashItems, items, amount)
|
function stashhasItem(stashItems, items, amount)
|
||||||
local invs = { OXInv, QSInv, CoreInv, CodeMInv, OrigenInv, TgiannInv, QBInv, PSInv, RSGInv }
|
local invs = { OXInv, QSInv, CoreInv, CodeMInv, OrigenInv, TgiannInv, JPRInv, QBInv, PSInv, RSGInv }
|
||||||
local foundInv = ""
|
local foundInv = ""
|
||||||
for _, inv in ipairs(invs) do
|
for _, inv in ipairs(invs) do
|
||||||
if isStarted(inv) then
|
if isStarted(inv) then
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ Exports = {
|
|||||||
CodeMInv = "codem-inventory",
|
CodeMInv = "codem-inventory",
|
||||||
OrigenInv = "origen_inventory",
|
OrigenInv = "origen_inventory",
|
||||||
TgiannInv = "tgiann-inventory",
|
TgiannInv = "tgiann-inventory",
|
||||||
|
JPRInv = "jpr-inventory",
|
||||||
|
|
||||||
OXLibExport = "ox_lib",
|
OXLibExport = "ox_lib",
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user