ygtdev / fivem-utils

Frontend tools to write plugin development easier for FiveM.

Home Page:https://www.npmjs.com/package/fivem-utils

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Description

šŸ§° Frontend tools to write plugin development easier for FiveM.

Installation

Using npm:

npm install fivem-utils

Using yarn:

yarn add fivem-utils

Example Uses

You can use the examples in the subsection below to use the tools.

isEnvBrowser

  • 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.

useNuiEvent

  • 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.
});

fetchNui

  • 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);
  });

debugData

  • Simulates sending a callback by the client.
debugData(data: object, delayTime: number): void;
  • Usage
// import

debugData(
  {
    action: "test",
    data: {
      name: "Mark Edward",
    },
  },
  500
);

Discord Server

License

MIT

About

Frontend tools to write plugin development easier for FiveM.

https://www.npmjs.com/package/fivem-utils

License:MIT License