Skip to content

feat(functions.lua): add ESX.GetJob() function to retrieve job data b… #1679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

MrSne7aky
Copy link
Contributor

Adds a new function ESX.GetJob(jobName) that returns the full job data for a given job name from the ESX.Jobs table.

If the job name is invalid or not found, the function returns nil and logs a warning.

This provides a simple way to access job metadata by name.


Description

Adds a utility function to retrieve a single job's full data using its name.


Motivation

To provide a cleaner and more consistent way to access job data, especially in cases where only one specific job is needed.


Implementation Details

  • Looks up the job in ESX.Jobs by key.
  • If found, returns the full job table.
  • If not found, returns nil and prints a warning to the console.

Usage Example

local job = ESX.GetJob("police")
if job then
    print(job.name, job.label)
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.

…y name

Adds a new function `ESX.GetJob(jobName)` that returns the full job data for a given job name from the `ESX.Jobs` table.

If the job name is invalid or not found, the function returns nil and logs a warning.

This provides a simple way to access job metadata by name.
@Kenshiin13 Kenshiin13 changed the base branch from main to dev July 25, 2025 13:39
@@ -561,6 +561,18 @@ function ESX.GetJobs()
return ESX.Jobs
end

---@param jobName string
---@return table|nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use

---@return table?

if job then
return job
else
print(("[^3WARNING^7] Attempting to get invalid job: ^5%s^7"):format(jobName))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simply attempt to retun ESX.Jobs[jobName]. This function should be one line. It is expected that this function will be called via user input a lot, so having a warning printed can be quite annoying.

@Kenshiin13
Copy link
Contributor

We can also add an optional key param to the function, which would be more aligned with your initial PR.

ESX.GetJob(jobName: string, key: string?)
local pdLabel = ESX.GetJob("police", "label")

@MrSne7aky MrSne7aky closed this Jul 25, 2025
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.

2 participants