Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: check for nil society #562

Merged
merged 2 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading