Skip to content

kibook/callbacks

Repository files navigation

callbacks

Network callbacks for FiveM and RedM, allowing data to be sent between server and client more conveniently and even in a synchronous manner.

Usage

Server callbacks

-- server.lua
exports.callbacks:registerServerCallback("getPlayers", function(source)
  return GetPlayers()
end)

Asynchronous

-- client.lua
exports.callbacks:triggerServerCallback("getPlayers", function(players)
	print(#players)
end)

Synchronous

-- client.lua
local players = exports.callbacks:awaitServerCallback("getPlayers")
print(#players)

Promise-based

-- client.lua
exports.callbacks:deferServerCallback("getPlayers"):next(function(players)
	print(#players)
end)

Client callbacks

-- client.lua
exports.callbacks:registerClientCallback("getCoords", function()
  return GetEntityCoords(PlayerPedId())
end)

Asynchronous

-- server.lua
exports.callbacks:triggerClientCallback("getCoords", 1, function(coords)
	print(coords)
end)

Synchronous

-- server.lua
local coords = exports.callbacks:awaitClientCallback("getCoords", 1)
print(coords)

Promise-based

-- server.lua
exports.callbacks:deferClientCallback("getCoords", 1):next(function(coords)
	print(coords)
end)

About

Network callbacks library for FiveM and RedM

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published