mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-08-29 01:08:57 +00:00
hotfix (exports): Updated the way functions return, now returns status, message and item (if applicable).
This commit is contained in:
+43
-58
@@ -1,25 +1,17 @@
|
||||
-- Single add job function which should only be used if you planning on adding a single job
|
||||
local function AddJob(jobName, job, source)
|
||||
local function AddJob(jobName, job)
|
||||
if type(jobName) ~= "string" then
|
||||
print('Failed to add the item, name is not a string')
|
||||
if source ~= nil and source ~= '' then
|
||||
TriggerClientEvent('QBCore:Notify', source, 'Failed to add the job, name is not a string', 'error', 3000)
|
||||
end
|
||||
return false
|
||||
return false, "invalid_job_name"
|
||||
end
|
||||
|
||||
if QBCore.Shared.Jobs[jobName] ~= nil then
|
||||
print('Failed to add the item, item already exists')
|
||||
if source ~= nil and source ~= '' then
|
||||
TriggerClientEvent('QBCore:Notify', source, 'Failed to add the job, job already exists', 'error', 3000)
|
||||
end
|
||||
return false
|
||||
return false, "job_exists"
|
||||
end
|
||||
|
||||
QBCore.Shared.Jobs[jobName] = job
|
||||
TriggerClientEvent('QBCore:Client:OnSharedUpdate', -1,'Jobs', jobName, job)
|
||||
TriggerEvent('QBCore:Server:UpdateObject')
|
||||
return true
|
||||
return true, "success"
|
||||
end
|
||||
QBCore.Functions.AddJob = AddJob
|
||||
exports('AddJob', AddJob)
|
||||
@@ -27,52 +19,47 @@ exports('AddJob', AddJob)
|
||||
-- Multiple Add Jobs
|
||||
local function AddJobs(jobs)
|
||||
local shouldContinue = true
|
||||
local message = "success"
|
||||
local errorItem = nil
|
||||
for key, value in pairs(jobs) do
|
||||
if type(key) ~= "string" then
|
||||
print('Failed to add the job, name is not a string')
|
||||
message = 'invalid_job_name'
|
||||
shouldContinue = false
|
||||
goto continue
|
||||
errorItem = jobs[key]
|
||||
break
|
||||
end
|
||||
|
||||
if QBCore.Shared.Jobs[key] ~= nil then
|
||||
print('Failed to add the job, job already exists: ' .. key)
|
||||
message = 'job_exists'
|
||||
shouldContinue = false
|
||||
goto continue
|
||||
errorItem = jobs[key]
|
||||
break
|
||||
end
|
||||
|
||||
QBCore.Shared.Jobs[key] = value
|
||||
::continue::
|
||||
end
|
||||
|
||||
if not shouldContinue then return false end
|
||||
if not shouldContinue then return false, message, errorItem end
|
||||
TriggerClientEvent('QBCore:Client:OnSharedUpdateMultiple', -1, 'Jobs', jobs)
|
||||
TriggerEvent('QBCore:Server:UpdateObject')
|
||||
return true
|
||||
return true, message, nil
|
||||
end
|
||||
QBCore.Functions.AddJobs = AddJobs
|
||||
exports('AddJobs', AddJobs)
|
||||
|
||||
-- Single add item
|
||||
local function AddItem(itemName, item, source)
|
||||
local function AddItem(itemName, item)
|
||||
if type(itemName) ~= "string" then
|
||||
print('Failed to add the item, name is not a string')
|
||||
if source ~= nil and source ~= '' then
|
||||
TriggerClientEvent('QBCore:Notify', source, 'Failed to add the item, name is not a string', 'error', 3000)
|
||||
end
|
||||
return false
|
||||
return false, "invalid_item_name"
|
||||
end
|
||||
if QBCore.Shared.Items[itemName] ~= nil then
|
||||
print('Failed to add the item, item already exists')
|
||||
if source ~= nil and source ~= '' then
|
||||
TriggerClientEvent('QBCore:Notify', source, 'Failed to add the item, item already exists', 'error', 3000)
|
||||
end
|
||||
return false
|
||||
return false, "item_exists"
|
||||
end
|
||||
|
||||
QBCore.Shared.Items[itemName] = item
|
||||
TriggerClientEvent('QBCore:Client:OnSharedUpdate', -1, 'Items', itemName, item)
|
||||
TriggerEvent('QBCore:Server:UpdateObject')
|
||||
return true
|
||||
return true, "success"
|
||||
end
|
||||
QBCore.Functions.AddItem = AddItem
|
||||
exports('AddItem', AddItem)
|
||||
@@ -80,26 +67,30 @@ exports('AddItem', AddItem)
|
||||
-- Multiple Add Items
|
||||
local function AddItems(items)
|
||||
local shouldContinue = true
|
||||
local message = "success"
|
||||
local errorItem = nil
|
||||
for key, value in pairs(items) do
|
||||
if type(key) ~= "string" then
|
||||
print('Failed to add the item, name is not a string')
|
||||
message = "invalid_item_name"
|
||||
shouldContinue = false
|
||||
goto continue
|
||||
errorItem = items[key]
|
||||
break
|
||||
end
|
||||
|
||||
if QBCore.Shared.Items[key] ~= nil then
|
||||
print('Failed to add the item, item already exists: ' .. key)
|
||||
message = "item_exists"
|
||||
shouldContinue = false
|
||||
goto continue
|
||||
errorItem = items[key]
|
||||
break
|
||||
end
|
||||
|
||||
QBCore.Shared.Items[key] = value
|
||||
::continue::
|
||||
end
|
||||
if not shouldContinue then return false end
|
||||
|
||||
if not shouldContinue then return false, message, errorItem end
|
||||
TriggerClientEvent('QBCore:Client:OnSharedUpdateMultiple', -1, 'Items', items)
|
||||
TriggerEvent('QBCore:Server:UpdateObject')
|
||||
return true
|
||||
return true, message, nil
|
||||
end
|
||||
QBCore.Functions.AddItems = AddItems
|
||||
exports('AddItems', AddItems)
|
||||
@@ -107,24 +98,16 @@ exports('AddItems', AddItems)
|
||||
-- Single Add Gang
|
||||
local function AddGang(gangName, gang, source)
|
||||
if type(gangName) ~= "string" then
|
||||
print('Failed to add the gang, name is not a string')
|
||||
if source ~= nil and source ~= '' then
|
||||
TriggerClientEvent('QBCore:Notify', source, 'Failed to add the gang, name is not a string', 'error', 3000)
|
||||
end
|
||||
return false
|
||||
return false, "invalid_gang_name"
|
||||
end
|
||||
if QBCore.Shared.Gangs[gangName] ~= nil then
|
||||
print('Failed to add the gang, gang already exists')
|
||||
if source ~= nil and source ~= '' then
|
||||
TriggerClientEvent('QBCore:Notify', source, 'Failed to add the gang, gang already exists', 'error', 3000)
|
||||
end
|
||||
return false
|
||||
return false, "gang_exists"
|
||||
end
|
||||
|
||||
QBCore.Shared.Gangs[gangName] = gang
|
||||
TriggerClientEvent('QBCore:Client:OnSharedUpdate', -1,'Gangs', gangName, gang)
|
||||
TriggerEvent('QBCore:Server:UpdateObject')
|
||||
return true
|
||||
return true, "success"
|
||||
end
|
||||
QBCore.Functions.AddGang = AddGang
|
||||
exports('AddGang', AddGang)
|
||||
@@ -132,28 +115,30 @@ exports('AddGang', AddGang)
|
||||
-- Multiple Add Gangs
|
||||
local function AddGangs(gangs)
|
||||
local shouldContinue = true
|
||||
|
||||
local message = "success"
|
||||
local errorItem = nil
|
||||
|
||||
for key, value in pairs(gangs) do
|
||||
if type(key) ~= "string" then
|
||||
print('Failed to add the gang, name is not a string')
|
||||
message = "invalid_gang_name"
|
||||
shouldContinue = false
|
||||
goto continue
|
||||
errorItem = items[key]
|
||||
break
|
||||
end
|
||||
|
||||
if QBCore.Shared.Gangs[key] ~= nil then
|
||||
print('Failed to add the gang, gang already exists: ' .. key)
|
||||
message = "gang_exists"
|
||||
shouldContinue = false
|
||||
goto continue
|
||||
errorItem = items[key]
|
||||
break
|
||||
end
|
||||
|
||||
QBCore.Shared.Gangs[key] = value
|
||||
::continue::
|
||||
end
|
||||
|
||||
if not shouldContinue then return false end
|
||||
if not shouldContinue then return false, message, errorItem end
|
||||
TriggerClientEvent('QBCore:Client:OnSharedUpdateMultiple', -1, 'Gangs', gangs)
|
||||
TriggerEvent('QBCore:Server:UpdateObject')
|
||||
return true
|
||||
return true, message, nil
|
||||
end
|
||||
QBCore.Functions.AddGangs = AddGangs
|
||||
exports('AddGangs', AddGangs)
|
||||
Reference in New Issue
Block a user