Here is an example of code that can be used to create pls_jobsystem (link) directly in the job database.
Valid for ESX only
1) Go to server.lua - Find event pls_jobsystem:server:saveNewJob
Insert the code registerJobInDatabase(jobData) under the SaveJobs() function
ifnotIsJobExist(jobData.job) thentable.insert(Jobs, jobData) lib.notify(src, { title="Hell yeah!", description="A new job has been created!", type="success" })SaveJobs()registerJobInDatabase(jobData)else
Then, at the end of server.lua, insert the new function we will create.
functionregisterJobInDatabase(data)end
What does the data value contain?
data.label = Job label - STRINGdata.coords = Player coords - VECTOR3data.job = job name - STRINGdata.area =Area ( size) -INT(NUMBER)
Function registerJobInDatabase(data)
functionregisterJobInDatabase(data) MySQL.query('SELECT * FROM jobs WHERE name = ?', { data.job }, function(result)if#result ==0then-- If job not exist MySQL.insert('INSERT INTO jobs (name, label, whitelisted) VALUES (?, ?, ?)', { data.job, data.label, 0 }, function(insertId)if insertId thenprint("Job successfully inserted with ID: " .. insertId)-- Define gradeslocal grades = { {job_name = data.job, grade =0, name ='newbie', label ='Newbie', salary =200, skin_male ='{}', skin_female ='{}'}, {job_name = data.job, grade =1, name ='employe', label ='Employe', salary =400, skin_male ='{}', skin_female ='{}'}, {job_name = data.job, grade =2, name ='manage', label ='Manage', salary =500, skin_male ='{}', skin_female ='{}'}, {job_name = data.job, grade =3, name ='boss', label ='Boss', salary =1000, skin_male ='{}', skin_female ='{}'} }-- Insert gradesfor _, grade inipairs(grades) do MySQL.insert('INSERT INTO job_grades (job_name, grade, name, label, salary, skin_male, skin_female) VALUES (?, ?, ?, ?, ?, ?, ?)', { grade.job_name, grade.grade, grade.name, grade.label, grade.salary, grade.skin_male, grade.skin_female }, function(gradeInsertId)if gradeInsertId thenprint("Grade successfully inserted with ID: " .. gradeInsertId)elseprint("Failed to insert grade: " .. grade.name)endend)endelseprint("Failed to insert job")endend)elseprint("Job already exists")endend)end
Don't forget to add to fxmanifest.lua
server_scripts {
"@oxmysql/lib/MySQL.lua", -- This line on start
}
IMPORTANT
This code assumes that you are using oxmysql https://github.com/overextended/oxmysql