Jump to content
RAGE Multiplayer Community

How to pass player from client to server while triggering an event


DeadlyHero
 Share

Recommended Posts

I'm trying to pass player object to server while triggering an event and some people told me that is not needed because player is always a first parameter of event callback function

My structure looks like that:

Client:
 

mp.events.add("onPlayerRequestRegister",(username, password, email)=>{
  // hud.destroy();
  //mp.gui.cursor.visible = false;
  const localPlayer = mp.players.local;
  if(!username) return hud.execute(`printError("Please enter your username");`);
  if(!email) return hud.execute(`printError("Please enter your email");`);
  if(!password) return hud.execute(`printError("Please enter your password");`);
  hud.execute(`printError("Player${JSON.stringify(localPlayer)}");`);
  if(username && password && email){
    //trigger on reggister
    const user = {"player": localPlayer, "username": username, "password": password,"email":email} ;
    mp.events.callRemote("onPlayerRequestRegister", JSON.stringify(user));

    //mp.events.callRemote(,username,email,password);
  }
})


Server:
 

mp.events.add("onPlayerRequestRegister", (args)=>{
  console.log("data",args);
})



and console.log("data",args) returns data { customData : {} } which is empty object,

So if somebody can write exact structure for event triggering that would be helpful.
Thanks.

Link to comment
Share on other sites

lol

 

Server:

mp.events.add("onPlayerRequestRegister", (player, args) => {
  console.log(`${player.name} call onPlayerRequestRegister data : ${args}`);
});

if you call the event from the client side, the first argument on the server will always be the player who triggered the event

Edited by kemperrr
Link to comment
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
 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...