Koja Scripts
KOJA-LIB

Police

Functions for checking how many police officers are online.

Police

Functions for checking how many police officers are online.


GetCopCount

Returns the number of players currently working a police job.

local count = KOJA.Server.GetCopCount()

Returns number

Also available as an export:

local count = exports['koja-lib']:getCopCount()

Configuration

Which jobs count as police is controlled by Config.PoliceGroups:

-- editable/shared/config.lua
Config.PoliceGroups = {
    ["police"]  = true,
    ["sheriff"] = true,
    ["swat"]    = true,
}

Examples

-- Gate an action behind a minimum cop count
local cops = KOJA.Server.GetCopCount()

if cops < 2 then
    KOJA.Server.SendNotify({
        source = source,
        type   = 'error',
        desc   = 'At least 2 police officers must be online.',
    })
    return
end

Callback

The cop count is also exposed as a server callback for client scripts:

-- Client
KOJA.Client.TriggerServerCallback('koja-heistlib:Server:getCopCount', nil, function(data)
    print('Cops online:', data.count)
end)
  • 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.
  • Player — Functions for reading player information on the server.
  • Server API — back to the section overview