JCKSDocs
JCKS LibFunkcie

Core modules

The jcks global from @jcks_lib/init.lua with callbacks, safe net events, cache, keybinds, streaming, points, zones and helpers.

jcks_lib replaces the ox_lib core for every JCKS resource. Add the import to your resource:

lua
shared_script '@jcks_lib/init.lua'

This creates the global jcks. Modules load on first use and run inside your resource, so calling them costs no export round trip. init.lua and imports/ stay readable in the escrowed release for that reason.

Field Value
jcks.name jcks_lib
jcks.context client or server
jcks.resource Name of your resource
jcks.require(...) Loads modules up front, for example jcks.require('cache', 'points')

callback

Server:

lua
jcks.callback.register('myres:getBalance', function(source, account)
    return Accounts.get(source, account)
end, { args = { 'string' }, limit = { count = 5, window = 1000 } })

local result = jcks.callback.await(playerId, 'myres:askConfirm', 15000, 'Sell the car?')

Client:

lua
local balance, err = jcks.callback.await('myres:getBalance', 5000, 'bank')

jcks.callback.register('myres:askConfirm', function(text)
    return Dialog.confirm(text)
end)
Option Default What it does
args none Types the server accepts, in order: string, number, boolean, table, any. Add ? for optional ('number?'). Calls with other types or more arguments are refused. NaN and infinity never pass as numbers. Takes the same schema as jcks.net.on.
rest false Accept extra arguments after the typed ones
limit 10 calls per 1000 ms per player { count, window }, or false to turn it off

A refused call returns nil, 'rate_limited', nil, 'invalid_arguments', nil, 'error' or nil, 'timeout' to the client. Refusals are printed at most once a minute per player and fire the server event jcks_lib:callbackRefused (resource, name, source, reason).

The handler gets source as its first argument. Keep it in a local before any Wait or await.

A callback name belongs to the first resource that registers it. A second resource that registers the same name while the first one runs gets false back and a console line. register returns true on success, unregister(name) frees the name again.

The client await(name, timeout, ...) takes 100 to 120000 ms, default 10000. The server await(playerId, name, timeout, ...) returns nil on timeout or when the player leaves. trigger is the callback form: jcks.callback.trigger(name, function(...) end, ...) on the client, with { timeout = 2000 } in place of the function to set a timeout and the function as the next argument, and jcks.callback.trigger(playerId, name, timeout, function(...) end, ...) on the server.

net (server)

Net events with a required schema. Anything outside it is refused before your handler runs, and refusals are reported to jcks_bridge security (weight 2 by default) and fire the server event jcks_lib:netRefused (resource, name, source, reason).

lua
jcks.net.on('myres:server:repair', {
    args = {
        { type = 'number', int = true, min = 1 },
        { type = 'string', max = 32, oneOf = { 'engine', 'body' } },
    },
    limit = { count = 2, window = 5000 },
    job = { mechanic = 1 },
    permission = 'myres.repair',
    distance = { arg = 1, entity = true, max = 6.0 },
    report = 3,
}, function(src, netId, part)
end)
Key What it does
args One entry per argument: a type name ('string', 'number?', 'table', 'boolean', 'vector3', 'any') or a table { type, optional, min, max, int, pattern, oneOf, maxKeys, fields = {...}, strict, items }. Strings default to at most 256 characters, tables to 64 keys.
noArgs Must be true on events without args
rest true accepts extra arguments after the typed ones
limit Per player, default 5 per second, false turns it off. Rate limit refusals are only reported to bridge security with limitReport = true.
job Job and minimum grade, or a function (src, job)
permission ACE or jcks_bridge permission, or a function (src)
distance coords (vector or function), or arg with entity = true (net id) or player = true (server id), plus max (default 5.0)
report Weight for bridge security, false does not report
allowServer true also runs the handler for events triggered on the server, with 0 as the source

jcks.net.off(name) removes the handler again.

cache (client)

lua
local ped = jcks.cache.ped
local off = jcks.cache.on('vehicle', function(vehicle, old)
    if vehicle then Hud.showSpeedo(vehicle) else Hud.hideSpeedo() end
end)

Keys: playerId, serverId, ped, vehicle (handle or false), seat (-1 driver, 0 and up passengers, or false), weapon (hash or false), resource. One loop in jcks_lib checks the values every 100 ms for every resource and only sends an event when something changes. cache.on returns a function that removes the handler.

keybind (client)

lua
local bind = jcks.keybind({
    name = 'myres_menu',
    description = 'Open the job menu',
    defaultKey = 'F5',
    onPressed = function(self) Menu.toggle() end,
    onReleased = function(self) end,
})

bind:disable(true)
print(bind:getKey())

Built on RegisterKeyMapping, so players change the key in the GTA settings. No loop runs while the key is not pressed. name takes letters, digits and _. mapper defaults to keyboard, disabled = true starts the bind off. A bind also has bind:isPressed() and bind:isDisabled().

Every bind shows on the Keys page of /jcks. When the admin picks another key there, the bind switches for every player at once, also for players who rebound it before. setting = 'key' follows a key field of your own registered settings instead, see Script settings. bind:getKey() returns the key the player really uses, bind:getConfiguredKey() the one set by the server. jcks.keybind.valid(key) checks a key name, jcks.keybind.list is the list of valid key names.

stream (client)

lua
local model = jcks.stream.model('prop_tool_box_04', 5000)
if not model then return end
local obj = CreateObject(model, coords.x, coords.y, coords.z, true, true, false)
jcks.stream.release('model', model)

Functions: model, animDict, animSet, ptfx, textureDict, weapon, scaleform, audioBank. Each returns the loaded value, or nil after the timeout (default 10000 ms) or for an invalid name, and never throws. model(name, timeout, kind) with kind ped, vehicle or object also refuses a model of another kind. stream.release(kind, value) frees it again.

points (client)

lua
local point = jcks.points.new({
    coords = vec3(441.2, -981.9, 30.7),
    distance = 3.0,
    onEnter = function(self) end,
    onExit = function(self) end,
    nearby = function(self) end,
})
point:remove()

Points sit in a 128 m grid, so only points near the player are checked. The check runs every 500 ms, 200 ms while inside a point. nearby runs every frame, only while the player is inside. Each point has isInside, currentDistance and isClosest. An inside function is treated as nearby. jcks.points.getAll() and jcks.points.getNearby() return the points of your resource.

A point can carry a key prompt:

lua
jcks.points.new({
    coords = vec3(441.2, -981.9, 30.7),
    distance = 2.0,
    interact = {
        key = 'E',
        label = 'Open the armory',
        icon = 'shield-halved',
        canInteract = function(self) return LocalPlayer.state.onDuty end,
        onSelect = function(self) end,
    },
})

While the player is inside, the text UI shows [E] Open the armory, only for the closest point. Instead of onSelect the prompt takes event (local event, gets the point) or serverEvent with args. The key is a jcks.keybind, so admins change it in /jcks, Keys and players in the GTA key bindings. key must be in jcks.keybind.list and label is required, otherwise points.new raises an error. A serverEvent handler must still check distance, job and cooldown on the server.

zones (client)

lua
jcks.zones.sphere({ coords = vec3(0.0, 0.0, 0.0), radius = 4.0, onEnter = fn, onExit = fn, inside = fn })
jcks.zones.box({ coords = vec3(0.0, 0.0, 0.0), size = vec3(6.0, 4.0, 3.0), rotation = 90.0, onEnter = fn })
jcks.zones.poly({ points = { vec3(0.0, 0.0, 0.0), vec3(5.0, 0.0, 0.0), vec3(0.0, 5.0, 0.0) }, thickness = 6.0, onEnter = fn })

Same grid as points. The check runs every 400 ms, 150 ms while inside a zone. inside runs every frame only while inside. zone:remove() triggers onExit if needed. debug = true draws the outline within 100 m, green while the player is inside. jcks.zones.getAll() returns the zones of your resource.

closest (client)

lua
local vehicle, distance = jcks.closest.vehicle(nil, 5.0)
local playerId, ped, distance = jcks.closest.player(nil, 3.0)
local list = jcks.closest.players(coords, 10.0)
Function Arguments
vehicle coords, maxDistance, includeOwn, filter
ped coords, maxDistance, filter (NPCs only)
object coords, maxDistance, filter
player coords, maxDistance, includeSelf, filter
players coords, maxDistance, includeSelf, sorted by distance
vehicles, peds, objects Same as the single versions. Return every match within maxDistance (default 10 m) as { entity, distance }, nearest first.

coords defaults to the player.

wait (client and server)

lua
local entity = jcks.wait(function()
    local e = NetworkGetEntityFromNetworkId(netId)
    return e ~= 0 and e or nil
end, 3000, 50)

jcks.wait(check, timeout, interval) calls check until it returns something other than nil or false and returns that value. On timeout it returns nil, 'timeout'. timeout defaults to 5000 ms, false waits forever. interval is the Wait between checks, default 0.

command (server)

lua
jcks.command({ 'givecar', 'gc' }, {
    help = 'Give a vehicle to a player',
    permission = 'jcks.admin',
    params = {
        { name = 'target', type = 'player', help = 'Server id' },
        { name = 'model', type = 'string' },
        { name = 'note', type = 'rest', optional = true },
    },
}, function(src, args)
    print(args.target, args.model, args.note)
end)

permission is an ACE, a jcks_bridge permission or a function (src) -> boolean. The console always passes. Param types: string, number, player (an online server id), rest (the rest of the line). A missing or wrong value answers with the usage line, denied = 'Text' replaces the reply for players without the permission. The handler gets src, args, raw. Chat suggestions are sent to everyone online and to players who join later.

vehicle (client)

lua
local props = jcks.vehicle.getProps(vehicle)
jcks.vehicle.setProps(vehicle, props)

setProps on a networked vehicle only works for the client that owns it and returns false otherwise. Vehicles that are not networked are never checked. Pass true as the third argument to skip the check.

Setting props right after a server spawn often fails because the owner can change within a tick. Use the server export ApplyVehicleProps instead, see API. The owner check runs on the server, so a player cannot clear props of a vehicle they do not own.

clipboard (client)

lua
jcks.clipboard('ABC 123')

screen (client)

Only one full screen JCKS window is open at a time. Claim the screen when your window opens and release it when it closes. When another resource claims it, your close function runs.

lua
jcks.screen.claim('admin', Ui.Close)
jcks.screen.release('admin')
local mine = jcks.screen.owns('admin')

Claims of the same resource never close each other. Panels, the theme market and the player and notification settings of jcks_lib claim the screen too.

locale (client and server)

lua
local texts = jcks.locale.load('sk')

jcks.locale.load(lang, resource?) merges defaults/locales/en.json, locales/en.json, defaults/locales/<lang>.json and locales/<lang>.json of the resource, in that order, and skips empty texts. It returns nil for a language without files. jcks.locale.missing(lang, resource?) lists the keys your own locales/<lang>.json lacks. Add 'locales/*.json' and 'defaults/locales/*.json' to files so clients can read them.

settings and theme

jcks.settings registers your resource settings in /jcks and reads them back, see Script settings. jcks.theme validates theme tables, see Themes.