diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index b8b5f8018..b5614c744 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -48,4 +48,5 @@ 23. [bpt_teleport]: chore: clean up the code @bitpredator 24. [mythic_notify]: fix: removed unused variables @bitpredator 25. [esx_status]: refactor: remove jquery + Remove some shitty lines @bitpredator -26. [esx_status/server]: fix: unused argument @bitpredator \ No newline at end of file +26. [esx_status/server]: fix: unused argument @bitpredator +27. [esx_addoninventory]: chore: check for nil society @bitpredator \ 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 index 9e57f1928..ecc53f034 100644 --- a/server-data/resources/[esx_addons]/esx_addoninventory/fxmanifest.lua +++ b/server-data/resources/[esx_addons]/esx_addoninventory/fxmanifest.lua @@ -3,8 +3,9 @@ fx_version 'adamant' game 'gta5' description 'ESX Addon Inventory' +lua54 'yes' -version '1.7.5' +version '1.0.0' server_scripts { '@es_extended/imports.lua', @@ -13,4 +14,9 @@ server_scripts { 'server/main.lua' } -dependency 'es_extended' +server_exports { + 'GetSharedInventory', + 'AddSharedInventory' +} + +dependency 'es_extended' \ No newline at end of file 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 index d5148f405..0b9fbb52e 100644 --- a/server-data/resources/[esx_addons]/esx_addoninventory/server/classes/addoninventory.lua +++ b/server-data/resources/[esx_addons]/esx_addoninventory/server/classes/addoninventory.lua @@ -8,15 +8,17 @@ function CreateAddonInventory(name, owner, items) function self.addItem(name, count) local item = self.getItem(name) item.count = item.count + count - Wait(100) + self.saveItem(name, item.count) end function self.removeItem(name, count) - local item = self.getItem(name) - item.count = item.count - count + if count > 0 then + local item = self.getItem(name) + item.count = item.count - count - self.saveItem(name, item.count) + self.saveItem(name, item.count) + end end function self.setItem(name, count) @@ -79,5 +81,4 @@ function CreateAddonInventory(name, owner, items) end return self -end - +end \ No newline at end of file diff --git a/server-data/resources/[esx_addons]/esx_addoninventory/server/main.lua b/server-data/resources/[esx_addons]/esx_addoninventory/server/main.lua index 3ed154f0d..73584827b 100644 --- a/server-data/resources/[esx_addons]/esx_addoninventory/server/main.lua +++ b/server-data/resources/[esx_addons]/esx_addoninventory/server/main.lua @@ -76,6 +76,7 @@ MySQL.ready(function() local addonInventory = CreateAddonInventory(name, nil, items) SharedInventories[name] = addonInventory + GlobalState.SharedInventories = SharedInventories end end end) @@ -92,6 +93,20 @@ 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) @@ -100,7 +115,7 @@ AddEventHandler('esx_addoninventory:getSharedInventory', function(name, cb) cb(GetSharedInventory(name)) end) -AddEventHandler('esx:playerLoaded', function(playerId, xPlayer) +AddEventHandler('esx:playerLoaded', function(_, xPlayer) local addonInventories = {} for i=1, #InventoriesIndex, 1 do @@ -116,4 +131,4 @@ AddEventHandler('esx:playerLoaded', function(playerId, xPlayer) end xPlayer.set('addonInventories', addonInventories) -end) +end) \ No newline at end of file