Skip to content

Work in progress

This page is incomplete and work in progress. This will be expanded in the future.
Reason: Because of time restraint we couldn't add all the details we wanted for now.

Callback system

We've written our own callback system. We know that other network callback systems exist like qb, esx or ox but we weren't sure it would work with TypeScript so just to be sure we've written one in TypeScript.

Through the CoreObject.Functions you can call the following callback function.

CreateCallback

Register a callback.

Returns: void

Arguments and Examples

Argument Type Description
name string The callback name.
cb EventCallback The callback that gets triggered when your callback event gets called.

We didn't heavily test this in Lua but our short tests say that it should work.

-- Get core object
local CoreObject = export["rn-bridge"]:GetCoreObject()

CoreObject.Functions.CreateCallback("CallbackName", function(src, arg1, arg2)
  -- Your code here, you can return values by just using return
  return true
end)

// Get core object
const CoreObject = export["rn-bridge"].GetCoreObject()

CoreObject.Functions.CreateCallback("CallbackName", (src, arg1, arg2) => {
  // Your code here, you can return values by just using return
  return true
})
import type { BridgeExport } from "@rn/lib_server";

// Get core object
const CoreObject = (export["rn-bridge"] as BridgeExport).GetCoreObject()

CoreObject.Functions.CreateCallback("CallbackName", (src: number, arg1: any, arg2: any) => {
  // Your code here, you can return values by just using return
  return true
})
Argument Type Description
name string The callback name.
cb EventCallback The callback that gets triggered when your callback event gets called.

We didn't heavily test this in Lua but our short tests say that it should work.

-- Get core object
local CoreObject = export["rn-bridge"]:GetCoreObject()

CoreObject.Functions.CreateCallback("CallbackName", function(arg1, arg2)
  -- Your code here, you can return values by just using return
  return true
end)

// Get core object
const CoreObject = export["rn-bridge"].GetCoreObject()

CoreObject.Functions.CreateCallback("CallbackName", (arg1, arg2) => {
  // Your code here, you can return values by just using return
  return true
})
import type { BridgeExport } from "@rn/lib_server";

// Get core object
const CoreObject = (export["rn-bridge"] as BridgeExport).GetCoreObject()

CoreObject.Functions.CreateCallback("CallbackName", (arg1: any, arg2: any) => {
  // Your code here, you can return values by just using return
  return true
})

TriggerClientCallback

Trigger a client callback and await a result.

Returns: Promise<any>

Arguments and Examples

Argument Type Description
name string The callback name.
src number The server id of the player to run the callback on.
...args any[] Arguments passed to the callback.
-- Get core object
local CoreObject = export["rn-bridge"]:GetCoreObject()

local result = CoreObject.Functions.TriggerClientCallback("CallbackName", source, "arg1", "arg2")
print(result)
// Get core object
const CoreObject = export["rn-bridge"].GetCoreObject()

const result = await CoreObject.Functions.TriggerClientCallback("CallbackName", source, "arg1", "arg2")
console.log(result)
import type { BridgeExport } from "@rn/lib_server";

// Get core object
const CoreObject = (export["rn-bridge"] as BridgeExport).GetCoreObject()

const result = await CoreObject.Functions.TriggerClientCallback("CallbackName", source, "arg1", "arg2")
console.log(result)

TriggerServerCallback

Trigger a server callback and await a result.

Returns: Promise<any>

Arguments and Examples

Argument Type Description
name string The callback name.
...args any[] Arguments passed to the callback.
-- Get core object
local CoreObject = export["rn-bridge"]:GetCoreObject()

local result = CoreObject.Functions.TriggerServerCallback("CallbackName", "arg1", "arg2")
print(result)
// Get core object
const CoreObject = export["rn-bridge"].GetCoreObject()

const result = await CoreObject.Functions.TriggerServerCallback("CallbackName", "arg1", "arg2")
console.log(result)
import type { BridgeExport } from "@rn/lib_client";

// Get core object
const CoreObject = (export["rn-bridge"] as BridgeExport).GetCoreObject()

const result = await CoreObject.Functions.TriggerServerCallback("CallbackName", "arg1", "arg2")
console.log(result)

TriggerCallback

Trigger a local callback directly (no networking). Returns null if the callback does not exist.

Returns: any | Promise<any> | null

Arguments and Examples

Argument Type Description
name string The callback name.
src number The server id of the player (passed to the callback).
...args any[] Arguments passed to the callback.
-- Get core object
local CoreObject = export["rn-bridge"]:GetCoreObject()

local result = CoreObject.Functions.TriggerCallback("CallbackName", source, "arg1", "arg2")
print(result)
// Get core object
const CoreObject = export["rn-bridge"].GetCoreObject()

const result = CoreObject.Functions.TriggerCallback("CallbackName", source, "arg1", "arg2")
console.log(result)
import type { BridgeExport } from "@rn/lib_server";

// Get core object
const CoreObject = (export["rn-bridge"] as BridgeExport).GetCoreObject()

const result = CoreObject.Functions.TriggerCallback("CallbackName", source, "arg1", "arg2")
console.log(result)
Argument Type Description
name string The callback name.
...args any[] Arguments passed to the callback.
-- Get core object
local CoreObject = export["rn-bridge"]:GetCoreObject()

local result = CoreObject.Functions.TriggerCallback("CallbackName", "arg1", "arg2")
print(result)
// Get core object
const CoreObject = export["rn-bridge"].GetCoreObject()

const result = CoreObject.Functions.TriggerCallback("CallbackName", "arg1", "arg2")
console.log(result)
import type { BridgeExport } from "@rn/lib_client";

// Get core object
const CoreObject = (export["rn-bridge"] as BridgeExport).GetCoreObject()

const result = CoreObject.Functions.TriggerCallback("CallbackName", "arg1", "arg2")
console.log(result)