[ESX] On / Off Duty Script

basically I just keep getting Locale [sv] dose not exist

how to make an animation?

i used the esx ,when i go off duty , it’s still show" you already off-duty "word , but player list ambulance still show “ambulance on-duty” , so my ambulance can’t off duty forever :sob:)

so i don’t know why ambulance still off-duty …
have people can tell my why and save me :sob::sob:?

me too … Have you solved this problem?

ignoring invalid .setJob()

for some reason i cannot go back on duty for police.

how did you get that notification box alert

Hello, this is kind of improvement if anyone wants.

esx_duty/server/main.lua

FROM

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)
    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)
    end
end)

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

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

    if xPlayer.job.name == 'ambulance' and xPlayer.job.grade == 1 then
        xPlayer.setJob('offambulance', 1)
    elseif xPlayer.job.name == 'ambulance' and xPlayer.job.grade == 2 then
        xPlayer.setJob('offambulance', 2)
    elseif xPlayer.job.name == 'ambulance' and xPlayer.job.grade == 3 then
        xPlayer.setJob('offambulance', 3)
    end

    if xPlayer.job.name == 'offambulance' and xPlayer.job.grade == 1 then
        xPlayer.setJob('ambulance', 1)
    elseif xPlayer.job.name == 'offambulance' and xPlayer.job.grade == 2 then
        xPlayer.setJob('ambulance', 2)
    elseif xPlayer.job.name == 'offambulance' and xPlayer.job.grade == 3 then
        xPlayer.setJob('ambulance', 3)
    end
end)

TO

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

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

    if xPlayer.job.name == 'police' then
        xPlayer.setJob('offpolice', xPlayer.job.grade)
    end

    if xPlayer.job.name == 'offpolice' then
        xPlayer.setJob('police', xPlayer.job.grade)
    end
end)

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

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

    if xPlayer.job.name == 'ambulance' then
        xPlayer.setJob('offambulance', xPlayer.job.grade)
    end

    if xPlayer.job.name == 'offambulance' then
        xPlayer.setJob('ambulance', xPlayer.job.grade)
    end
end)

This code supports all kind of the job grades that are coded above(police, ambulance).

2 Likes

What do you mean duplicated the mod?

Hello again, i received some messages asking me about how to add multiple on/off duty for some jobs such as police departments, ambulance etc.

This is they way you want to do it:

esx_duty/client/main.lua

Go on the --keycontrols and you will need to double-create the code of the job you want and change the action value.

This is the ambulance:

        if CurrentAction == 'ambulance_duty' then
          if PlayerData.job.name == 'ambulance' or PlayerData.job.name == 'offambulance' then
            TriggerServerEvent('duty:ambulance')
          if PlayerData.job.name == 'ambulance' then
            sendNotification(_U('offduty'), 'success', 2500)
            Wait(1000)
          else
            sendNotification(_U('onduty'), 'success', 2500)
            Wait(1000)
          end
        else
          sendNotification(_U('not_ambulance'), 'error', 5000)
          Wait(1000)
        end
      end

What you have to do is to not change the original code and copy-paste the same thing below, the only thing you change is the CurrentAction == ‘ambulance_duty’, you just do it as CurrentAction == ‘ambulance_duty_2’ or whatever you want to just keep it out from the default ambulance code.

Then you go up to the hasEnteredMarker event and you just do the same as the other one, you add this inside:

  if zone == 'AmbulanceDuty2' then
    CurrentAction     = 'ambulance_duty_2' -- <- this is the action you added to be used
    CurrentActionMsg  = _U('duty')
    CurrentActionData = {}
  end

after that, just open config and add AmbulanceDuty2 inside and choose the location you want.

Im ambulance but i can see police blip for change duty ?
Can you help me?

Hello, I want to add the taxi and the mechanic too

im only go offduty can somebody help me with this problem

could be posible add cardealer ?

is possible to add like a short command via chat for this script? example type in chat /dutyoff and auto set a police or ambulance off service?

Hi, great scrip thanks though when I change the Police Zone for the marker it stops working and it dosnt recognise that I am in the zone. Any tips?

UPDATE: I just had to restart the script /restart esx_duty

how to add more job to off duty ? example , i want burgershot to off duty

The script works perfectly, you don’t need anything else, thanks

Hey type it and it say, invalid password how to fix

did you know why… in my server error [es_extended] [WARNING] Ignoring invalid .setjob()

happens to me too :frowning: does anyone know?

image