For the complete documentation index, see llms.txt. This page is also available as Markdown.

Callback

The ak47_lib features a powerful, two-way callback system built on promises. This allows you to easily request data from the Server to the Client, or from the Client to the Server, yielding the thread until a response is received or a timeout occurs.

You can access these functions via the Lib47.Callback namespace.

Client to Server Callbacks

These functions are used when a Client script needs to request data from the Server.

Lib47.Callback.Register (Server-Side)

Registers a server-side callback that can be triggered by clients. Duplicate registrations will output an error to the console to prevent overlapping event handlers.

--- @param name string The unique name of the callback
--- @param cb function The function to execute when called. The first parameter is ALWAYS the player's source.
Lib47.Callback.Register('ak47_lib:server:getPlayerData', function(source, arg1, arg2)
    -- The first argument is automatically the invoking player's server ID
    local player = Lib47.GetPlayer(source)
    local money = Lib47.GetMoney(source, 'cash')
    
    -- You can return a single value, multiple values, or nil
    return money, player.job.name
end)

Lib47.Callback.Await (Client-Side)

Triggers a registered server callback and waits for the response. If the server takes longer than the configured timeout (defaulting to 15 seconds), it will automatically resolve as nil and print a timeout warning.

Server to Client Callbacks

These functions are used when the Server needs to request data from a specific Client (e.g., checking their UI state, getting a waypoint coordinate, or verifying a client-side entity).

Lib47.Callback.Register (Client-Side)

Registers a client-side callback that can be triggered by the server.

Lib47.Callback.Await (Server-Side)

Triggers a registered client callback on a specific player and waits for the response. If the target player doesn't exist or fails to respond within the timeout, it resolves to nil.

Last updated