@@ -60,14 +60,97 @@ CreateThread(function()
60
60
return true
61
61
end , {
62
62
print = false ,
63
- itemFilter = {
64
- bag1 = true ,
65
- bag2 = true
66
- },
63
+ Config .Filter
64
+ })
65
+
66
+ local createHook
67
+ createHook = exports .ox_inventory :registerHook (' createItem' , function (payload )
68
+ local count_bagpacks = 0
69
+
70
+ for vbag in pairs (Config .Backpacks ) do
71
+ count_bagpacks = ox_inventory :GetItem (payload .inventoryId , vbag , nil , true )
72
+ local playerItems = ox_inventory :GetInventoryItems (payload .inventoryId )
73
+
74
+
75
+ if count_bagpacks > 0 then
76
+ local slot = nil
77
+
78
+ for i ,k in pairs (playerItems ) do
79
+ if k .name == vbag then
80
+ slot = k .slot
81
+ break
82
+ end
83
+ end
84
+
85
+ Citizen .CreateThread (function ()
86
+ local inventoryId = payload .inventoryId
87
+ local dontRemove = slot
88
+ Citizen .Wait (1000 )
89
+
90
+ for i ,k in pairs (ox_inventory :GetInventoryItems (inventoryId )) do
91
+ if k .name == vbag and dontRemove ~= nil and k .slot ~= dontRemove then
92
+ local success = ox_inventory :RemoveItem (inventoryId , vbag , 1 , nil , k .slot )
93
+ if success then
94
+ TriggerClientEvent (' ox_lib:notify' , inventoryId , {type = ' error' , title = Strings .action_incomplete , description = Strings .one_backpack_only })
95
+ end
96
+ break
97
+ end
98
+ end
99
+ end )
100
+ end
101
+ end
102
+
103
+ --[[
104
+ print(ox_inventory:GetItemCount(payload.inventoryId, "bag1", nil, false))
105
+ for vbag in pairs(Config.Backpacks) do
106
+ --count_bagpacks = ox_inventory:GetItem(payload.inventoryId, vbag, nil, true)
107
+ count_bagpacks = ox_inventory:GetItemCount(payload.inventoryId, vbag, nil, false)
108
+ local count_backpacks = ox_inventory:GetItemCount(payload.inventoryId, vbag, nil, false)
109
+ print("count: "..count_bagpacks)
110
+ print("vbag: "..vbag)
111
+ if count_backpacks >= 1 then
112
+ bag_pack = vbag
113
+ end
114
+ end
115
+ print("count: "..count_bagpacks)
116
+ local playerItems = ox_inventory:GetInventoryItems(payload.inventoryId)
117
+
118
+ if count_bagpacks > 0 then
119
+ local slot = nil
120
+
121
+ for i,k in pairs(playerItems) do
122
+ if k.name == bag_pack then
123
+ slot = k.slot
124
+ break
125
+ end
126
+ end
127
+
128
+ Citizen.CreateThread(function()
129
+ local inventoryId = payload.inventoryId
130
+ local dontRemove = slot
131
+ Citizen.Wait(1000)
132
+
133
+ for i,k in pairs(ox_inventory:GetInventoryItems(inventoryId)) do
134
+ if k.name == bag_pack and dontRemove ~= nil and k.slot ~= dontRemove then
135
+ local success = ox_inventory:RemoveItem(inventoryId, bag_pack, 1, nil, k.slot)
136
+ if success then
137
+ TriggerClientEvent('ox_lib:notify', inventoryId, {type = 'error', title = Strings.action_incomplete, description = Strings.one_backpack_only})
138
+ end
139
+ break
140
+ end
141
+ end
142
+ end)
143
+ end
144
+ --]]
145
+
146
+ end , {
147
+ print = false ,
148
+ Config .Filter
67
149
})
68
150
69
151
AddEventHandler (' onResourceStop' , function ()
70
152
ox_inventory :removeHooks (swapHook )
153
+ ox_inventory :removeHooks (createHook )
71
154
end )
72
155
end )
73
156
0 commit comments