Sign in to follow this  
Kar

Clientside p2p variable sync.

Recommended Posts

Okay, so I noticed when doing

 

Quote

mp.players.local.shared = {};

Idk if its because its an object, it doesn't get synced. But doing

Quote

mp.players.local.variable = true;

Gets synced between players fine.

Thus, if I want to do

Quote

mp.players.local.shared = {};

mp.players.local.shared.isTyping = true;

This won't work when looping through players for example, 

Quote

mp.events.add({
    'render' : (nametags) => {
        nametags.forEach( (nametag) => {
            let [player, x, y, distance] = nametag;
            
            if(player.shared.isTyping) {
                //
            }
        }
    }
});

Will throw an error on the if statement line.

 

Can we have variable objects and it's entries (keys & values) synced between players? Or is this too much of a bottleneck?

Share this post


Link to post
Share on other sites

Are you sure "mp.players.local.variable = true;" actually gets synced (automatically)? If you want to get it synced, you should use shared data (get/setVariable).

Share this post


Link to post
Share on other sites
Posted (edited)

It appeared to work, when I print another players' object, I can see extra variables that I added client side. Maybe its unintended situation...

So let's say for example, I want to p2p sync when a player is typing... I have to send that data to the server and then ragemp syncs that everytime? I just see that getting effy with many players... but I guess I'll take that path.
 

Edited by Kar

Share this post


Link to post
Share on other sites

No thats the way. Nothing else would the rage server do. It would send it from the client you were changing the variable to the server and the server would share the change of the client with all connected players.

Just make an event on the server you call from a client changing a value like

mp.events.add("changeData", function(thisPlayer, thisData, thisValue) {
  thisPlayer.setVariable(thisData, thisValue);
});

and the client which starts typing will do something like:

mp.events.callRemote("changeData", "isTyping", true);

when he starts typing.

Share this post


Link to post
Share on other sites

I understand, I know how to do the stuff, I already do it which is why I am suggesting or asking about this. Also using that for something like typing is too slow (client - server - clients). Try the stuff pls and understand why I am complaining.

 

Variables seem to sync between clients anyway, intendedly or unintendedly. You can literally just do `mp.players.local.isTyping` and then check that whereever against other players.

Share this post


Link to post
Share on other sites
5 hours ago, Kar said:

You can literally just do `mp.players.local.isTyping` and then check that whereever against other players.

It's just a random match, the client really won't do that.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.