Network callbacks for FiveM and RedM, allowing data to be sent between server and client more conveniently and even in a synchronous manner.
-- server.lua
exports.callbacks:registerServerCallback("getPlayers", function(source)
return GetPlayers()
end)
-- client.lua
exports.callbacks:triggerServerCallback("getPlayers", function(players)
print(#players)
end)
-- client.lua
local players = exports.callbacks:awaitServerCallback("getPlayers")
print(#players)
-- client.lua
exports.callbacks:deferServerCallback("getPlayers"):next(function(players)
print(#players)
end)
-- client.lua
exports.callbacks:registerClientCallback("getCoords", function()
return GetEntityCoords(PlayerPedId())
end)
-- server.lua
exports.callbacks:triggerClientCallback("getCoords", 1, function(coords)
print(coords)
end)
-- server.lua
local coords = exports.callbacks:awaitClientCallback("getCoords", 1)
print(coords)
-- server.lua
exports.callbacks:deferClientCallback("getCoords", 1):next(function(coords)
print(coords)
end)