How to create an ESX job

So I am trying to make a simple version of ESX_policejob. Number 1, because I don’t like esx_policejob and number 2, I need to get better at Lua. Anyway, I’m making it with NativeUI so they just have to click a button and boom! They are now on duty. I have everything on it, weapons, cars, and the locker room. The only thing I’m missing is a way to make it so when they click the “Go on duty” button, it actually makes them go on duty. By “go on duty” I mean that when they click that it starts to pay them and whatnot, instead of just always paying them. And then they click go off duty and it stops. Can anyone help?

Create a seperate job in the database, for example offduty, set the paycheck to 0.
When he goes offduty set his job to this, when he goes onduty ser his job back to police

you are a genius. That seemed so simple lol.

wait but wont it give them the first job grade and not the one they were on if they go off duty and back on.

If your job has 4 grades, you will have to add 4 grades for the offduty job. You can find an example of that here: ESX_Duty

1 Like

I will take a look.

oh that makes sense thank you!

How do I make it so the code knows which grade I am talking about? For instance

function FourthItem(menu)
    local job = xPlayer.job.name
    local grade = xPlayer.job.grade
    local onduty = NativeUI.CreateItem("Go On Duty", "Lets you go on duty")
    menu:AddItem(onduty)
    menu.OnItemSelect = function(sender, item, index)
        if item == onduty then
            if job == 'offpolice' then

How will it know which grade of ‘offpolice’ I am talking about?

Create 4 offduty jobs with 4 grades.
Then do xPlayer.job_grade and you should get a number

1 Like

Exactly, on the server side you can put this:

RegisterServerEvent('duty:police')
AddEventHandler('duty:police', function(job)

        local _source = source
        local xPlayer = ESX.GetPlayerFromId(_source)

    
    if xPlayer.job.name == 'police' and xPlayer.job.grade == 1 then
        xPlayer.setJob('offpolice', 1)
    elseif xPlayer.job.name == 'police' and xPlayer.job.grade == 2 then
        xPlayer.setJob('offpolice', 2)
    elseif xPlayer.job.name == 'police' and xPlayer.job.grade == 3 then
        xPlayer.setJob('offpolice', 3)
    elseif xPlayer.job.name == 'police' and xPlayer.job.grade == 4 then
        xPlayer.setJob('offpolice', 4)
    elseif xPlayer.job.name == 'police' and xPlayer.job.grade == 0 then
        xPlayer.setJob('offpolice', 0)
    end

    if xPlayer.job.name == 'offpolice' and xPlayer.job.grade == 1 then
        xPlayer.setJob('police', 1)
    elseif xPlayer.job.name == 'offpolice' and xPlayer.job.grade == 2 then
        xPlayer.setJob('police', 2)
    elseif xPlayer.job.name == 'offpolice' and xPlayer.job.grade == 3 then
        xPlayer.setJob('police', 3)
    elseif xPlayer.job.name == 'offpolice' and xPlayer.job.grade == 4 then
        xPlayer.setJob('police', 4)
    elseif xPlayer.job.name == 'offpolice' and xPlayer.job.grade == 0 then
        xPlayer.setJob('police', 0)
    end
end)

I can’t seem to find where i found that code. I thought it was in what i sent you (esx_duty) but after looking it seems like that wasn’t the case, sorry.

1 Like

Thank you. And its ok

1 Like

why would this be used in the server and not client.lua

You have to put it server side because it’s the server which changes the job of the player. The xPlayer.setJob is only available on the server side (i believe)

Alright

1 Like