Skip to content

Commit

Permalink
Added the support of multiple bag Items
Browse files Browse the repository at this point in the history
  • Loading branch information
1OSaft authored Dec 29, 2023
1 parent 6336037 commit 9624e08
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 135 deletions.
56 changes: 51 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# wasabi_backpack
# unr3al_backpack

This resource was created as a free script for backpacks using ox_inventory

Expand All @@ -11,25 +11,71 @@ This resource was created as a free script for backpacks using ox_inventory

- Download this script
- Add backpack to inventory as it is in "Extra Information" below
- Add backpack image to inventory images (found in `wasabi_backpack/_inventory_images/backpack.png`)
- Add backpack image to inventory images (found in `unr3al_backpack/_inventory_images/backpack.png`)
- Put script in your `resources` directory
- ensure `wasabi_backpack` *after* `ox_lib` but *before* `ox_inventory`
- ensure `unr3al_backpack` *after* `ox_lib` but *before* `ox_inventory`

# Dependencies
- ox_inventory

## Extra Information

You can add infinite backpacks, just adjust the config for your liking.
Then add the export to your `ox_inventory/data/items.lua`. The ending of the export is always the itemname you defined in your config.lua



Item to add to `ox_inventory/data/items.lua`
```
['backpack'] = {
['bag1'] = {
label = 'Backpack',
weight = 220,
stack = false,
consume = 0,
client = {
export = 'wasabi_backpack.openBackpack'
export = 'unr3al_backpack.openBackpack_bag1'
}
},
['bag2'] = {
label = 'Backpack',
weight = 220,
stack = false,
consume = 0,
client = {
export = 'unr3al_backpack.openBackpack_bag2'
}
},
```
Configure the bags in `unr3al_backpack/config.lua`
```
['bag1'] = {
Slots = 35,
Weight = 20000,
Uniform = {
Male = {
['bags_1'] = 41,
['bags_2'] = 0,
},
Female = {
['bags_1'] = 41,
['bags_2'] = 0,
}
}
},
['bag2'] = {
Slots = 15,
Weight = 5000,
Uniform = {
Male = {
['bags_1'] = 41,
['bags_2'] = 0,
},
Female = {
['bags_1'] = 41,
['bags_2'] = 0,
}
}
},
```

## Preview from Wasabi
Expand Down
80 changes: 46 additions & 34 deletions client/client.lua
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
-----------------For support, scripts, and more----------------
--------------- https://discord.gg/wasabiscripts -------------
---------------------------------------------------------------

local bagEquipped, bagObj
local hash = `p_michael_backpack_s`
local bagEquipped, bagObj, skin
local ox_inventory = exports.ox_inventory
local ped = cache.ped
local justConnect = true
local skin
local count = 0


local function PutOnBag()
print("Putting on Backpack")
local function PutOnBag(bagtype)
bagtype = bagtype
if Config.Debug then print("Putting on Backpack") end
if Config.Debug then print("Bag type: "..bagtype) end
TriggerEvent('skinchanger:getSkin', function(skin)
if skin.sex == 0 then
TriggerEvent('skinchanger:loadClothes', skin, Config.Uniforms.Male)
TriggerEvent('skinchanger:loadClothes', skin, Config.Backpacks[bagtype].Uniform.Male)
else
TriggerEvent('skinchanger:loadClothes', skin, Config.Uniforms.Female)
TriggerEvent('skinchanger:loadClothes', skin, Config.Backpacks[bagtype].Uniform.Female)
end
saveSkin()
end)
Expand All @@ -27,12 +24,12 @@ saveSkin = function()
Wait(100)

TriggerEvent('skinchanger:getSkin', function(skin)
TriggerServerEvent('wasabi_backpack:save', skin)
TriggerServerEvent('unr3al_backpack:save', skin)
end)
end

local function RemoveBag()
print("Removing Backpack")
if Config.Debug then print("Removing Backpack") end
TriggerEvent('skinchanger:getSkin', function(skin)
if skin.sex == 0 then
TriggerEvent('skinchanger:loadClothes', skin, Config.CleanUniforms.Male)
Expand All @@ -50,24 +47,31 @@ AddEventHandler('ox_inventory:updateInventory', function(changes)
Wait(4500)
justConnect = nil
end
if Config.Debug then print("Update Inv") end
for k, v in pairs(changes) do
if Config.Debug then print("V: "..tostring(v)) end
if type(v) == 'table' then
local count = ox_inventory:Search('count', 'backpack')
if count > 0 and (not bagEquipped or not bagObj) then
PutOnBag()
elseif count < 1 and bagEquipped then
RemoveBag()
for vbag in pairs(Config.Backpacks) do
count = count + ox_inventory:Search('count', vbag)
if count > 0 and (not bagEquipped or not bagObj) then
for vbag in pairs(Config.Backpacks) do
bagcount = ox_inventory:GetItemCount(vbag)
if bagcount >= 1 then
PutOnBag(vbag)
if Config.Debug then print("Count: "..bagcount) end
end
end
elseif count < 1 and bagEquipped then
RemoveBag()
end
end

end
if type(v) == 'boolean' then
local count = ox_inventory:Search('count', 'backpack')
if count < 1 and bagEquipped then
RemoveBag()
end
RemoveBag()
end
end
end)

lib.onCache('ped', function(value)
ped = value
end)
Expand All @@ -77,19 +81,27 @@ lib.onCache('vehicle', function(value)
if value then
RemoveBag()
else
local count = ox_inventory:Search('count', 'backpack')
for vbag in pairs(Config.Backpacks) do
count = count + ox_inventory:Search('count', vbag)
end
if count and count >= 1 then
PutOnBag()
PutOnBag(bagtype)
end
end
end)

exports('openBackpack', function(data, slot)
if not slot?.metadata?.identifier then
local identifier = lib.callback.await('wasabi_backpack:getNewIdentifier', 100, data.slot)
ox_inventory:openInventory('stash', 'bag_'..identifier)
else
TriggerServerEvent('wasabi_backpack:openBackpack', slot.metadata.identifier)
ox_inventory:openInventory('stash', 'bag_'..slot.metadata.identifier)
end
end)
for kbag in pairs(Config.Backpacks) do
local bagtype = kbag
exports('openBackpack_'..bagtype, function(data, slot)
if Config.Debug then print("Export "..bagtype.." Triggered") end
if not slot?.metadata?.identifier then
local identifier = lib.callback.await('unr3al_backpack:getNewIdentifier', 100, data.slot, bagtype)
ox_inventory:openInventory('stash', bagtype..'_'..identifier)
if Config.Debug then print("Registered new identifier") end
else
TriggerServerEvent('unr3al_backpack:openBackpack', slot.metadata.identifier, bagtype)
ox_inventory:openInventory('stash', bagtype..'_'..slot.metadata.identifier)
if Config.Debug then print("Triggering open backpack") end
end
end)
end
56 changes: 36 additions & 20 deletions config.lua
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
-----------------For support, scripts, and more----------------
--------------- https://discord.gg/wasabiscripts -------------
---------------------------------------------------------------
Config = {}

Config.checkForUpdates = true -- Check for updates?
Config.Debug = false

Config.OneBagInInventory = true -- Allow only one bag in inventory?

Config.BackpackStorage = {
slots = 35, -- Slots of backpack storage
weight = 20000 -- Total weight for backpack
}


Config.Uniforms = {

Male = {
['bags_1'] = 41,
['bags_2'] = 0,
},
Female = {
['bags_1'] = 41,
['bags_2'] = 0,
Config.Filter = { -- Items not allowed in your bags
itemFilter = {
bag1 = true,
bag2 = true
}
}

Expand All @@ -37,6 +22,37 @@ Config.CleanUniforms = {
}
}

Config.Backpacks = {
['bag1'] = {
Slots = 35,
Weight = 20000,
Uniform = {
Male = {
['bags_1'] = 41,
['bags_2'] = 0,
},
Female = {
['bags_1'] = 41,
['bags_2'] = 0,
}
}
},
['bag2'] = {
Slots = 15,
Weight = 5000,
Uniform = {
Male = {
['bags_1'] = 41,
['bags_2'] = 0,
},
Female = {
['bags_1'] = 41,
['bags_2'] = 0,
}
}
},
}

Strings = { -- Notification strings
action_incomplete = 'Action Incomplete',
one_backpack_only = 'You can only have 1x backpack!',
Expand Down
5 changes: 1 addition & 4 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
-----------------For support, scripts, and more----------------
--------------- https://discord.gg/wasabiscripts -------------
---------------------------------------------------------------
fx_version 'cerulean'
game 'gta5'
lua54 'yes'

description 'Wasabi Backpack for Ox Inventory'
version '1.0.4'
version '1.0.1'

client_scripts {
'client/**.lua'
Expand Down
Loading

0 comments on commit 9624e08

Please sign in to comment.