Koja Scripts
KOJA-LIB

Callbacks

koja-lib provides a callback system that lets client scripts request data from the server and vice versa.

Callbacks

koja-lib provides a callback system that lets client scripts request data from the server and vice versa.

TriggerServerCallback

Trigger a callback registered on the server and receive the result asynchronously.

KOJA.Client.TriggerServerCallback(key, payload, callback)
ParameterTypeDescription
keystringCallback identifier
payloadanyData sent to the server
callbackfunctionCalled with the server's response

Example

KOJA.Client.TriggerServerCallback('myScript:getPlayerData', nil, function(data)
    print('Player name:', data.name)
    print('Money:', data.money)
end)

RegisterClientCallback

Register a callback on the client that the server can trigger.

KOJA.Client.RegisterClientCallback(key, handler)
ParameterTypeDescription
keystringCallback identifier
handlerfunction(payload, cb)Handler function — call cb(result) to respond

Example

KOJA.Client.RegisterClientCallback('myScript:getLocalPos', function(payload, cb)
    local coords = GetEntityCoords(PlayerPedId())
    cb({ x = coords.x, y = coords.y, z = coords.z })
end)

Registering a Server Callback

On the server side you register the handler:

KOJA.Server.RegisterServerCallback('myScript:getPlayerData', function(source, payload, cb)
    local name = KOJA.Server.GetPlayerName(source)
    local money = KOJA.Server.getMoney(source, 'cash')
    cb({ name = name, money = money })
end)

See Server Callbacks for full server-side documentation.

  • Inventory — Client-side inventory functions let you check what items the local player has without a server round-trip.
  • DUI — DUI (Dynamic UI) allows you to render a web page as a texture on any in-game surface — screens, billboards, laptops, phones, etc.
  • Money — Retrieve the local player's money balance from the client side via a server callback.
  • Keybinds — Register persistent key bindings that players can rebind in the GTA V settings menu.
  • Notifications — koja-lib provides two notification interfaces: SendNotify (routes through the configured backend) and LibNotify (built-in koja-lib notification).
  • Player — Functions for reading the local player's data on the client side.
  • Client API — back to the section overview