Minor server sided code improvement, fixed #14

This commit is contained in:
ElPumpo
2020-01-04 12:56:46 +01:00
parent a1575ee3fc
commit 00b5a75d4f
2 changed files with 19 additions and 20 deletions
+2 -1
View File
@@ -1,4 +1,5 @@
# esx_joblisting
Simple job listing script, you can specify what jobs you want to be whitelisted in db.
## Download & Installation
@@ -30,7 +31,7 @@ start esx_joblisting
### License
esx_joblisting - job listing script
Copyright (C) 2015-2018 Jérémie N'gadi
Copyright (C) 2015-2020 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.
+17 -19
View File
@@ -1,37 +1,35 @@
ESX = nil
local availableJobs = {}
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
ESX.RegisterServerCallback('esx_joblisting:getJobsList', function(source, cb)
MySQL.ready(function()
MySQL.Async.fetchAll('SELECT * FROM jobs WHERE whitelisted = @whitelisted', {
['@whitelisted'] = false
}, function(result)
local data = {}
for i=1, #result, 1 do
table.insert(data, {
job = result[i].name,
table.insert(availableJobs, {
job = result[i].name,
label = result[i].label
})
end
cb(data)
end)
end)
ESX.RegisterServerCallback('esx_joblisting:getJobsList', function(source, cb)
cb(availableJobs)
end)
RegisterServerEvent('esx_joblisting:setJob')
AddEventHandler('esx_joblisting:setJob', function(job)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local xPlayer = ESX.GetPlayerFromId(source)
MySQL.Async.fetchAll('SELECT whitelisted FROM jobs WHERE name = @name', {
['@name'] = job,
}, function(result)
if not result[1].whitelisted then
xPlayer.setJob(job, 0)
else
print(('esx_joblisting: %s attempted to set a whitelisted job! (lua injector)'):format(xPlayer.identifier))
if xPlayer then
for k,v in ipairs(availableJobs) do
if v.job == job then
xPlayer.setJob(job, 0)
break
end
end
end)
end
end)