Sign in to follow this  
Matix8981

Problem script JS

Recommended Posts

My function DBSelect

function DBSelect(query) {
    if(query == undefined) {
        console.log("Not definied query");
    } else {
        handler.query(query, function(error, result) {
            if(error) {
                console.log("Error " + error);
                throw error;
            }
            return result;
        });
    }
}

And whitelist script

"use strict"
const mysql = require("./database");

mp.events.add("playerJoin", function(player) {
    const check = mysql.DBSelect("SELECT * FROM whitelist WHERE socialID='" + player + "';");
    if(check == 0) {
        player.kick("Kick reason");
        console.log("sadsad");
    }
});

Console dont show any errors, in join in server and dont kick me

Edited by Matix8981

Share this post


Link to post
Share on other sites

That should work...

// Connection file
var mysql = require('mysql');
module.exports = {
    Handle: null,
    Connect: function(callback) {
        this.Handle = mysql.createConnection({
            host     : 'your_host',
            user     : 'your_user',
            password : 'your_pass',
            database : 'your_database'
        });
        this.Handle.connect(function(e) {
            if ( !e ) { callback(); }
            else console.log ("Error in Database " + e);
         });        
    }
};

// White list file
var db = require("./database");
mp.events.add("playerJoin", (player) => {
        db.Handle.query("SELECT * FROM whitelist WHERE socialID = ?", [player.socialClub], function(e, result) {
        if (!result.length){
            player.kick("Not in whitelist.");
        }else{
            // In Whitelist :)
        }
});

But instead of using the social club, I recommend creating a login with a unique user ID. Players with pirate gta do not have the socialClub! Sorry for my English, I'm Brazilian.

Edited by LeozinH1
  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.