Skip to content

Commit d820881

Browse files
authored
Readded code for onebagtype per playerinv
Readded old code for only letting a player have onebag type when buying it in a shop
1 parent 26d1638 commit d820881

File tree

3 files changed

+88
-8
lines changed

3 files changed

+88
-8
lines changed

fxmanifest.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ game 'gta5'
33
lua54 'yes'
44

55
description 'Clothing Based Backpack for Ox Inventory'
6-
version '1.0.4'
6+
version '1.0.5'
77

88
client_scripts {
99
'client/**.lua'

server/server.lua

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,97 @@ CreateThread(function()
6060
return true
6161
end, {
6262
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
67149
})
68150

69151
AddEventHandler('onResourceStop', function()
70152
ox_inventory:removeHooks(swapHook)
153+
ox_inventory:removeHooks(createHook)
71154
end)
72155
end)
73156

server/updater.lua

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
-----------------For support, scripts, and more----------------
2-
--------------- https://discord.gg/wasabiscripts -------------
3-
---------------------------------------------------------------
41
if Config.checkForUpdates then
52
local curVersion = GetResourceMetadata(GetCurrentResourceName(), "version")
63
local resourceName = "unr3al_backpack"

0 commit comments

Comments
 (0)