Callbacks

Ask the server a question from the client — and get an answer back. The backbone of most gameplay scripts.

Callbacks run inside YOUR resource (via the @echo_core/import.lua import), so the blocking await form never causes a cross-resource hang. Transport is automatic — a request goes out on a per-name event so only the resource that registered a callback ever receives it.

Register a callback

On the server, register a handler others can call. The handler receives the player source first, then any arguments, and returns one or more values.

Echo.RegisterCallback('myjob:canClockIn', function(source, stationId)
    local data = Echo.GetPlayerData(source)
    return data and data.job and data.job.name == 'mechanic'
end)

Call it from the client

From the client, call it in one of two styles — blocking (simplest) or async with a callback.

-- blocking: returns the value(s) the server returned
local allowed = Echo.AwaitCallback('myjob:canClockIn', stationId)
if allowed then ... end

-- async: your function receives the result
Echo.TriggerCallback('myjob:canClockIn', function(allowed)
    if allowed then ... end
end, stationId)
💡 Why await is safe here

Because the import runs inside your resource, Echo.AwaitCallback yields your own thread — not echo_core's — so it blocks cleanly and returns the result.

Server to client

The reverse direction works too — register the callback on the CLIENT, and trigger it from the SERVER for a specific player.

-- client
Echo.RegisterCallback('myjob:getLocalThing', function()
    return GetEntityHealth(PlayerPedId())
end)

-- server
local hp = Echo.AwaitClientCallback('myjob:getLocalThing', source)

All callback functions

Function Side Description
Echo.RegisterCallback(name, fn) client & server Register a handler the other side can call. Server: fn(source, ...). Client: fn(...).
Echo.TriggerCallback(name, cb, ...) client Call a server callback; cb(...) receives the result.
Echo.AwaitCallback(name, ...) client Call a server callback and block, returning the result.
Echo.TriggerClientCallback(name, source, cb, ...) server Call a client callback; cb(...) receives the result.
Echo.AwaitClientCallback(name, source, ...) server Call a client callback and block, returning the result.