🧰 Frontend tools to write plugin development easier for FiveM.
Using npm
:
npm install fivem-utils
Using yarn
:
yarn add fivem-utils
You can use the examples in the subsection below to use the tools.
- Checks whether the development environment is a browser.
isEnvBrowser(): boolean;
- Usage
// import
const browser = isEnvBrowser();
console.log(browser); // returns true if the page developed is open in the browser.
- Allows you to listen to nui callbacks.
useNuiEvent(handler: (data: unknown) => void): void;
- Usage
// import
useNuiEvent((event) => {
console.log(event.data); // prints the event data.
});
- Allows you to send requests to the client side.
fetchNui(eventName: string, data: object): any;
- Usage
// import
fetchNui("test", {
name: "Mark Edward",
})
.then((data) => {
console.log(data); // prints if a return was provided by the game.
})
.catch((error) => {
console.log(error);
});
- Simulates sending a callback by the client.
debugData(data: object, delayTime: number): void;
- Usage
// import
debugData(
{
action: "test",
data: {
name: "Mark Edward",
},
},
500
);