Jump to content

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


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:


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");`);
  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.add("onPlayerRequestRegister", (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.

Link to comment
Share on other sites




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

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