Skip to main content

🧭 About

Github

https://github.com/freamee/fivem-rpc

About

Easy server-client communication (ping-pong) between environments.

  • You can easily trigger serverside from your NUI
  • You can create a request to serverside, which will send back the response from server

Very basic example use case:

Authentication system

FRONTEND, Calling the server
import rpc from "browser.ts"

rpc.callGlobalServer("auth:sendLoginRequest", {
username: "freamee",
password: "password"
}).then(res => {
y console.log(JSON.stringify(res));
// {
// charId = 1
// charName = "Ray Shelby",
// },
// {
// charId = 2,
// charName = "Ray Washington"
// }
});
Serverside, register the event and do the auth, then return a response
exports["fivem-rpc"]:registerGlobal("auth:sendLoginRequest", function(d)
local username = d.username
local password = d.password

-- Do the authentication methods

-- Return a value, maybe return his character names and ids if you have a multiple character system.
return {
{
charId = 1
charName = "Ray Shelby",
},
{
charId = 2,
charName = "Ray Washington"
}
}
end)