MrMexico
MrMexico

Reputation: 21

JSON Variable for a nodejs script

im searching for an idea to fix my problem. First of all, there is a server.exe software, that can load some stuff. But if i change something, it needs a restart, but not, if i use a json file to store account names. Look:

    const allowedPlayers = 

    [

    "Socialclubuser1", 
    "Socialclubuser2", 
    "Socialclubuser3"

    ]

mp.events.add("playerJoin", (player) => {

if (!allowedPlayers.includes(player.socialClub)) {
    player.notify('Youre not whitelisted!');
}

});

mp.events.add("playerJoin", (player) => {

if (!allowedPlayers.includes(player.socialClub)) {

    player.kick('Youre not whitelisted!');    
}

});

i would use account.json, and insert there the stuff but how?

greetings

Upvotes: 1

Views: 48

Answers (1)

xdeepakv
xdeepakv

Reputation: 8125

Create an account.json file and require it using require on start.

// account.json
// ["Socialclubuser1", "Socialclubuser2", "Socialclubuser3"]

const allowedPlayers = require("./account.json");

// rest of the code
mp.events.add("playerJoin", player => {
  if (allowedPlayers.indexOf(player.socialClub) === -1) {
    player.notify("Youre not whitelisted!");
    player.kick("Youre not whitelisted!");
  }
});

Upvotes: 1

Related Questions