Skip to content

Exports & events

Public API of Cuxial Community Service: server exports to add, remove and read community service and jail.

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:

ValueTypeDescription
okbooleantrue when the change was saved.
detailstringOn 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.

lua
local ok, detail = exports.cuxial_cmservices:AddCommunityService(citizenid, amount, reason, admin)
ParameterTypeDescription
citizenidstringCharacter id.
amountnumberTasks to give, from 1 to comserv.maxApiTasks. Decimals are rounded down.
reasonstringReason. Required; cut to admin.reasonMax characters.
admintableOptional. Who gives the sanction.

Returns: boolean, string.

lua
local ok, detail = exports.cuxial_cmservices:AddCommunityService('ABC12345', 10, 'Reckless driving', {
    name = 'Web panel',
    identifier = 'web',
})
if not ok then print(detail) end

RemoveCommunityService ​

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.

lua
local ok, detail = exports.cuxial_cmservices:RemoveCommunityService(citizenid, admin)
ParameterTypeDescription
citizenidstringCharacter id.
admintableOptional. 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.

lua
local ok, detail = exports.cuxial_cmservices:AddJail(citizenid, minutes, reason, admin)
ParameterTypeDescription
citizenidstringCharacter id.
minutesnumberMinutes, from 1 to jail.maxMinutes. Decimals are rounded down.
reasonstringReason. Required; cut to admin.reasonMax characters.
admintableOptional. 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.

lua
local ok, detail = exports.cuxial_cmservices:RemoveJail(citizenid, admin)
ParameterTypeDescription
citizenidstringCharacter id.
admintableOptional. 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.

lua
local punishment = exports.cuxial_cmservices:GetPlayerPunishment(player, kind)
ParameterTypeDescription
playernumber | string | tableServer id of an online player, a citizenid, or a player table with citizenid (or PlayerData.citizenid).
kindstringOptional. 'comserv' or 'jail'.

Returns:

kindReturns
'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:

FieldTypeDescription
donenumberTasks done, or minutes served.
totalnumberTasks given, or total minutes.
reasonstringReason.
startnumberUnix time when the sanction was given.
admintableWho gave it: name and identifier.
lua
local jail = exports.cuxial_cmservices:GetPlayerPunishment(source, 'jail')
if jail then
    print(('%d minutes left'):format(jail.total - jail.done))
end

© Cuxial