> For the complete documentation index, see [llms.txt](https://docs.kojascripts.eu/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kojascripts.eu/koja-lib/api-reference/server-api/player.md).

# Player

Functions for reading player information on the server.

## GetPlayers

Returns a list of all connected player server IDs.

```lua
local players = KOJA.Server.GetPlayers()
```

**Returns** `number[]`

## GetPlayerBySource

Returns the framework's player object for a given server ID.

```lua
local player = KOJA.Server.GetPlayerBySource(source)
```

**Returns** `table | nil` — the raw framework player object, or `nil` if not found.

{% hint style="info" %}
The structure of the returned table depends on the framework. Use the specific helper functions below when possible.
{% endhint %}

## GetPlayerIdentifier

Returns the player's unique character identifier.

```lua
local id = KOJA.Server.GetPlayerIdentifier(source)
```

**Returns** `string | nil`

| Framework | Returns                                                 |
| --------- | ------------------------------------------------------- |
| ESX       | `identifier` (license hash)                             |
| QBCore    | `citizenid`                                             |
| Custom    | whatever `CustomFramework.Server.GetIdentifier` returns |

## GetPlayerName

Returns the player's display name.

```lua
local name = KOJA.Server.GetPlayerName(source)
```

**Returns** `string`

| Framework | Returns                                |
| --------- | -------------------------------------- |
| ESX       | `firstName lastName`                   |
| QBCore    | `charinfo.firstname charinfo.lastname` |

## GetPlayerJob

Returns the player's current job.

```lua
local job = KOJA.Server.GetPlayerJob(source)
```

**Returns** `table`

```lua
{
    name  = "police",  -- job name
    grade = 2,         -- grade level (number)
}
```

## GetPlayerGroup

Returns the player's permission group.

```lua
local group = KOJA.Server.GetPlayerGroup(source)
```

**Returns** `string | nil` — e.g. `"admin"`, `"superadmin"`, `"user"`.

## Examples

```lua
-- Print info for all players
for _, id in ipairs(KOJA.Server.GetPlayers()) do
    local name = KOJA.Server.GetPlayerName(id)
    local job  = KOJA.Server.GetPlayerJob(id)
    print(('%s — %s [grade %d]'):format(name, job.name, job.grade))
end

-- Check if a player is an admin
if KOJA.Server.GetPlayerGroup(source) == 'admin' then
    -- grant access
end

-- Check job
local job = KOJA.Server.GetPlayerJob(source)
if job.name == 'mechanic' and job.grade >= 2 then
    -- senior mechanic
end
```


---

# 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:

```
GET https://docs.kojascripts.eu/koja-lib/api-reference/server-api/player.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
