mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-02 19:28:52 +00:00
Minor server sided code improvement, fixed #14
This commit is contained in:
@@ -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
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user