Jump to content

console output [object Object]


Recommended Posts

Posted (edited)

Hello everyone.

I'm facing a issue wich i can't solve, thats why I'm asking you if anyone could help me.

I'm trying to write a login/register script

 

Client:

Spoiler
mp.events.add('loginInformationToServer', (usernamepassword=> {
    mp.events.callRemote('OnPlayerLoginAttempt'usernamepassword);
});
 
mp.events.add('registerInformationToServer', (usernamepassword=> {
    mp.events.callRemote('OnPlayerRegisterAttempt'usernamepassword);
});

 

Server

Spoiler
mp.events.add("OnPlayerLoginAttempt", (usernamepassword=> {
    console.log("0" + username);
 
    var spielerTitel = String(username);
 
    console.log("1" + spielerTitel);
 
    var spielerName = JSON.stringify(username);
    console.log("2" + spielerName);
    
    console.log("Username: " + spielerName , "Passwort: " + password);
 
});

 

no matter what i do, the output is always like this:

IJzqIj6.png

 

as u can see, i tryed to use the String option aswell as JSON.stringify

 

 

Edited by Vrael
Posted (edited)

you dont need to stringfy strings or cast  string

just send your login information from html page to clientside => mp.trigger("OnPlayerLoginAttempt", username, password); //username and password are strings

=>> and from clientside to server

And try to don't paste. Write code by your hand to understand it

Edited by mDenis16
Posted (edited)
vor 1 Stunde schrieb mDenis16:

you dont need to stringfy strings or cast  string

just send your login information from html page to clientside => mp.trigger("OnPlayerLoginAttempt", username, password); //username and password are strings

=>> and from clientside to server

And try to don't paste. Write code by your hand to understand it

 

i already send the login information from html to clientside

$('#loginButton').click(() => {
 
    $('.alert').remove(); //Remove any alerts when we attempt to login/register
    mp.trigger('loginInformationToServer'$('#loginUsernameText').val(), $('#loginPasswordText').val());
});

and yes you're right, I should write every code myself but this login script is good to understand how I can send things from html to client then to server and back to client.

I understand most of it but there are still some things like this wich i dont get.

 

Edited by Vrael
Posted
mp.events.add("OnPlayerLoginAttempt", (usernamepassword=> {
    console.log(`Username: ${username} and password: ${password}`);
 
}); serverside
mp.events.add('loginInformationToServer', (usernamepassword=> {
    mp.events.callRemote('OnPlayerLoginAttempt'usernamepassword);
}); clientside
 
 
 
js html 
$('#loginButton').click(() => {
 
    $('.alert').remove(); 
    mp.trigger('loginInformationToServer'$('#loginUsernameText').val(), $('#loginPasswordText').val());
});

thats should work

Posted (edited)

It doesn’t make sense your username is an object, isn’t the first parameter of the event supposed to be a player object, so it’d be “OnPlayerLoginAttempt” (player, username, password)

[I barely looked over the code sonce I’m at work, it might be your other event idk]

pretty sure you’ve had it right, you just didn’t consider the first parameter being a player object. If stringifying the object gives you {} then most likely its a ragemp object (aka the player)

Edited by MrPancakers
  • Like 1
Posted

MrPancakers is correct, you're referring to the player object in the first parameter. The password param is giving you the username in your case and that's crystal clear in your console output tests.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...