diff --git a/[core]/es_extended/config.lua b/[core]/es_extended/config.lua index 933312cb7..a1a69c369 100644 --- a/[core]/es_extended/config.lua +++ b/[core]/es_extended/config.lua @@ -47,6 +47,7 @@ Config.EnableDebug = false -- Use Debug options? Config.EnableDefaultInventory = true -- Display the default Inventory ( F2 ) Config.EnableWantedLevel = false -- Use Normal GTA wanted Level? Config.EnablePVP = true -- Allow Player to player combat +Config.DefaultJobDuty = true -- A players default duty status when changing jobs Config.Multichar = GetResourceState("esx_multicharacter") ~= "missing" Config.Identity = true -- Select a character identity data before they have loaded in (this happens by default with multichar) diff --git a/[core]/es_extended/server/classes/player.lua b/[core]/es_extended/server/classes/player.lua index a9145d129..17968d0e1 100644 --- a/[core]/es_extended/server/classes/player.lua +++ b/[core]/es_extended/server/classes/player.lua @@ -58,6 +58,11 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, self.license = ("license:%s"):format(identifier) end + if type(self.metadata.jobDuty) ~= "boolean" then + self.metadata.jobDuty = self.job.name ~= "unemployed" and Config.DefaultJobDuty or false + end + job.onDuty = self.metadata.jobDuty + ExecuteCommand(("add_principal identifier.%s group.%s"):format(self.license, self.group)) local stateBag = Player(self.source).state @@ -503,8 +508,9 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, ---@param newJob string ---@param grade string + ---@param onDuty? boolean ---@return nil - function self.setJob(newJob, grade) + function self.setJob(newJob, grade, onDuty) grade = tostring(grade) local lastJob = self.job @@ -512,12 +518,21 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, return print(("[ESX] [^3WARNING^7] Ignoring invalid ^5.setJob()^7 usage for ID: ^5%s^7, Job: ^5%s^7"):format(self.source, newJob)) end + if newJob == "unemployed" then + onDuty = false + end + + if type(onDuty) ~= "boolean" then + onDuty = Config.DefaultJobDuty + end + local jobObject, gradeObject = ESX.Jobs[newJob], ESX.Jobs[newJob].grades[grade] self.job = { id = jobObject.id, name = jobObject.name, label = jobObject.label, + onDuty = onDuty, grade = tonumber(grade), grade_name = gradeObject.name, @@ -528,6 +543,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, skin_female = gradeObject.skin_female and json.decode(gradeObject.skin_female) or {}, } + self.metadata.jobDuty = onDuty TriggerEvent("esx:setJob", self.source, self.job, lastJob) self.triggerEvent("esx:setJob", self.job, lastJob) Player(self.source).state:set("job", self.job, true) diff --git a/[core]/es_extended/server/commands.lua b/[core]/es_extended/server/commands.lua index a8f1eb8e6..dfb4baa5d 100644 --- a/[core]/es_extended/server/commands.lua +++ b/[core]/es_extended/server/commands.lua @@ -544,7 +544,9 @@ ESX.RegisterCommand("group", { "user", "admin" }, function(xPlayer, _, _) end, true) ESX.RegisterCommand("job", { "user", "admin" }, function(xPlayer, _, _) - print(("%s, your job is: ^5%s^0 - ^5%s^0"):format(xPlayer.getName(), xPlayer.getJob().name, xPlayer.getJob().grade_label)) + local job = xPlayer.getJob() + + print(("%s, your job is: ^5%s^0 - ^5%s^0 - ^5%s^0"):format(xPlayer.getName(), job.name, job.grade_label, job.onDuty and "On Duty" or "Off Duty")) end, false) ESX.RegisterCommand("info", { "user", "admin" }, function(xPlayer)