Skip to content

Commit

Permalink
Merge pull request #1437 from Kenshiin13/job-duty
Browse files Browse the repository at this point in the history
feat(server/classes/player): Add job duty
  • Loading branch information
Mycroft-Studios authored Nov 2, 2024
2 parents bb27898 + 6259e12 commit 1594510
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions [core]/es_extended/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 17 additions & 1 deletion [core]/es_extended/server/classes/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -503,21 +508,31 @@ 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

if not ESX.DoesJobExist(newJob, grade) then
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,
Expand All @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion [core]/es_extended/server/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1594510

Please sign in to comment.