Skip to main content

Exports

Server & Client (Shared)

Adding new events

Add single local event

exports["fivem-rpc"]:on(eventName, cb)
  • eventName: string
  • cb: EventCallback

Add single global event

exports["fivem-rpc"]:onGlobal(eventName, cb)
  • eventName: string
  • cb: EventCallback

Add many local events (in key pair table)

exports["fivem-rpc"]:onMany(e)
  • e: Record<string, EventCallback>

Add many global events (in key pair table)

exports["fivem-rpc"]:onGlobalMany(e)
  • e: Record<string, EventCallback>

Examples

exports['fivem-rpc']:on('onPlayerLogin', function(playerSource)
print(playerSource)
end)

Triggering events

Triggering local event

exports["fivem-rpc"]:trigger(eventName, args?)
  • eventName: string
  • args?: any

Triggering global event

exports["fivem-rpc"]:triggerGlobal(eventName, args?)
  • eventName: string
  • args?: any

Examples

exports["fivem-rpc"]:trigger("onPlayerLogin", 2)

Creating new listeners

Registering locally

exports["fivem-rpc"]:register(eventName, cb)
  • eventName: string
  • cb: RemoteCallback

Registering globally

exports["fivem-rpc"]:registerGlobal(eventName, cb)
  • eventName: string
  • cb: RemoteCallback

Examples

Registering the listener on clientside
exports["fivem-rpc"]:register("isPlayerSwimming", function()
return IsPedSwimming(PlayerPedId())
end)
Calling the event from server
local isSwimming = exports["fivem-rpc"]:callClient(source, "isPlayerSwimming")
print(isSwimming)

Calling listeners

Server only

  • callClient(source, eventName, args)
  • callGlobalClient(source, eventName, args)

Client only

  • callServer(eventName, args)
  • callGlobalServer(eventName, args)

Shared

  • call(eventName, args)
  • callGlobal(eventName, args)

Browser / NUI / CEF - RPC

info

Require/import the browser.js(or .ts) file into your frontend.

Events

- triggerGlobalServer(eventName: string, args?: any)
- triggerGlobalClient(eventName: string, args?: any)
- callGlobalServer<T>(eventName: string, args?:any): Promise<T>
- callGlobalClient<T>(eventName: string, args?:any): Promise<T>