npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

discord-fivem-api

v2.0.5

Published

A NodeJS package that helps you to interact with the little FiveM API.

Downloads

812

Readme

GitHub Copilot: Sure, here's an example of how to use the DiscordFivemApi class:

Installation

You can install the discord-fivem-api package using npm:

$ npm install discord-fivem-api
OR 
$ yarn add discord-fivem-api

Usage

To use the DiscordFivemApi class, you first need to import it:

const DiscordFivemApi = require('discord-fivem-api');

Then, you can create a new instance of the class with the desired options:

const options = {
  address: 'localhost',
  port: 30120,
  useStructure: true,
  interval: 5000,
};

const api = new DiscordFivemApi(options, true);

The options object can contain the following properties:

  • address: The IP address or hostname of the FiveM server (required).
  • port: The port number of the FiveM server (default: 30120).
  • useStructure: Whether to use the Player and Server classes from the structures directory (default: true).
  • interval: The interval in milliseconds between updates (default: 2500).

The second argument to the constructor (init) specifies whether to initialize the API immediately (default: false).

Once you have created an instance of the DiscordFivemApi class, you can use its methods to retrieve information about the FiveM server:

api.getStatus()
  .then((status) => console.log(`Server status: ${status}`))
  .catch((err) => console.error(err));

api.getServerData()
  .then((serverData) => console.log(serverData))
  .catch((err) => console.error(err));

api.getServerPlayers()
  .then((players) => console.log(players))
  .catch((err) => console.error(err));

api.getPlayersOnline()
  .then((count) => console.log(`Players online: ${count}`))
  .catch((err) => console.error(err));

api.getMaxPlayers()
  .then((maxPlayers) => console.log(`Max players: ${maxPlayers}`))
  .catch((err) => console.error(err));

The getStatus() method returns a promise that resolves to either 'online' or 'offline'.

The getServerData() method returns a promise that resolves to an object containing information about the FiveM server. If useStructure is true, the object will be an instance of the Server class.

The getServerPlayers() method returns a promise that resolves to an array of objects containing information about the players on the FiveM server. If useStructure is true, the objects will be instances of the Player class.

The getPlayersOnline() method returns a promise that resolves to the number of players currently online.

The getMaxPlayers() method returns a promise that resolves to the maximum number of players allowed on the FiveM server.

You can also listen for events emitted by the DiscordFivemApi instance:

api.on('ready', () => console.log('API initialized'));
api.on('readyPlayers', (players) => console.log(`Players: ${players.length}`));
api.on('readyResources', (resources) => console.log(`Resources: ${resources.length}`));
api.on('playerJoin', (player) => console.log(`${player.name} joined the server`));
api.on('playerLeave', (player) => console.log(`${player.name} left the server`));
api.on('resourceAdd', (resource) => console.log(`Resource added: ${resource}`));
api.on('resourceRemove', (resource) => console.log(`Resource removed: ${resource}`));

The ready event is emitted when the API is initialized.

The readyPlayers event is emitted when the player data is ready.

The readyResources event is emitted when the resource data is ready.

The playerJoin event is emitted when a player joins the server.

The playerLeave event is emitted when a player leaves the server.

The resourceAdd event is emitted when a resource is added to the server.

The resourceRemove event is emitted when a resource is removed from the server.

License

This package is licensed under the MIT License.