Adir Posted April 9, 2022 Posted April 9, 2022 Hello! I'm invoking an event on the server from the client when pressing C on the keyboard. Then on the server I set a SharedData value for the player entity that invoked the event. Then on the client side, I listen for the data change like this: Events.AddDataHandler("isCrouched", HandleCrouch); I noticed, however, that the the isCrouched data handler triggered on all of the clients, even those who didn't press C to crouch. So I wondered whether it's necessary to check in the data handler whether the client is the entity the data is changed for. private void HandleCrouch(Entity entity, object arg, object oldArg) { if (entity.Type == Type.Player) { Player player = (Player)entity; // Check if player who this data has changed for is not the local player. // If not the local player, return. if (player != Player.LocalPlayer) return; bool crouch = (bool)arg; if (crouch) { player.SetMovementClipset(movementClipSet, clipSetSwitchTime); player.SetStrafeClipset(strafeClipSet); return; } player.ResetMovementClipset(clipSetSwitchTime); player.ResetStrafeClipset(); } } Crouching works whether I have that check in there, or not, and that's what confuses me. This should set the clipsets for the entity on client side for all clients. But it still sets the clipsets even if I make sure to run this code only on the local player. I printed a chat message when the DataHandler is invoked, to make sure: Local player's view: Remote player's view:
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now