Front-End utilities that facilitate add-ons development for FiveM.
Using npm
:
npm install @nuxtlab/utils
Using pnpm
:
pnpm install @nuxtlab/utils
Using yarn
:
yarn add @nuxtlab/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 isBrowser = isEnvBrowser()
console.log(isBrowser) // returns true if the page developed is open in the browser.
- Allows you to send requests to the client side.
fetchNui(eventName: string, data: object): any;
- Usage
// import
fetchNui('updateName', {
name: 'Mark Edward'
})
.then((data) => {
console.log(data) // prints if a return was provided by the game.
})
.catch((error) => {
console.log(error)
})
- Allows you to listen to nui callbacks.
useNuiEvent(handler: (event: { action: string, data?: object }) => void): void;
- Usage
// import
useNuiEvent((event) => {
console.log(event) // prints the event.
})
- Simulates sending a callback by the client.
sendDebugEvent(name: string, data?: object): void;
- Usage
// import
sendDebugEvent('updateName', {
name: 'Mark Edward'
})
Join our Discord Server for updates, support and special discounts!