Skip to content

Commit 9aada09

Browse files
committed
Added support for Rc2-inventory
1 parent ee0b291 commit 9aada09

10 files changed

Lines changed: 98 additions & 5 deletions

File tree

it_bridge/config.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Config.FrameworkAdminGroups = {
3636
* Inventories.OX: ox_inventory,
3737
* Inventories.CODEM: codem-inventory
3838
* Inventories.ORIGEN: origen-inventory
39+
* Inventories.Rc2: Rv2-inventory
3940
]]
4041

4142
Config.Inventories = AUTO_DETECT
@@ -46,6 +47,7 @@ Config.InventoryImgPath = {
4647
[Inventories.OX] = "ox_inventory/web/images/",
4748
[Inventories.CODEM] = "codem-inventory/html/images/",
4849
[Inventories.ORIGEN] = "origen_inventory/html/images/",
50+
[Inventories.Rc2] = "Rc2-inventory/html/images/",
4951
}
5052

5153
--[[

it_bridge/modules/init.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ local function detectInventory()
114114
end
115115
end
116116

117+
local function detectRc2()
118+
if GetResourceState('Rc2-inventory') ~= 'missing' then
119+
it.inventory = Inventories.RC2
120+
return Inventories.RC2
121+
end
122+
end
123+
117124
local function detectQS()
118125
if GetResourceState('qs-inventory') ~= 'missing' then
119126
it.inventory = Inventories.QS
@@ -157,7 +164,7 @@ local function detectInventory()
157164
end
158165

159166
if Config.Inventories == AUTO_DETECT then
160-
local inventory = detectPS() or detectQS() or detectOX() or detectCODEM() or detectORIGEN() or detectESX() or detectQB() or STANDALONE
167+
local inventory = detectPS() or detectRc2() or detectQS() or detectOX() or detectCODEM() or detectORIGEN() or detectESX() or detectQB() or STANDALONE
161168
if inventory == STANDALONE then
162169
it.print.warn('[it_bridge] No inventory was detected, you will need to integrate it!')
163170
return

it_bridge/modules/inventory/server/canCarryItem.lua

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,37 @@ function it.canCarryItem(source, item, amount)
5252
return true
5353
end
5454

55+
if it.inventory == Inventories.RC2 then
56+
local Player = CoreObject.Functions.GetPlayer(source)
57+
local itemData = CoreObject.Shared.Items[item:lower()]
58+
if not itemData then it.print.error('[canCarryItem] - No itemData Found!') return true end
59+
60+
-- Get Config Table from the ps-inventory config.lua file
61+
local rc2ConfigFile = LoadResourceFile('Rc2-inventory', 'config.lua')
62+
local rc2Config = json.decode(rc2ConfigFile)
63+
64+
local inventory, items
65+
if Player then
66+
inventory = {
67+
maxWeight = rc2Config.MaxInventoryWeight,
68+
slots = rc2Config.MaxInventorySlots,
69+
}
70+
items = Player.PlayerData.items
71+
end
72+
73+
if not inventory then
74+
it.print.error('[canCarryItem] - Unable to load the player inventory. Please contact the developer.')
75+
return true
76+
end
77+
78+
local weight = itemData.weight * amount
79+
local totalWeight = exports['Rc2-inventory']:GetTotalWeight(items) + weight
80+
if totalWeight > inventory.maxWeight then
81+
return false
82+
end
83+
return true
84+
end
85+
5586
if it.inventory == Inventories.QS then
5687
local canCarryItem = exports['qs-inventory']:CanCarryItem(source, item, amount)
5788
if canCarryItem then return true else return false end

it_bridge/modules/inventory/server/canCarryItems.lua

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,46 @@ function it.canCarryItems(src, itemList)
9999
return false
100100
end
101101
return true
102-
end
102+
end
103+
104+
if it.inventory == Inventories.RC2 then
105+
local Player = CoreObject.Functions.GetPlayer(source)
106+
-- Get Config Table from the ps-inventory config.lua file
107+
local rc2ConfigFile = LoadResourceFile('Rc2-inventory', 'config.lua')
108+
local rc2Config = json.decode(rc2ConfigFile)
109+
110+
local inventory, items
111+
if Player then
112+
inventory = {
113+
maxWeight = rc2Config.MaxInventoryWeight,
114+
slots = rc2Config.MaxInventorySlots,
115+
}
116+
items = Player.PlayerData.items
117+
end
118+
119+
if not inventory then
120+
it.print.error('[canCarryItem] - Unable to load the player inventory. Please contact the developer.')
121+
return true
122+
end
123+
124+
local totalWeight = 0
125+
for item, amount in pairs(itemList) do
126+
local currentItemData = CoreObject.Shared.Items[item:lower()]
127+
if currentItemData then
128+
totalWeight = totalWeight + (currentItemData.weight * amount)
129+
else
130+
it.print.error('[canCarryItem] - No itemData Found for item!', item)
131+
return true
132+
end
133+
end
134+
135+
136+
local inventoryWeight = exports['Rc2-inventory']:GetTotalWeight(items) + totalWeight
137+
if inventoryWeight > inventory.maxWeight then
138+
return false
139+
end
140+
return true
141+
end
103142

104143
if it.inventory == Inventories.ESX then
105144
local xPlayer = it.getPlayer(src)

it_bridge/modules/inventory/server/getItemCount.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function it.getItemCount(source, item, metadata)
2424
if itemCount then return itemCount end
2525
end
2626

27-
if it.inventory == Inventories.PS then
27+
if it.inventory == Inventories.PS or it.inventory == Inventories.RC2 then
2828
local Player = CoreObject.Functions.GetPlayer(source)
2929
if not Player then it.print.error('[getItemCount] - Unable to load Playerdata') return 0 end
3030
local count = 0

it_bridge/modules/inventory/server/getItemLabel.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function it.getItemLabel(itemName)
1313
if item then return item.label end
1414
end
1515

16-
if it.inventory == Inventories.PS then
16+
if it.inventory == Inventories.PS or it.inventory == Inventories.RC2 then
1717
local item = CoreObject.Shared.Items[itemName]
1818
if item then return item.label end
1919
end

it_bridge/modules/inventory/server/giveItem.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ function it.giveItem(source, item, amount, metadata)
2525
return exports['ps-inventory']:AddItem(source, item, amount, false, false, 'Item added by it_bridge')
2626
end
2727

28+
if it.inventory == Inventories.RC2 then
29+
return exports['Rc2-inventory']:AddItem(source, item, amount, nil, nil)
30+
end
31+
2832
if it.inventory == Inventories.QS then
2933
local currentItemCount = it.getItemCount(source, item, metadata or {})
3034
exports['qs-inventory']:AddItem(source, item, amount, nil, metadata or {})

it_bridge/modules/inventory/server/hasItem.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ function it.hasItem(source, item, amount, metadata)
2929
if hasItem then return true else return false end
3030
end
3131

32+
if it.inventory == Inventories.RC2 then
33+
local hasItem = exports['Rc2-inventory']:HasItem(source, item, amount)
34+
if hasItem then return true else return false end
35+
end
36+
3237
if it.inventory == Inventories.QS then
3338
local totalAmount = exports['qs-inventory']:GetItemTotalAmount(source, item)
3439
if totalAmount then

it_bridge/modules/inventory/server/removeItem.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ function it.removeItem(source, item, amount, metadata)
2121
return exports['qb-inventory']:RemoveItem(source, item, amount)
2222
end
2323

24-
if it.inventory == Inventories.PS then
24+
if it.inventory == Inventories.RC2 then
2525
return exports['ps-inventory']:RemoveItem(source, item, amount)
2626
end
2727

28+
if it.inventory == Inventories.PS then
29+
return exports['Rc2-inventory']:RemoveItem(source, item, amount)
30+
end
31+
2832
if it.inventory == Inventories.QS then
2933
local currentItemCount = it.getItemCount(source, item, metadata or {})
3034
exports['qs-inventory']:RemoveItem(source, item, amount, metadata or {})

it_bridge/modules/variables.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Inventories = {
3333
OX = 'ox_inventory',
3434
CODEM = 'codem-inventory',
3535
ORIGEN = 'origen_inventory',
36+
RC2 = 'Rc2-inventory',
3637
}
3738

3839
Interactions = {

0 commit comments

Comments
 (0)