Give, remove and read sanctions from your own resources, such as an admin menu or a web panel. The API is five server exports; the script exposes no public events.
Every export works with the character online (applied at once) or offline (saved and applied on their next login). Characters are identified by citizenid; on ESX this is the character identifier.
Return values
The four write exports return two values:
| Value | Type | Description |
|---|---|---|
ok | boolean | true when the change was saved. |
detail | string | On success, 'online' or 'offline'. On failure, the reason in the server language, for example "Invalid data", "The player already has an active punishment", "Player or punishment not found" or "Internal error". |
The optional admin parameter is a table { name = string, identifier = string } that is stored with the sanction and shown in the panel and the logs. Without it, the sanction is recorded as given from the panel.
Every sanction given, removed or served through an export is announced and logged like one given by command.
Server exports
AddCommunityService
Gives community service tasks to a character. If the character already has community service, the tasks are added to it and the reason is appended. It is refused while the character is in jail.
local ok, detail = exports.cuxial_cmservices:AddCommunityService(citizenid, amount, reason, admin)| Parameter | Type | Description |
|---|---|---|
citizenid | string | Character id. |
amount | number | Tasks to give, from 1 to comserv.maxApiTasks. Decimals are rounded down. |
reason | string | Reason. Required; cut to admin.reasonMax characters. |
admin | table | Optional. Who gives the sanction. |
Returns: boolean, string.
local ok, detail = exports.cuxial_cmservices:AddCommunityService('ABC12345', 10, 'Reckless driving', {
name = 'Web panel',
identifier = 'web',
})
if not ok then print(detail) endRemoveCommunityService
Removes the community service of a character. An online player is moved to the exit point, or back to jail if they also have jail time.
local ok, detail = exports.cuxial_cmservices:RemoveCommunityService(citizenid, admin)| Parameter | Type | Description |
|---|---|---|
citizenid | string | Character id. |
admin | table | Optional. Who removes it. |
Returns: boolean, string. Fails with "Player or punishment not found" when the character has no community service.
AddJail
Sends a character to administrative jail. It is refused while the character is already in jail. If the character has community service, jail goes first and the community service resumes where it was once the time is served.
local ok, detail = exports.cuxial_cmservices:AddJail(citizenid, minutes, reason, admin)| Parameter | Type | Description |
|---|---|---|
citizenid | string | Character id. |
minutes | number | Minutes, from 1 to jail.maxMinutes. Decimals are rounded down. |
reason | string | Reason. Required; cut to admin.reasonMax characters. |
admin | table | Optional. Who gives the sanction. |
Returns: boolean, string.
RemoveJail
Releases a character from jail. An online player is moved to the jail exit point, or to the community service zone if they still have tasks.
local ok, detail = exports.cuxial_cmservices:RemoveJail(citizenid, admin)| Parameter | Type | Description |
|---|---|---|
citizenid | string | Character id. |
admin | table | Optional. Who removes it. |
Returns: boolean, string. Fails with "Player or punishment not found" when the character is not in jail.
GetPlayerPunishment
Returns the active sanctions of a character.
local punishment = exports.cuxial_cmservices:GetPlayerPunishment(player, kind)| Parameter | Type | Description |
|---|---|---|
player | number | string | table | Server id of an online player, a citizenid, or a player table with citizenid (or PlayerData.citizenid). |
kind | string | Optional. 'comserv' or 'jail'. |
Returns:
kind | Returns |
|---|---|
'comserv' or 'jail' | The sanction of that type, or false. |
| omitted | { comserv = sanction?, jail = sanction? }, or false when the character has neither. |
A sanction is a table with these fields:
| Field | Type | Description |
|---|---|---|
done | number | Tasks done, or minutes served. |
total | number | Tasks given, or total minutes. |
reason | string | Reason. |
start | number | Unix time when the sanction was given. |
admin | table | Who gave it: name and identifier. |
local jail = exports.cuxial_cmservices:GetPlayerPunishment(source, 'jail')
if jail then
print(('%d minutes left'):format(jail.total - jail.done))
end