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
- on
- onGlobal
- onMany
- onGlobalMany
exports['fivem-rpc']:on('onPlayerLogin', function(playerSource)
print(playerSource)
end)
exports['fivem-rpc']:onGlobal('onPlayerLogin', function(playerSource)
print(playerSource)
end)
exports['fivem-rpc']:onMany({
['onPlayerLogin'] = function(playerSource)
print(playerSource)
end,
['onPlayerLogout'] = function(playerSource)
print(playerSource)
end
})
exports['fivem-rpc']:onGlobalMany({
['onPlayerLogin'] = function(playerSource)
print(playerSource)
end,
['onPlayerLogout'] = 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
- trigger
- triggerGlobal
exports["fivem-rpc"]:trigger("onPlayerLogin", 2)
exports["fivem-rpc"]:triggerGlobal("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
- register
- registerGlobal
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)
Registering the listener on clientside
exports["fivem-rpc"]:registerGlobal("isPlayerSwimming", function()
return IsPedSwimming(PlayerPedId())
end)
Calling the event from server
local isSwimming = exports["fivem-rpc"]:callGlobalClient(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>