Skip to content

Conversation

Kenshiin13
Copy link
Contributor

@Kenshiin13 Kenshiin13 commented Sep 7, 2025

Description

Introducing job types for ESX, inspired by the QB framework (leo, ems, etc.). Each job now has an associated type, making it easier to categorize and handle them without relying on manual whitelists.


Motivation

Currently, developers often resort to maintaining long, error-prone job whitelists for common tasks such as:

  • Dispatch notifications
  • Basic Permission checks
  • Shared logic between similar jobs

By introducing job types, developers can check a player’s job type directly instead of maintaining and updating multiple job-specific conditions. This provides cleaner, more maintainable, and more scalable code.


Implementation Details

  • Each job definition in ESX.Jobs can now include a type property (e.g., "leo", "ems", "mechanic", "civ", etc.).
  • A new utility ESX.GetJobs(jobType) was added to filter jobs by type.
  • Backwards compatibility is preserved — existing jobs without a type will continue to function as usual. The default jobType is civ.

Usage Example

-- Check if a player is in law enforcement (LEO)
if xPlayer.job.type == "leo" then
    print("Player is in law enforcement")
end

-- Get all EMS jobs
local emsJobs = ESX.GetJobs("ems")
for jobName, jobData in pairs(emsJobs) do
    print(jobName, jobData.label)
end

-- Get all jobs that are either EMS or LEO
local emergencyJobs = ESX.GetJobs({ "ems", "leo" })

This eliminates the need for code like:

if xPlayer.job.name == "police" or xPlayer.job.name == "sheriff" or xPlayer.job.name == "fib" then
    -- do something
end

PR Checklist

  • My commit messages and PR title follow the Conventional Commits standard.
  • My changes have been tested locally and function as expected.
  • My PR does not introduce any breaking changes.
  • I have provided a clear explanation of what my PR does, including the reasoning behind the changes and any relevant context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant