> For the complete documentation index, see [llms.txt](https://xcore.gitbook.io/xcore-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xcore.gitbook.io/xcore-docs/multijob/functions.md).

# FUNCTIONS

```lua
functions = {}

functions.setJob = function(data)
    local xPlayer = nil
    if type(data.playerid) == "number" then
        xPlayer = ESX.GetPlayerFromId(data.playerid)
        if not xPlayer then
            print("[ERROR][setJob] No player found with ID:", data.playerid)
        end
    elseif type(data.playerid) == "string" then
        for _, player in pairs(ESX.GetPlayers()) do
            local tempPlayer = ESX.GetPlayerFromId(player)
            if tempPlayer and tempPlayer.identifier == data.playerid then
                xPlayer = tempPlayer
                break
            end
        end
        if not xPlayer then
            print("[ERROR][setJob] No player found with identifier:", data.playerid)
        end
    else
        print("[ERROR][setJob] Invalid playerid type:", type(data.playerid))
    end

    if xPlayer then
        xPlayer.setJob(data.jobname, data.jobgrade)
    else
        print("[ERROR][setJob] Player not found for setJob with playerid:", data.playerid)
    end
end

functions.getJobName = function(playerid)
    local xPlayer = nil
    if type(playerid) == "number" then
        xPlayer = ESX.GetPlayerFromId(playerid)
        if not xPlayer then
            print("[ERROR][getJobName] No player found with ID:", playerid)
        end
    elseif type(playerid) == "string" then
        for _, player in pairs(ESX.GetPlayers()) do
            local tempPlayer = ESX.GetPlayerFromId(player)
            if tempPlayer and tempPlayer.identifier == playerid then
                xPlayer = tempPlayer
                break
            end
        end
        if not xPlayer then
            print("[ERROR][getJobName] No player found with identifier:", playerid)
        end
    else
        print("[ERROR][getJobName] Invalid playerid type:", type(playerid))
    end

    if xPlayer and xPlayer.getJob() then
        return xPlayer.getJob().name
    else
        print("[ERROR][getJobName] xPlayer or job is nil for playerid:", playerid)
        return nil
    end
end

functions.getJobGrade = function(playerid)
    local xPlayer = nil
    if type(playerid) == "number" then
        xPlayer = ESX.GetPlayerFromId(playerid)
        if not xPlayer then
            print("[ERROR][getJobGrade] No player found with ID:", playerid)
        end
    elseif type(playerid) == "string" then
        for _, player in pairs(ESX.GetPlayers()) do
            local tempPlayer = ESX.GetPlayerFromId(player)
            if tempPlayer and tempPlayer.identifier == playerid then
                xPlayer = tempPlayer
                break
            end
        end
        if not xPlayer then
            print("[ERROR][getJobGrade] No player found with identifier:", playerid)
        end
    else
        print("[ERROR][getJobGrade] Invalid playerid type:", type(playerid))
    end

    if xPlayer and xPlayer.getJob() then
        return xPlayer.getJob().grade
    else
        print("[ERROR][getJobGrade] xPlayer or job is nil for playerid:", playerid)
        return nil
    end
end

functions.getIdentifier = function(playerid)
    if type(playerid) == "number" then
        local xPlayer = ESX.GetPlayerFromId(playerid)
        if xPlayer then
            return xPlayer.identifier
        else
            print("[ERROR][getIdentifier] Player not found or xPlayer is nil for player ID:", playerid)
            return nil
        end
    elseif type(playerid) == "string" then
        for _, player in pairs(ESX.GetPlayers()) do
            local xPlayer = ESX.GetPlayerFromId(player)
            if xPlayer and xPlayer.identifier == playerid then
                return xPlayer.identifier
            end
        end
        print("[ERROR][getIdentifier] No player found with identifier:", playerid)
        return nil
    else
        print("[ERROR][getIdentifier] Invalid playerid type:", type(playerid))
        return nil
    end
end

functions.getName = function(playerid)
    local xPlayer = nil
    if type(playerid) == "number" then
        xPlayer = ESX.GetPlayerFromId(playerid)
        if not xPlayer then
            print("[ERROR][getName] No player found with ID:", playerid)
        end
    elseif type(playerid) == "string" then
        for _, player in pairs(ESX.GetPlayers()) do
            local tempPlayer = ESX.GetPlayerFromId(player)
            if tempPlayer and tempPlayer.identifier == playerid then
                xPlayer = tempPlayer
                break
            end
        end
        if not xPlayer then
            print("[ERROR][getName] No player found with identifier:", playerid)
        end
    else
        print("[ERROR][getName] Invalid playerid type:", type(playerid))
    end

    if xPlayer then
        return xPlayer.getName()
    else
        print("[ERROR][getName] xPlayer is nil for playerid:", playerid)
        return nil
    end
end

functions.getPlayerGroup = function(playerid)
    local xPlayer = nil
    if type(playerid) == "number" then
        xPlayer = ESX.GetPlayerFromId(playerid)
        if not xPlayer then
            print("[ERROR][getPlayerGroup] No player found with ID:", playerid)
        end
    elseif type(playerid) == "string" then
        for _, player in pairs(ESX.GetPlayers()) do
            local tempPlayer = ESX.GetPlayerFromId(player)
            if tempPlayer and tempPlayer.identifier == playerid then
                xPlayer = tempPlayer
                break
            end
        end
        if not xPlayer then
            print("[ERROR][getPlayerGroup] No player found with identifier:", playerid)
        end
    else
        print("[ERROR][getPlayerGroup] Invalid playerid type:", type(playerid))
    end

    if xPlayer then
        return xPlayer.getGroup()
    else
        print("[ERROR][getPlayerGroup] xPlayer is nil for playerid:", playerid)
        return nil
    end
end

functions.getESXPlayer = function(playerid)
    local xPlayer = nil
    if type(playerid) == "number" then
        xPlayer = ESX.GetPlayerFromId(playerid)
        if not xPlayer then
            print("[ERROR][getESXPlayer] No player found with ID:", playerid)
        end
    elseif type(playerid) == "string" then
        for _, player in pairs(ESX.GetPlayers()) do
            local tempPlayer = ESX.GetPlayerFromId(player)
            if tempPlayer and tempPlayer.identifier == playerid then
                xPlayer = tempPlayer
                break
            end
        end
        if not xPlayer then
            print("[ERROR][getESXPlayer] No player found with identifier:", playerid)
        end
    else
        print("[ERROR][getESXPlayer] Invalid playerid type:", type(playerid))
    end

    return xPlayer
end

return functions

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://xcore.gitbook.io/xcore-docs/multijob/functions.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
