diff --git a/frameworkCache.lua b/frameworkCache.lua index 002b9c4..84643f7 100644 --- a/frameworkCache.lua +++ b/frameworkCache.lua @@ -20,6 +20,7 @@ local Exports = { CodeMInv = "codem-inventory", OrigenInv = "origen_inventory", TgiannInv = "tgiann-inventory", + JPRInv = "jpr-inventory", OXLibExport = "ox_lib", diff --git a/shared/coreloader.lua b/shared/coreloader.lua index 5d32050..1ce8f57 100644 --- a/shared/coreloader.lua +++ b/shared/coreloader.lua @@ -10,7 +10,7 @@ OXLibExport, QBXExport, QBExport, ESXExport, OXCoreExport = Exports.ESXExport 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.QBInv or "", Exports.PSInv or "", @@ -18,7 +18,8 @@ OXInv, QBInv, PSInv, QSInv, CoreInv, CodeMInv, OrigenInv, TgiannInv = Exports.CoreInv or "", Exports.CodeMInv or "", Exports.OrigenInv or "", - Exports.TgiannInv or "" + Exports.TgiannInv or "", + Exports.JPRInv or "" RSGExport, RSGInv = Exports.RSGExport or "", Exports.RSGInv or "" QBMenuExport = Exports.QBMenuExport or "" diff --git a/shared/inventories.lua b/shared/inventories.lua index 9e850a2..e6c4f47 100644 --- a/shared/inventories.lua +++ b/shared/inventories.lua @@ -50,7 +50,7 @@ function hasItem(items, amount, src) local count = 0 for _, itemData in pairs(grabInv) do - jsonPrint(itemData) + --jsonPrint(itemData) if itemData and itemData.name == item then count += (itemData.amount or itemData.count or 1) end @@ -138,6 +138,14 @@ function getPlayerInv(src) grabInv = exports[TgiannInv]:GetPlayerItems() 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 foundInv = QBInv if src then @@ -148,8 +156,11 @@ function getPlayerInv(src) elseif isStarted(PSInv) then foundInv = PSInv - if src then grabInv = Core.Functions.GetPlayer(src).PlayerData.items - else grabInv = Core.Functions.GetPlayerData().items end + if src then + grabInv = Core.Functions.GetPlayer(src).PlayerData.items + else + grabInv = Core.Functions.GetPlayerData().items + end elseif ESX and isStarted(ESXExport) then foundInv = ESX @@ -179,41 +190,6 @@ function isInventoryOpen() 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 ------------------------------------------------------------- @@ -248,12 +224,14 @@ function invImg(item) elseif isStarted(OrigenInv) then 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 imgLink = "nui://"..QBInv.."/html/images/"..(Items[item].image or "") elseif isStarted(PSInv) then imgLink = "nui://"..PSInv.."/html/images/"..(Items[item].image or "") - elseif isStarted(TgiannInv) then imgLink = "nui://inventory_images/images/"..(Items[item].image or "") diff --git a/shared/itemcontrol.lua b/shared/itemcontrol.lua index a258cd9..3c83a90 100644 --- a/shared/itemcontrol.lua +++ b/shared/itemcontrol.lua @@ -186,6 +186,20 @@ RegisterNetEvent(getScript()..":server:toggleItem", function(give, item, amount, invName = TgiannInv 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 invName = QBInv while remamount > 0 do @@ -270,6 +284,13 @@ RegisterNetEvent(getScript()..":server:toggleItem", function(give, item, amount, elseif isStarted(TgiannInv) then invName = TgiannInv 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 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) @@ -379,7 +400,7 @@ end function getDurability(item) local lowestSlot = 100 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 for k, v in pairs(itemcheck) do if v.name == item then @@ -488,7 +509,7 @@ end --- ``` RegisterNetEvent(getScript()..":server:setMetaData", function(data) 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) local Player = Core.Functions.GetPlayer(src) Player.PlayerData.items[data.slot].info = data.metadata @@ -626,6 +647,22 @@ function canCarry(itemTable, src) resultTable[k] = exports[TgiannInv]:CanCarryItem(source, k, v) 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 if QBInvNew then for k, v in pairs(itemTable) do diff --git a/shared/stashcontrol.lua b/shared/stashcontrol.lua index a7f2edd..324fa6a 100644 --- a/shared/stashcontrol.lua +++ b/shared/stashcontrol.lua @@ -151,6 +151,22 @@ function openStash(data) 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 if QBInvNew then TriggerServerEvent(getScript()..':server:openServerStash', { @@ -211,6 +227,9 @@ RegisterNetEvent(getScript()..":server:openServerStash", function(data) if isStarted(TgiannInv) then exports[TgiannInv]:OpenInventory(source, 'stash', data.stashName, data) end + if isStarted(JPRInv) then + exports[JPRInv]:OpenInventory(source, data.stashName, data) + end if isStarted(QBInv) then exports[QBInv]:OpenInventory(source, data.stashName, data) end @@ -223,7 +242,18 @@ RegisterNetEvent(getScript()..":server:openServerStash", function(data) end) 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) if QBInvNew then exports[QBInv]:ClearStash(stashId) @@ -241,7 +271,7 @@ function clearStash(stashId) elseif isStarted(PSInv) then debugPrint("^5Bridge^7: ^2Cleared ^3"..PSInv.."^2 Stash^7", stashId) if QBInvNew then - exports[QBInv]:ClearStash(stashId) + exports[PSInv]:ClearStash(stashId) else MySQL.Async.insert('INSERT INTO stashitems (stash, items) VALUES (:stash, :items) ON DUPLICATE KEY UPDATE items = :items', { ['stash'] = stashId, @@ -249,6 +279,7 @@ function clearStash(stashId) }) end + elseif isStarted(QSInv) then debugPrint("^5Bridge^7: ^2Cleared ^3"..QSInv.."^2 Stash^7", 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 }) 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 stashResource = QBInv 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) 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 if QBInvNew then 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 }) --- ``` 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 = "" for _, inv in ipairs(invs) do if isStarted(inv) then diff --git a/starter.lua b/starter.lua index 107a00e..7fc3c6f 100644 --- a/starter.lua +++ b/starter.lua @@ -14,6 +14,7 @@ Exports = { CodeMInv = "codem-inventory", OrigenInv = "origen_inventory", TgiannInv = "tgiann-inventory", + JPRInv = "jpr-inventory", OXLibExport = "ox_lib",