diff --git a/server-data/resources/[esx_addons]/esx_addoninventory/LICENSE b/server-data/resources/[bpt_addons]/bpt_addoninventory/LICENSE similarity index 98% rename from server-data/resources/[esx_addons]/esx_addoninventory/LICENSE rename to server-data/resources/[bpt_addons]/bpt_addoninventory/LICENSE index b13054b5e..62f066311 100644 --- a/server-data/resources/[esx_addons]/esx_addoninventory/LICENSE +++ b/server-data/resources/[bpt_addons]/bpt_addoninventory/LICENSE @@ -1,7 +1,7 @@ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. @@ -631,8 +631,8 @@ to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. - esx_addoninventory - Copyright (C) 2015-2022 Jérémie N'gadi + + 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 @@ -645,14 +645,14 @@ the "copyright" line and a pointer to where the full notice is found. 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 . + along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: - esx_addoninventory Copyright (C) 2015-2022 Jérémie N'gadi + Copyright (C) 2024 bitpredator This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. @@ -664,11 +664,11 @@ might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see -. +. The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read -. \ No newline at end of file +. diff --git a/server-data/resources/[bpt_addons]/bpt_addoninventory/README.md b/server-data/resources/[bpt_addons]/bpt_addoninventory/README.md new file mode 100644 index 000000000..adc4c388f --- /dev/null +++ b/server-data/resources/[bpt_addons]/bpt_addoninventory/README.md @@ -0,0 +1,19 @@ +

bpt_addoninventory

+

Discord + +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/. \ No newline at end of file diff --git a/server-data/resources/[esx_addons]/esx_addoninventory/esx_addoninventory.sql b/server-data/resources/[bpt_addons]/bpt_addoninventory/bpt_addoninventory.sql similarity index 99% rename from server-data/resources/[esx_addons]/esx_addoninventory/esx_addoninventory.sql rename to server-data/resources/[bpt_addons]/bpt_addoninventory/bpt_addoninventory.sql index e8007511d..1019324ff 100644 --- a/server-data/resources/[esx_addons]/esx_addoninventory/esx_addoninventory.sql +++ b/server-data/resources/[bpt_addons]/bpt_addoninventory/bpt_addoninventory.sql @@ -18,4 +18,4 @@ CREATE TABLE `addon_inventory_items` ( INDEX `index_addon_inventory_items_inventory_name_name` (`inventory_name`, `name`), INDEX `index_addon_inventory_items_inventory_name_name_owner` (`inventory_name`, `name`, `owner`), INDEX `index_addon_inventory_inventory_name` (`inventory_name`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/server-data/resources/[bpt_addons]/bpt_addoninventory/fxmanifest.lua b/server-data/resources/[bpt_addons]/bpt_addoninventory/fxmanifest.lua new file mode 100644 index 000000000..105e4b672 --- /dev/null +++ b/server-data/resources/[bpt_addons]/bpt_addoninventory/fxmanifest.lua @@ -0,0 +1,22 @@ +fx_version 'adamant' + +game 'gta5' + +description 'Adds a way for resources to store items for players' +lua54 'yes' + +version '1.0.1' + +server_scripts { + '@es_extended/imports.lua', + '@oxmysql/lib/MySQL.lua', + 'server/classes/addoninventory.lua', + 'server/main.lua' +} + +server_exports { + 'GetSharedInventory', + 'AddSharedInventory' +} + +dependency 'es_extended' diff --git a/server-data/resources/[bpt_addons]/bpt_addoninventory/server/classes/addoninventory.lua b/server-data/resources/[bpt_addons]/bpt_addoninventory/server/classes/addoninventory.lua new file mode 100644 index 000000000..09fb2ebe8 --- /dev/null +++ b/server-data/resources/[bpt_addons]/bpt_addoninventory/server/classes/addoninventory.lua @@ -0,0 +1,89 @@ +local self, name, owner, items = {}, {}, {}, {} +self.name = name +self.owner = owner +self.items = items + +function CreateAddonInventory() + function self.addItem(name, count) + local item = self.getItem(name) + item.count = item.count + count + + self.saveItem(name, item.count) + end + + function self.removeItem(name, count) + if count > 0 then + local item = self.getItem(name) + item.count = item.count - count + + self.saveItem(name, item.count) + end + end + + function self.setItem(name, count) + local item = self.getItem(name) + item.count = count + + self.saveItem(name, item.count) + end + + function self.getItem(name) + for i = 1, #self.items, 1 do + if self.items[i].name == name then + return self.items[i] + end + end + + item = { + name = name, + count = 0, + label = Items[name] + } + + table.insert(self.items, item) + + if self.owner == nil then + MySQL.update( + 'INSERT INTO addon_inventory_items (inventory_name, name, count) VALUES (@inventory_name, @item_name, @count)', + { + ['@inventory_name'] = self.name, + ['@item_name'] = name, + ['@count'] = 0 + }) + else + MySQL.update( + 'INSERT INTO addon_inventory_items (inventory_name, name, count, owner) VALUES (@inventory_name, @item_name, @count, @owner)', + { + ['@inventory_name'] = self.name, + ['@item_name'] = name, + ['@count'] = 0, + ['@owner'] = self.owner + }) + end + + return item + end + + function self.saveItem(name, count) + if self.owner == nil then + MySQL.update( + 'UPDATE addon_inventory_items SET count = @count WHERE inventory_name = @inventory_name AND name = @item_name', + { + ['@inventory_name'] = self.name, + ['@item_name'] = name, + ['@count'] = count + }) + else + MySQL.update( + 'UPDATE addon_inventory_items SET count = @count WHERE inventory_name = @inventory_name AND name = @item_name AND owner = @owner', + { + ['@inventory_name'] = self.name, + ['@item_name'] = name, + ['@count'] = count, + ['@owner'] = self.owner + }) + end + end + + return self +end diff --git a/server-data/resources/[bpt_addons]/bpt_addoninventory/server/main.lua b/server-data/resources/[bpt_addons]/bpt_addoninventory/server/main.lua new file mode 100644 index 000000000..2835f1214 --- /dev/null +++ b/server-data/resources/[bpt_addons]/bpt_addoninventory/server/main.lua @@ -0,0 +1,131 @@ +if ESX.GetConfig().OxInventory then + AddEventHandler('onServerResourceStart', function(resourceName) + if resourceName == 'ox_inventory' or resourceName == GetCurrentResourceName() then + local stashes = MySQL.query.await('SELECT * FROM addon_inventory') + + for i = 1, #stashes do + local stash = stashes[i] + local jobStash = stash.name:find('society') and string.sub(stash.name, 9) + exports.ox_inventory:RegisterStash(stash.name, stash.label, 100, 200000, + stash.shared == 0 and true or false, jobStash) + end + end + end) + + return +end + +Items = {} +local InventoriesIndex, Inventories, SharedInventories = {}, {}, {} + +MySQL.ready(function() + local items = MySQL.query.await('SELECT * FROM items') + + for i = 1, #items, 1 do + Items[items[i].name] = items[i].label + end + + local result = MySQL.query.await('SELECT * FROM addon_inventory') + + for i = 1, #result, 1 do + local name = result[i].name + local _ = result[i].label + local shared = result[i].shared + + local result2 = MySQL.query.await('SELECT * FROM addon_inventory_items WHERE inventory_name = @inventory_name', { + ['@inventory_name'] = name + }) + + if shared == 0 then + table.insert(InventoriesIndex, name) + + Inventories[name] = {} + + for j = 1, #result2, 1 do + local itemName = result2[j].name + local itemCount = result2[j].count + local itemOwner = result2[j].owner + + if items[itemOwner] == nil then + items[itemOwner] = {} + end + + table.insert(items[itemOwner], { + name = itemName, + count = itemCount, + label = Items[itemName] + }) + end + + for k, v in pairs(items) do + local addonInventory = CreateAddonInventory(name, k, v) + table.insert(Inventories[name], addonInventory) + end + else + + for j = 1, #result2, 1 do + table.insert(items, { + name = result2[j].name, + count = result2[j].count, + label = Items[result2[j].name] + }) + end + + local addonInventory = CreateAddonInventory(name, nil, items) + SharedInventories[name] = addonInventory + GlobalState.SharedInventories = SharedInventories + end + end +end) + +function GetInventory(name, owner) + for i = 1, #Inventories[name], 1 do + if Inventories[name][i].owner == owner then + return Inventories[name][i] + end + end +end + +function GetSharedInventory(name) + return SharedInventories[name] +end + +function AddSharedInventory(society) + if type(society) ~= 'table' or not society?.name or not society?.label then return end + -- society (array) containing name (string) and label (string) + + -- addon inventory: + MySQL.Async.execute('INSERT INTO addon_inventory (name, label, shared) VALUES (@name, @label, @shared)', { + ['name'] = society.name, + ['label'] = society.label, + ['shared'] = 1 + }) + + SharedInventories[society.name] = CreateAddonInventory(society.name, nil, {}) +end + +AddEventHandler('bpt_addoninventory:getInventory', function(name, owner, cb) + cb(GetInventory(name, owner)) +end) + +AddEventHandler('bpt_addoninventory:getSharedInventory', function(name, cb) + cb(GetSharedInventory(name)) +end) + +AddEventHandler('esx:playerLoaded', function(playerId, xPlayer) + local addonInventories = {} + + for i = 1, #InventoriesIndex, 1 do + local name = InventoriesIndex[i] + local inventory = GetInventory(name, xPlayer.identifier) + + if inventory == nil then + inventory = CreateAddonInventory(name, xPlayer.identifier, {}) + table.insert(Inventories[name], inventory) + end + + table.insert(addonInventories, inventory) + end + + xPlayer.set('addonInventories', addonInventories) +end) diff --git a/server-data/resources/[bpt_addons]/bpt_ammujob/server/main.lua b/server-data/resources/[bpt_addons]/bpt_ammujob/server/main.lua index f8b99393b..2eb3d0ae8 100644 --- a/server-data/resources/[bpt_addons]/bpt_ammujob/server/main.lua +++ b/server-data/resources/[bpt_addons]/bpt_ammujob/server/main.lua @@ -33,7 +33,7 @@ AddEventHandler("bpt_ammujob:getStockItem", function(itemName, count) local xPlayer = ESX.GetPlayerFromId(source) if xPlayer.job.name == "ammu" then - TriggerEvent("esx_addoninventory:getSharedInventory", "society_ammu", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_ammu", function(inventory) local item = inventory.getItem(itemName) -- is there enough in the society? @@ -56,7 +56,7 @@ AddEventHandler("bpt_ammujob:getStockItem", function(itemName, count) end) ESX.RegisterServerCallback("bpt_ammujob:getStockItems", function(_, cb) - TriggerEvent("esx_addoninventory:getSharedInventory", "society_ammu", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_ammu", function(inventory) cb(inventory.items) end) end) @@ -67,7 +67,7 @@ AddEventHandler("bpt_ammujob:putStockItems", function(itemName, count) local sourceItem = xPlayer.getInventoryItem(itemName) if xPlayer.job.name == "ammu" then - TriggerEvent("esx_addoninventory:getSharedInventory", "society_ammu", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_ammu", function(inventory) local item = inventory.getItem(itemName) if sourceItem.count >= count and count > 0 then diff --git a/server-data/resources/[bpt_addons]/bpt_bakerjob/server/main.lua b/server-data/resources/[bpt_addons]/bpt_bakerjob/server/main.lua index 982787cf3..db40ab2df 100644 --- a/server-data/resources/[bpt_addons]/bpt_bakerjob/server/main.lua +++ b/server-data/resources/[bpt_addons]/bpt_bakerjob/server/main.lua @@ -33,7 +33,7 @@ AddEventHandler("bpt_bakerjob:getStockItem", function(itemName, count) local xPlayer = ESX.GetPlayerFromId(source) if xPlayer.job.name == "baker" then - TriggerEvent("esx_addoninventory:getSharedInventory", "society_baker", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_baker", function(inventory) local item = inventory.getItem(itemName) -- is there enough in the society? @@ -56,7 +56,7 @@ AddEventHandler("bpt_bakerjob:getStockItem", function(itemName, count) end) ESX.RegisterServerCallback("bpt_bakerjob:getStockItems", function(_, cb) - TriggerEvent("esx_addoninventory:getSharedInventory", "society_baker", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_baker", function(inventory) cb(inventory.items) end) end) @@ -67,7 +67,7 @@ AddEventHandler("bpt_bakerjob:putStockItems", function(itemName, count) local sourceItem = xPlayer.getInventoryItem(itemName) if xPlayer.job.name == "baker" then - TriggerEvent("esx_addoninventory:getSharedInventory", "society_baker", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_baker", function(inventory) local item = inventory.getItem(itemName) if sourceItem.count >= count and count > 0 then diff --git a/server-data/resources/[bpt_addons]/bpt_ballasjob/server/main.lua b/server-data/resources/[bpt_addons]/bpt_ballasjob/server/main.lua index 72de92a09..78895486e 100644 --- a/server-data/resources/[bpt_addons]/bpt_ballasjob/server/main.lua +++ b/server-data/resources/[bpt_addons]/bpt_ballasjob/server/main.lua @@ -16,7 +16,7 @@ AddEventHandler("bpt_ballasjob:getStockItem", function(itemName, count) local xPlayer = ESX.GetPlayerFromId(source) if xPlayer.job.name == "ballas" then - TriggerEvent("esx_addoninventory:getSharedInventory", "society_ballas", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_ballas", function(inventory) local item = inventory.getItem(itemName) -- is there enough in the society? @@ -39,7 +39,7 @@ AddEventHandler("bpt_ballasjob:getStockItem", function(itemName, count) end) ESX.RegisterServerCallback("bpt_ballasjob:getStockItems", function(_, cb) - TriggerEvent("esx_addoninventory:getSharedInventory", "society_ballas", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_ballas", function(inventory) cb(inventory.items) end) end) @@ -50,7 +50,7 @@ AddEventHandler("bpt_ballasjob:putStockItems", function(itemName, count) local sourceItem = xPlayer.getInventoryItem(itemName) if xPlayer.job.name == "ballas" then - TriggerEvent("esx_addoninventory:getSharedInventory", "society_ballas", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_ballas", function(inventory) local item = inventory.getItem(itemName) if sourceItem.count >= count and count > 0 then diff --git a/server-data/resources/[bpt_addons]/bpt_dustman/server/main.lua b/server-data/resources/[bpt_addons]/bpt_dustman/server/main.lua index bbca0ee74..b55c0a783 100644 --- a/server-data/resources/[bpt_addons]/bpt_dustman/server/main.lua +++ b/server-data/resources/[bpt_addons]/bpt_dustman/server/main.lua @@ -35,7 +35,7 @@ AddEventHandler("bpt_dustmanjob:getStockItem", function(itemName, count) local xPlayer = ESX.GetPlayerFromId(source) if xPlayer.job.name == "dustman" then - TriggerEvent("esx_addoninventory:getSharedInventory", "society_dustman", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_dustman", function(inventory) local item = inventory.getItem(itemName) -- is there enough in the society? @@ -58,7 +58,7 @@ AddEventHandler("bpt_dustmanjob:getStockItem", function(itemName, count) end) ESX.RegisterServerCallback("bpt_dustmanjob:getStockItems", function(_, cb) - TriggerEvent("esx_addoninventory:getSharedInventory", "society_dustman", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_dustman", function(inventory) cb(inventory.items) end) end) @@ -69,7 +69,7 @@ AddEventHandler("bpt_dustmanjob:putStockItems", function(itemName, count) local sourceItem = xPlayer.getInventoryItem(itemName) if xPlayer.job.name == "dustman" then - TriggerEvent("esx_addoninventory:getSharedInventory", "society_dustman", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_dustman", function(inventory) local item = inventory.getItem(itemName) if sourceItem.count >= count and count > 0 then diff --git a/server-data/resources/[bpt_addons]/bpt_fisherman/server/main.lua b/server-data/resources/[bpt_addons]/bpt_fisherman/server/main.lua index c0f625a6a..db70110af 100644 --- a/server-data/resources/[bpt_addons]/bpt_fisherman/server/main.lua +++ b/server-data/resources/[bpt_addons]/bpt_fisherman/server/main.lua @@ -41,7 +41,7 @@ AddEventHandler("bpt_fishermanjob:getStockItem", function(itemName, count) local xPlayer = ESX.GetPlayerFromId(source) if xPlayer.job.name == "fisherman" then - TriggerEvent("esx_addoninventory:getSharedInventory", "society_fisherman", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_fisherman", function(inventory) local item = inventory.getItem(itemName) -- is there enough in the society? @@ -64,7 +64,7 @@ AddEventHandler("bpt_fishermanjob:getStockItem", function(itemName, count) end) ESX.RegisterServerCallback("bpt_fishermanjob:getStockItems", function(_, cb) - TriggerEvent("esx_addoninventory:getSharedInventory", "society_fisherman", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_fisherman", function(inventory) cb(inventory.items) end) end) @@ -75,7 +75,7 @@ AddEventHandler("bpt_fishermanjob:putStockItems", function(itemName, count) local sourceItem = xPlayer.getInventoryItem(itemName) if xPlayer.job.name == "fisherman" then - TriggerEvent("esx_addoninventory:getSharedInventory", "society_fisherman", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_fisherman", function(inventory) local item = inventory.getItem(itemName) if sourceItem.count >= count and count > 0 then diff --git a/server-data/resources/[bpt_addons]/bpt_importjob/server/main.lua b/server-data/resources/[bpt_addons]/bpt_importjob/server/main.lua index e872bd9ba..414c7865b 100644 --- a/server-data/resources/[bpt_addons]/bpt_importjob/server/main.lua +++ b/server-data/resources/[bpt_addons]/bpt_importjob/server/main.lua @@ -33,7 +33,7 @@ AddEventHandler("bpt_importjob:getStockItem", function(itemName, count) local xPlayer = ESX.GetPlayerFromId(source) if xPlayer.job.name == "import" then - TriggerEvent("esx_addoninventory:getSharedInventory", "society_import", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_import", function(inventory) local item = inventory.getItem(itemName) -- is there enough in the society? @@ -56,7 +56,7 @@ AddEventHandler("bpt_importjob:getStockItem", function(itemName, count) end) ESX.RegisterServerCallback("bpt_importjob:getStockItems", function(_, cb) - TriggerEvent("esx_addoninventory:getSharedInventory", "society_import", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_import", function(inventory) cb(inventory.items) end) end) @@ -67,7 +67,7 @@ AddEventHandler("bpt_importjob:putStockItems", function(itemName, count) local sourceItem = xPlayer.getInventoryItem(itemName) if xPlayer.job.name == "import" then - TriggerEvent("esx_addoninventory:getSharedInventory", "society_import", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_import", function(inventory) local item = inventory.getItem(itemName) if sourceItem.count >= count and count > 0 then diff --git a/server-data/resources/[bpt_addons]/bpt_unicornjob/server/main.lua b/server-data/resources/[bpt_addons]/bpt_unicornjob/server/main.lua index 87ecb9d3f..f2fc3595f 100644 --- a/server-data/resources/[bpt_addons]/bpt_unicornjob/server/main.lua +++ b/server-data/resources/[bpt_addons]/bpt_unicornjob/server/main.lua @@ -35,7 +35,7 @@ AddEventHandler("bpt_unicornjob:getStockItem", function(itemName, count) local xPlayer = ESX.GetPlayerFromId(source) if xPlayer.job.name == "unicorn" then - TriggerEvent("esx_addoninventory:getSharedInventory", "society_unicorn", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_unicorn", function(inventory) local item = inventory.getItem(itemName) -- is there enough in the society? @@ -58,7 +58,7 @@ AddEventHandler("bpt_unicornjob:getStockItem", function(itemName, count) end) ESX.RegisterServerCallback("bpt_unicornjob:getStockItems", function(_, cb) - TriggerEvent("esx_addoninventory:getSharedInventory", "society_unicorn", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_unicorn", function(inventory) cb(inventory.items) end) end) @@ -69,7 +69,7 @@ AddEventHandler("bpt_unicornjob:putStockItems", function(itemName, count) local sourceItem = xPlayer.getInventoryItem(itemName) if xPlayer.job.name == "unicorn" then - TriggerEvent("esx_addoninventory:getSharedInventory", "society_unicorn", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_unicorn", function(inventory) local item = inventory.getItem(itemName) if sourceItem.count >= count and count > 0 then diff --git a/server-data/resources/[esx_addons]/esx_addoninventory/README.md b/server-data/resources/[esx_addons]/esx_addoninventory/README.md deleted file mode 100644 index ecf72bc5d..000000000 --- a/server-data/resources/[esx_addons]/esx_addoninventory/README.md +++ /dev/null @@ -1,61 +0,0 @@ -# esx_addoninventory - -## Download & Installation - -### Using [fvm](https://github.com/qlaffont/fvm-installer) -``` -fvm install --save --folder=esx esx-org/esx_addoninventory -``` - -### Using Git -``` -cd resources -git clone https://github.com/ESX-Org/esx_addoninventory [esx]/esx_addoninventory -``` - -### Manually -- Download https://github.com/ESX-Org/esx_addoninventory/archive/master.zip -- Put it in the `[esx]` directory - -## Installation -- Import `esx_addoninventory.sql` in your database -- Add this in your `server.cfg`: - -``` -start esx_addoninventory -``` - -## Usage -There are two types of inventories: shared and not shared. - -- Shared inventories don't belong to a specific user. Example: foodstore items. -- None-shared inventories are created for every user in the server. They are created in db when player is loaded, Example: property items - -### `addon_inventory` database information -An addon inventory must be configured in the database before using it. Don't forget to run a server restart afterwards (you can alternative restart the script and relog all clients) - -| `name` | `label` | `shared` | -| -------- | ------- | -------- | -| name of the inventory | label of the inventory (not used) | is the inventory shared with others? (boolean either `0` or `1`) | - -```lua -TriggerEvent('esx_addoninventory:getSharedInventory', 'society_police', function(inventory) - inventory.addItem('bread', 1) -end) - -TriggerEvent('esx_addoninventory:getInventory', 'property', 'steam:0123456789', function(inventory) - inventory.removeItem('water', 1) -end) - -``` -# Legal -### License -esx_addoninventory - inventories! - -Copyright (C) 2015-2022 Jérémie N'gadi - -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. - -You should have received a copy Of the GNU General Public License along with this program. If Not, see http://www.gnu.org/licenses/. \ No newline at end of file diff --git a/server-data/resources/[esx_addons]/esx_addoninventory/fxmanifest.lua b/server-data/resources/[esx_addons]/esx_addoninventory/fxmanifest.lua deleted file mode 100644 index ea28cdecb..000000000 --- a/server-data/resources/[esx_addons]/esx_addoninventory/fxmanifest.lua +++ /dev/null @@ -1,22 +0,0 @@ -fx_version("adamant") - -game("gta5") - -description("ESX Addon Inventory") -lua54("yes") - -version("1.0.1") - -server_scripts({ - "@es_extended/imports.lua", - "@oxmysql/lib/MySQL.lua", - "server/classes/addoninventory.lua", - "server/main.lua", -}) - -server_exports({ - "GetSharedInventory", - "AddSharedInventory", -}) - -dependency("es_extended") diff --git a/server-data/resources/[esx_addons]/esx_addoninventory/server/classes/addoninventory.lua b/server-data/resources/[esx_addons]/esx_addoninventory/server/classes/addoninventory.lua deleted file mode 100644 index a024c2e0e..000000000 --- a/server-data/resources/[esx_addons]/esx_addoninventory/server/classes/addoninventory.lua +++ /dev/null @@ -1,82 +0,0 @@ -function CreateAddonInventory(name, owner, items) - local self = {} - - self.name = name - self.owner = owner - self.items = items - - function self.addItem(name, count) - local item = self.getItem(name) - item.count = item.count + count - - self.saveItem(name, item.count) - end - - function self.removeItem(name, count) - if count > 0 then - local item = self.getItem(name) - item.count = item.count - count - - self.saveItem(name, item.count) - end - end - - function self.setItem(name, count) - local item = self.getItem(name) - item.count = count - - self.saveItem(name, item.count) - end - - function self.getItem(name) - for i = 1, #self.items, 1 do - if self.items[i].name == name then - return self.items[i] - end - end - - item = { - name = name, - count = 0, - label = Items[name], - } - - table.insert(self.items, item) - - if self.owner == nil then - MySQL.update("INSERT INTO addon_inventory_items (inventory_name, name, count) VALUES (@inventory_name, @item_name, @count)", { - ["@inventory_name"] = self.name, - ["@item_name"] = name, - ["@count"] = 0, - }) - else - MySQL.update("INSERT INTO addon_inventory_items (inventory_name, name, count, owner) VALUES (@inventory_name, @item_name, @count, @owner)", { - ["@inventory_name"] = self.name, - ["@item_name"] = name, - ["@count"] = 0, - ["@owner"] = self.owner, - }) - end - - return item - end - - function self.saveItem(name, count) - if self.owner == nil then - MySQL.update("UPDATE addon_inventory_items SET count = @count WHERE inventory_name = @inventory_name AND name = @item_name", { - ["@inventory_name"] = self.name, - ["@item_name"] = name, - ["@count"] = count, - }) - else - MySQL.update("UPDATE addon_inventory_items SET count = @count WHERE inventory_name = @inventory_name AND name = @item_name AND owner = @owner", { - ["@inventory_name"] = self.name, - ["@item_name"] = name, - ["@count"] = count, - ["@owner"] = self.owner, - }) - end - end - - return self -end diff --git a/server-data/resources/[esx_addons]/esx_addoninventory/server/main.lua b/server-data/resources/[esx_addons]/esx_addoninventory/server/main.lua deleted file mode 100644 index 73584827b..000000000 --- a/server-data/resources/[esx_addons]/esx_addoninventory/server/main.lua +++ /dev/null @@ -1,134 +0,0 @@ -if ESX.GetConfig().OxInventory then - AddEventHandler('onServerResourceStart', function(resourceName) - if resourceName == 'ox_inventory' or resourceName == GetCurrentResourceName() then - local stashes = MySQL.query.await('SELECT * FROM addon_inventory') - - for i=1, #stashes do - local stash = stashes[i] - local jobStash = stash.name:find('society') and string.sub(stash.name, 9) - exports.ox_inventory:RegisterStash(stash.name, stash.label, 100, 200000, stash.shared == 0 and true or false, jobStash) - end - end - end) - - return -end - -Items = {} -local InventoriesIndex, Inventories, SharedInventories = {}, {}, {} - -MySQL.ready(function() - local items = MySQL.query.await('SELECT * FROM items') - - for i=1, #items, 1 do - Items[items[i].name] = items[i].label - end - - local result = MySQL.query.await('SELECT * FROM addon_inventory') - - for i=1, #result, 1 do - local name = result[i].name - local label = result[i].label - local shared = result[i].shared - - local result2 = MySQL.query.await('SELECT * FROM addon_inventory_items WHERE inventory_name = @inventory_name', { - ['@inventory_name'] = name - }) - - if shared == 0 then - - table.insert(InventoriesIndex, name) - - Inventories[name] = {} - local items = {} - - for j=1, #result2, 1 do - local itemName = result2[j].name - local itemCount = result2[j].count - local itemOwner = result2[j].owner - - if items[itemOwner] == nil then - items[itemOwner] = {} - end - - table.insert(items[itemOwner], { - name = itemName, - count = itemCount, - label = Items[itemName] - }) - end - - for k,v in pairs(items) do - local addonInventory = CreateAddonInventory(name, k, v) - table.insert(Inventories[name], addonInventory) - end - - else - local items = {} - - for j=1, #result2, 1 do - table.insert(items, { - name = result2[j].name, - count = result2[j].count, - label = Items[result2[j].name] - }) - end - - local addonInventory = CreateAddonInventory(name, nil, items) - SharedInventories[name] = addonInventory - GlobalState.SharedInventories = SharedInventories - end - end -end) - -function GetInventory(name, owner) - for i=1, #Inventories[name], 1 do - if Inventories[name][i].owner == owner then - return Inventories[name][i] - end - end -end - -function GetSharedInventory(name) - return SharedInventories[name] -end - -function AddSharedInventory(society) - if type(society) ~= 'table' or not society?.name or not society?.label then - return - end - -- society (array) containing name (string) and label (string) - -- addon inventory: - MySQL.Async.execute('INSERT INTO addon_inventory (name, label, shared) VALUES (@name, @label, @shared)', { - ['name'] = society.name, - ['label'] = society.label, - ['shared'] = 1 - }) - SharedInventories[society.name] = CreateAddonInventory(society.name, nil, {}) -end - -AddEventHandler('esx_addoninventory:getInventory', function(name, owner, cb) - cb(GetInventory(name, owner)) -end) - -AddEventHandler('esx_addoninventory:getSharedInventory', function(name, cb) - cb(GetSharedInventory(name)) -end) - -AddEventHandler('esx:playerLoaded', function(_, xPlayer) - local addonInventories = {} - - for i=1, #InventoriesIndex, 1 do - local name = InventoriesIndex[i] - local inventory = GetInventory(name, xPlayer.identifier) - - if inventory == nil then - inventory = CreateAddonInventory(name, xPlayer.identifier, {}) - table.insert(Inventories[name], inventory) - end - - table.insert(addonInventories, inventory) - end - - xPlayer.set('addonInventories', addonInventories) -end) \ No newline at end of file diff --git a/server-data/resources/[esx_addons]/esx_mechanicjob/server/main.lua b/server-data/resources/[esx_addons]/esx_mechanicjob/server/main.lua index ef5f513b2..52e273c7c 100644 --- a/server-data/resources/[esx_addons]/esx_mechanicjob/server/main.lua +++ b/server-data/resources/[esx_addons]/esx_mechanicjob/server/main.lua @@ -245,7 +245,7 @@ RegisterServerEvent("esx_mechanicjob:getStockItem") AddEventHandler("esx_mechanicjob:getStockItem", function(itemName, count) local xPlayer = ESX.GetPlayerFromId(source) - TriggerEvent("esx_addoninventory:getSharedInventory", "society_mechanic", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_mechanic", function(inventory) local item = inventory.getItem(itemName) -- is there enough in the society? @@ -265,7 +265,7 @@ AddEventHandler("esx_mechanicjob:getStockItem", function(itemName, count) end) ESX.RegisterServerCallback("esx_mechanicjob:getStockItems", function(source, cb) - TriggerEvent("esx_addoninventory:getSharedInventory", "society_mechanic", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_mechanic", function(inventory) cb(inventory.items) end) end) @@ -274,7 +274,7 @@ RegisterServerEvent("esx_mechanicjob:putStockItems") AddEventHandler("esx_mechanicjob:putStockItems", function(itemName, count) local xPlayer = ESX.GetPlayerFromId(source) - TriggerEvent("esx_addoninventory:getSharedInventory", "society_mechanic", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_mechanic", function(inventory) local item = inventory.getItem(itemName) local playerItemCount = xPlayer.getInventoryItem(itemName).count diff --git a/server-data/resources/[esx_addons]/esx_policejob/README.md b/server-data/resources/[esx_addons]/esx_policejob/README.md index 7c085b60b..21a7a79bd 100644 --- a/server-data/resources/[esx_addons]/esx_policejob/README.md +++ b/server-data/resources/[esx_addons]/esx_policejob/README.md @@ -8,7 +8,6 @@ This resource for ESX adds police armories, vehicle garages and ability for cops * [esx_vehicleshop](https://github.com/esx-framework/esx_vehicleshop) * Player management (boss actions and armory with buyable weapons) - * [esx_addoninventory](https://github.com/esx-framework/esx_addoninventory) * [esx_datastore](https://github.com/esx-framework/esx_datastore) * [esx_society](https://github.com/esx-framework/esx_society) diff --git a/server-data/resources/[esx_addons]/esx_policejob/server/main.lua b/server-data/resources/[esx_addons]/esx_policejob/server/main.lua index 08b4593ce..c3316be83 100644 --- a/server-data/resources/[esx_addons]/esx_policejob/server/main.lua +++ b/server-data/resources/[esx_addons]/esx_policejob/server/main.lua @@ -138,7 +138,7 @@ AddEventHandler("esx_policejob:getStockItem", function(itemName, count) local source = source local xPlayer = ESX.GetPlayerFromId(source) - TriggerEvent("esx_addoninventory:getSharedInventory", "society_police", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_police", function(inventory) local inventoryItem = inventory.getItem(itemName) -- is there enough in the society? @@ -162,7 +162,7 @@ AddEventHandler("esx_policejob:putStockItems", function(itemName, count) local xPlayer = ESX.GetPlayerFromId(source) local sourceItem = xPlayer.getInventoryItem(itemName) - TriggerEvent("esx_addoninventory:getSharedInventory", "society_police", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_police", function(inventory) local inventoryItem = inventory.getItem(itemName) -- does the player have enough of the item? @@ -457,7 +457,7 @@ function getPriceFromHash(vehicleHash, jobGrade, type) end ESX.RegisterServerCallback("esx_policejob:getStockItems", function(source, cb) - TriggerEvent("esx_addoninventory:getSharedInventory", "society_police", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_police", function(inventory) cb(inventory.items) end) end) diff --git a/server-data/resources/[esx_addons]/esx_vehicleshop/README.md b/server-data/resources/[esx_addons]/esx_vehicleshop/README.md index 18bf34ee9..121be8cf8 100644 --- a/server-data/resources/[esx_addons]/esx_vehicleshop/README.md +++ b/server-data/resources/[esx_addons]/esx_vehicleshop/README.md @@ -10,7 +10,6 @@ ESX Vehicle Shop adds an vehicle shop to the game, where employeed players can s * Player management (the car dealer job): billing, boss actions and more! * [esx_society] * [esx_billing] - * [esx_addoninventory] * [cron] ### Installation diff --git a/server-data/resources/[esx_addons]/esx_vehicleshop/server/main.lua b/server-data/resources/[esx_addons]/esx_vehicleshop/server/main.lua index fdfebb06b..839b709b0 100644 --- a/server-data/resources/[esx_addons]/esx_vehicleshop/server/main.lua +++ b/server-data/resources/[esx_addons]/esx_vehicleshop/server/main.lua @@ -187,7 +187,7 @@ AddEventHandler("esx_vehicleshop:getStockItem", function(itemName, count) local source = source local xPlayer = ESX.GetPlayerFromId(source) - TriggerEvent("esx_addoninventory:getSharedInventory", "society_cardealer", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_cardealer", function(inventory) local item = inventory.getItem(itemName) if count > 0 and item.count >= count then @@ -208,7 +208,7 @@ AddEventHandler("esx_vehicleshop:putStockItems", function(itemName, count) local source = source local xPlayer = ESX.GetPlayerFromId(source) - TriggerEvent("esx_addoninventory:getSharedInventory", "society_cardealer", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_cardealer", function(inventory) local item = inventory.getItem(itemName) if item.count < 0 then @@ -423,7 +423,7 @@ ESX.RegisterServerCallback("esx_vehicleshop:resellVehicle", function(source, cb, end) ESX.RegisterServerCallback("esx_vehicleshop:getStockItems", function(source, cb) - TriggerEvent("esx_addoninventory:getSharedInventory", "society_cardealer", function(inventory) + TriggerEvent("bpt_addoninventory:getSharedInventory", "society_cardealer", function(inventory) cb(inventory.items) end) end)