Player
Functions for reading player information on the server.
GetPlayers
Returns a list of all connected player server IDs.
local players = KOJA.Server.GetPlayers()
Returns number[]
GetPlayerBySource
Returns the framework's player object for a given server ID.
local player = KOJA.Server.GetPlayerBySource(source)
Returns table | nil — the raw framework player object, or nil if not found.
GetPlayerIdentifier
Returns the player's unique character identifier.
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.
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.
local job = KOJA.Server.GetPlayerJob(source)
Returns table
{
name = "police", -- job name
grade = 2, -- grade level (number)
}
GetPlayerGroup
Returns the player's permission group.
local group = KOJA.Server.GetPlayerGroup(source)
Returns string | nil — e.g. "admin", "superadmin", "user".
Examples
-- 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 — Functions for checking how many police officers are online.
- Callbacks — The callback system allows server scripts to handle requests from clients and vice versa.
- Licenses — Check whether a player holds a specific driving or skill license.
- Money — Functions for reading and modifying a player's money on the server.
- Inventory — Server-side inventory functions.
- Notifications — Send notifications to a player from the server side.
- Server API — back to the section overview