Skip to content

[Feature Request] - es_extended - include duty status in job statebag counter #1536

Description

@Maximus7474

Describe the Feature

With the new version (1.11.*) and the integration of job duty, it would be useful to alter the data in ESX.JobsPlayerCount to not only reflect the number of connected players with the job but also players with the job active.

This could also be done with another system in parallel with an object called something like ESX.JobsOnDutyPlayerCount.

Screenshots

This is only rough idea to detail the imagined concept

AddEventHandler("esx:setJob", function(_, job, lastJob)
    local lastJobKey = ("%s:count"):format(lastJob.name)
    local jobKey = ("%s:count"):format(job.name)

    local currentLastJob = ESX.JobsPlayerCount[lastJob.name] or {players: 0, onDuty: 0}
    local currentNewJob = ESX.JobsPlayerCount[lastJob.name] or {players: 0, onDuty: 0}

    ESX.JobsPlayerCount[lastJob.name] = {
        players: currentLastJob - 1,
        onDuty: currentLastJob - (lastJob.onDuty and 1 or 0)
    }

    ESX.JobsPlayerCount[job.name] = {
        players: currentNewJob + 1,
        onDuty: currentNewJob + (job.onDuty and 1 or 0)
    }

    GlobalState[lastJobKey] = ESX.JobsPlayerCount[lastJob.name]
    GlobalState[jobKey] = ESX.JobsPlayerCount[job.name]
end)

Additional context

This can be very useful for scripts that check if any players are on duty to allow/deny the use of certain functionalities.

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
To Be Assigned

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions