# 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{type="info"}
The structure of the returned table depends on the framework. Use the specific helper functions below when possible.
:::

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

## Related pages

- [Police](/koja-lib/api-reference/server-api/police) — Functions for checking how many police officers are online.
- [Callbacks](/koja-lib/api-reference/server-api/callbacks) — The callback system allows server scripts to handle requests from clients and vice versa.
- [Licenses](/koja-lib/api-reference/server-api/licenses) — Check whether a player holds a specific driving or skill license.
- [Money](/koja-lib/api-reference/server-api/money) — Functions for reading and modifying a player's money on the server.
- [Inventory](/koja-lib/api-reference/server-api/inventory) — Server-side inventory functions.
- [Notifications](/koja-lib/api-reference/server-api/notifications) — Send notifications to a player from the server side.
- [Server API](/koja-lib/api-reference/server-api) — back to the section overview
