Coder Social home page Coder Social logo

avuxdemons / fivem-server-api Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 2.0 27 KB

JavaScript API for getting information about FiveM Server

License: Apache License 2.0

JavaScript 100.00%
fivem fivem-script fivem-server fivemserver nodejs fivem-npm fivem-server-status fivem-servers

fivem-server-api's Introduction

fivem-server-api

Package for getting information about FiveM Server Using API

Installation

Add fivem-server-api to your existing project.

npm i fivem-server-api

Documentation

// Import the Package ( Required )
const FiveM = require("fivem-server-api")

// Options ( Optional )
const options = {
    timeout: 5000, // Default 5000ms / 5 seconds ( Milliseconds )
    errmsg: 'Error Occured', // Default 'Error Occured' ( String )
}

// Create New Object ( Require )
const server = new FiveM.Server('CFX.re URL / IP:PORT', options)
/*  
    The first argument is CFX.re Server URL / Server IP Address ( REQUIRED )
    The second argument is Options                              ( Optional )
    Example : 
      const server = new FiveM.Server('205.178.183.132:50120', options)  ||  Using IP:PORT
      const server = new FiveM.Server('cfx.re/join/my59jq', options)     ||  Using CFX.re Url
      const server = new FiveM.Server('https://cfx.re/join/my59jq')      ||  Using CFX.re Url
*/


// How to use the function

// Promise ( Single Func )
server.getServerStatus().then(data => console.log(data))
server.getPlayers().then(data => console.log(data))

// PromiseAll ( Multiple Func )
Promise.all([server.getServerStatus(), server.getPlayers()]).then(([serverStatus, players]) => {
    console.log(serverStatus);
    console.log(players);
}).catch(error => {
    console.error(error);
});

// Async/Await ( Single Func )
async function fetchServerStatus() {
    const serverStatus = await server.getServerStatus();
    console.log(serverStatus);
}

async function fetchPlayers() {
    const players = await server.getPlayers();
    console.log(players);
}

// Async/Await ( Multiple Func )
async function fetchData() {
    try {
        const [serverStatus, players] = await Promise.all([server.getServerStatus(), server.getPlayers()]);
        console.log(serverStatus);
        console.log(players);
    } catch (error) {
        console.error(error);
    }
}

FUNCTION LIST

FUNCTION DETAIL RESULT
getServer() Get the whole server object (string)
getServerStatus() Server Status (boolean)
getServerName() Get server name (string)
getServerDesc() Get server description (string)
getPlayers() Number of players online (number)
getPlayersAll() List all players (string/array)
getMaxPlayers() Max players that are able to join the server (number)
getResources() Get resource names of all server resources (string/array)
getTags() Get all server tags (string)
getOnesync() See if the server has OneSync enabled (boolean)
getLocale() The language of the server (string)
getGamename() Get the name of the server (string)
getSteamTicket() Is server require Steam ticket (boolean)
getGameBuild() FiveM build version (boolean)
getEnhancedHostSupport() ... (boolean)
getlicenseKeyToken() The license key for the server (string)
getScriptHookAllowed() See if the server supports external mod menus from the client (boolean)

fivem-server-api's People

Contributors

avuxdemons avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.