-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert: wasabi_backpack > bpt_backpack
- Loading branch information
1 parent
a040603
commit ca7482c
Showing
8 changed files
with
202 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<h1 align='center'>bpt_backpack</a></h1> | ||
<p align='center'><a href='https://discord.gg/ksGfNvDEfq'>Discord</a> | ||
|
||
Copyright (C) 2024 bitpredator | ||
|
||
This program Is free software: you can redistribute it And/Or modify it under the terms Of the GNU General Public License As published by the Free Software Foundation, either version 3 Of the License, Or (at your option) any later version. | ||
|
||
This program Is distributed In the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty Of MERCHANTABILITY Or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License For more details. | ||
|
||
ATTENTION: | ||
You are not authorized to change the name of the resource and the resources within it. | ||
|
||
If you want to contribute you can open a pull request. | ||
|
||
You are not authorized to sell this software (this is free project). | ||
|
||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/. | ||
|
||
This resource was created as a free script for backpacks using ox_inventory | ||
|
||
<b>Features:</b> | ||
- 0.0 ms Usage | ||
- Perisistent backpack prop added to back when in inventory | ||
- Customizable item name and storage parameters | ||
- Compatibility for ox_core, ESX, QBCore, whatever else running ox_inventory | ||
|
||
## Installation | ||
|
||
- Download this script | ||
- Add backpack to inventory as it is in "Extra Information" below | ||
- Put script in your `resources` directory | ||
- ensure `bpt_backpack` *after* `ox_lib` but *before* `ox_inventory` | ||
|
||
# Dependencies | ||
- ox_inventory | ||
|
||
## Extra Information | ||
Item to add to `ox_inventory/data/items.lua` | ||
``` | ||
['backpack'] = { | ||
label = 'Backpack', | ||
weight = 220, | ||
stack = false, | ||
consume = 0, | ||
client = { | ||
export = 'bpt_backpack.openBackpack' | ||
} | ||
}, | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
server-data/resources/[bpt_addons]/bpt_backpack/config.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Config = {} | ||
Config.OneBagInInventory = true -- Allow only one bag in inventory? | ||
|
||
Config.BackpackStorage = { | ||
slots = 8, -- Slots of backpack storage | ||
weight = 10000, -- Total weight for backpack | ||
} | ||
|
||
Strings = { -- Notification strings | ||
action_incomplete = "Action Incomplete", | ||
one_backpack_only = "You can only have 1x backpack!", | ||
backpack_in_backpack = "You can't place a backpack within another!", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
server-data/resources/[bpt_addons]/bpt_backpack/server/server.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
local registeredStashes = {} | ||
local ox_inventory = exports.ox_inventory | ||
|
||
local function GenerateText(num) | ||
local str | ||
repeat | ||
str = {} | ||
for i = 1, num do | ||
str[i] = string.char(math.random(65, 90)) | ||
end | ||
str = table.concat(str) | ||
until str ~= "POL" and str ~= "EMS" | ||
return str | ||
end | ||
|
||
local function GenerateSerial(text) | ||
if text and text:len() > 3 then | ||
return text | ||
end | ||
return ("%s%s%s"):format(math.random(100000, 999999), text == nil and GenerateText(3) or text, math.random(100000, 999999)) | ||
end | ||
|
||
RegisterServerEvent("bpt_backpack:openBackpack") | ||
AddEventHandler("bpt_backpack:openBackpack", function(identifier) | ||
if not registeredStashes[identifier] then | ||
ox_inventory:RegisterStash("bag_" .. identifier, "Backpack", Config.BackpackStorage.slots, Config.BackpackStorage.weight, false) | ||
registeredStashes[identifier] = true | ||
end | ||
end) | ||
|
||
lib.callback.register("bpt_backpack:getNewIdentifier", function(source, slot) | ||
local newId = GenerateSerial() | ||
ox_inventory:SetMetadata(source, slot, { identifier = newId }) | ||
ox_inventory:RegisterStash("bag_" .. newId, "Backpack", Config.BackpackStorage.slots, Config.BackpackStorage.weight, false) | ||
registeredStashes[newId] = true | ||
return newId | ||
end) | ||
|
||
CreateThread(function() | ||
while GetResourceState("ox_inventory") ~= "started" do | ||
Wait(500) | ||
end | ||
local swapHook = ox_inventory:registerHook("swapItems", function(payload) | ||
local start, destination, move_type = payload.fromInventory, payload.toInventory, payload.toType | ||
local count_bagpacks = ox_inventory:GetItem(payload.source, "backpack", nil, true) | ||
|
||
if string.find(destination, "bag_") then | ||
TriggerClientEvent("ox_lib:notify", payload.source, { type = "error", title = Strings.action_incomplete, description = Strings.backpack_in_backpack }) | ||
return false | ||
end | ||
if Config.OneBagInInventory then | ||
if count_bagpacks > 0 and move_type == "player" and destination ~= start then | ||
TriggerClientEvent("ox_lib:notify", payload.source, { type = "error", title = Strings.action_incomplete, description = Strings.one_backpack_only }) | ||
return false | ||
end | ||
end | ||
|
||
return true | ||
end, { | ||
print = false, | ||
itemFilter = { | ||
backpack = true, | ||
}, | ||
}) | ||
|
||
local createHook | ||
if Config.OneBagInInventory then | ||
createHook = exports.ox_inventory:registerHook("createItem", function(payload) | ||
local count_bagpacks = ox_inventory:GetItem(payload.inventoryId, "backpack", nil, true) | ||
local playerItems = ox_inventory:GetInventoryItems(payload.inventoryId) | ||
|
||
if count_bagpacks > 0 then | ||
local slot = nil | ||
|
||
for i, k in pairs(playerItems) do | ||
if k.name == "backpack" then | ||
slot = k.slot | ||
break | ||
end | ||
end | ||
|
||
Citizen.CreateThread(function() | ||
local inventoryId = payload.inventoryId | ||
local dontRemove = slot | ||
Citizen.Wait(1000) | ||
|
||
for i, k in pairs(ox_inventory:GetInventoryItems(inventoryId)) do | ||
if k.name == "backpack" and dontRemove ~= nil and k.slot ~= dontRemove then | ||
local success = ox_inventory:RemoveItem(inventoryId, "backpack", 1, nil, k.slot) | ||
if success then | ||
TriggerClientEvent("ox_lib:notify", inventoryId, { type = "error", title = Strings.action_incomplete, description = Strings.one_backpack_only }) | ||
end | ||
break | ||
end | ||
end | ||
end) | ||
end | ||
end, { | ||
print = false, | ||
itemFilter = { | ||
backpack = true, | ||
}, | ||
}) | ||
end | ||
|
||
AddEventHandler("onResourceStop", function() | ||
ox_inventory:removeHooks(swapHook) | ||
if Config.OneBagInInventory then | ||
ox_inventory:removeHooks(createHook) | ||
end | ||
end) | ||
end) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
37 changes: 0 additions & 37 deletions
37
server-data/resources/[wasabi]/wasabi_backpack/server/server.lua
This file was deleted.
Oops, something went wrong.