Skip to content

Commit

Permalink
Merge pull request #562 from bitpredator/dev
Browse files Browse the repository at this point in the history
chore: check for nil society
  • Loading branch information
bitpredator authored Nov 18, 2023
2 parents f59f81a + 9fc6ee8 commit 39396a0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
26. [esx_status/server]: fix: unused argument @bitpredator
27. [esx_addoninventory]: chore: check for nil society @bitpredator
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -13,4 +14,9 @@ server_scripts {
'server/main.lua'
}

dependency 'es_extended'
server_exports {
'GetSharedInventory',
'AddSharedInventory'
}

dependency 'es_extended'
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -79,5 +81,4 @@ function CreateAddonInventory(name, owner, items)
end

return self
end

end
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ MySQL.ready(function()

local addonInventory = CreateAddonInventory(name, nil, items)
SharedInventories[name] = addonInventory
GlobalState.SharedInventories = SharedInventories
end
end
end)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -116,4 +131,4 @@ AddEventHandler('esx:playerLoaded', function(playerId, xPlayer)
end

xPlayer.set('addonInventories', addonInventories)
end)
end)

0 comments on commit 39396a0

Please sign in to comment.