mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 01:08:54 +00:00
Merge pull request #960 from wasabirobby/main
feat(es_extended/server/functions.lua): ESX.CreateJob(tb)
This commit is contained in:
@@ -321,6 +321,37 @@ function ESX.DiscordLogFields(name, title, color, fields)
|
||||
})
|
||||
end
|
||||
|
||||
--- Create Job at Runtime
|
||||
--- @param name string
|
||||
--- @param label string
|
||||
--- @param grades table
|
||||
function ESX.CreateJob(name, label, grades)
|
||||
if not name then
|
||||
return print('[^3WARNING^7] missing argument `name(string)` while creating a job')
|
||||
end
|
||||
|
||||
if not label then
|
||||
return print('[^3WARNING^7] missing argument `label(string)` while creating a job')
|
||||
end
|
||||
|
||||
if not grades or not next(grades) then
|
||||
return print('[^3WARNING^7] missing argument `grades(table)` while creating a job!')
|
||||
end
|
||||
|
||||
local parameters = {}
|
||||
local job = {name = name, label = label, grades = {}}
|
||||
|
||||
for k,v in pairs(grades) do
|
||||
job.grades[tostring(v.grade)] = {job_name = name, grade = v.grade, name = v.name, label = v.label, salary = v.salary, skin_male = {}, skin_female = {}}
|
||||
parameters[#parameters + 1] = { name, v.grade, v.name, v.label, v.salary}
|
||||
end
|
||||
|
||||
MySQL.insert('INSERT IGNORE INTO jobs (name, label) VALUES (?, ?)', {name, label})
|
||||
MySQL.prepare('INSERT INTO job_grades (job_name, grade, name, label, salary) VALUES (?, ?, ?, ?, ?)', parameters)
|
||||
|
||||
ESX.Jobs[name] = job
|
||||
end
|
||||
|
||||
function ESX.RefreshJobs()
|
||||
local Jobs = {}
|
||||
local jobs = MySQL.query.await('SELECT * FROM jobs')
|
||||
|
||||
Reference in New Issue
Block a user