diff --git a/EXILED/Exiled.API/Features/Player.cs b/EXILED/Exiled.API/Features/Player.cs index 323b4ec463..779982d2fb 100644 --- a/EXILED/Exiled.API/Features/Player.cs +++ b/EXILED/Exiled.API/Features/Player.cs @@ -699,7 +699,7 @@ public ScpSpawnPreferences.SpawnPreferences ScpPreferences public Vector3 Scale { get => ReferenceHub.transform.localScale; - set => SetScale(value, List); + set => SetScale(value); } /// @@ -2065,6 +2065,16 @@ public void Disconnect(string reason = null) => /// public void ResetStamina() => Stamina = StaminaStat.MaxValue; + /// + /// Sets the scale of a player on the server side. + /// + /// The scale to set. + public void SetScale(Vector3 scale) + { + ReferenceHub.transform.localScale = scale; + new SyncedScaleMessages.ScaleMessage(scale, ReferenceHub).SendToAuthenticated(); + } + /// /// Sets the scale of a player on the server side. /// @@ -2072,20 +2082,8 @@ public void Disconnect(string reason = null) => /// Who should see the updated scale. public void SetScale(Vector3 scale, IEnumerable viewers) { - if (scale == Scale) - return; - - try - { - ReferenceHub.transform.localScale = scale; - - foreach (Player target in viewers) - Server.SendSpawnMessage?.Invoke(null, new object[] { NetworkIdentity, target.Connection }); - } - catch (Exception exception) - { - Log.Error($"{nameof(SetScale)} error: {exception}"); - } + ReferenceHub.transform.localScale = scale; + new SyncedScaleMessages.ScaleMessage(scale, ReferenceHub).SendToHubsConditionally(x => x != null && viewers.Contains(Get(x))); } /// @@ -2095,21 +2093,9 @@ public void SetScale(Vector3 scale, IEnumerable viewers) /// Who should see the fake scale. public void SetFakeScale(Vector3 fakeScale, IEnumerable viewers) { - Vector3 currentScale = Scale; - - try - { - ReferenceHub.transform.localScale = fakeScale; - - foreach (Player target in viewers) - Server.SendSpawnMessage.Invoke(null, new object[] { NetworkIdentity, target.Connection }); - - ReferenceHub.transform.localScale = currentScale; - } - catch (Exception ex) - { - Log.Error($"{nameof(SetFakeScale)}: {ex}"); - } + SyncedScaleMessages.ScaleMessage scaleMessage = new(fakeScale, ReferenceHub); + foreach (Player player in viewers) + player.Connection.Send(scaleMessage, 0); } /// diff --git a/EXILED/Exiled.API/Features/Roles/FpcRole.cs b/EXILED/Exiled.API/Features/Roles/FpcRole.cs index d1c0a12591..d54201ff0e 100644 --- a/EXILED/Exiled.API/Features/Roles/FpcRole.cs +++ b/EXILED/Exiled.API/Features/Roles/FpcRole.cs @@ -76,6 +76,15 @@ public Vector3 Gravity set => FirstPersonController.FpcModule.Motor.GravityController.Gravity = value; } + /// + /// Gets or sets the player's scale. + /// + public Vector3 Scale + { + get => FirstPersonController.FpcModule.Motor.ScaleController.Scale; + set => FirstPersonController.FpcModule.Motor.ScaleController.Scale = value; + } + /// /// Gets or sets a value indicating whether if the player should get damage. /// diff --git a/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs b/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs index db5e599cd3..895b483b2e 100644 --- a/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs +++ b/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs @@ -564,7 +564,7 @@ public virtual void AddRole(Player player) Log.Debug($"{Name}: Setting health values."); player.Health = MaxHealth; player.MaxHealth = MaxHealth; - player.Scale = Scale; + Timing.CallDelayed(0.1f, () => player.Scale = Scale); // To fix : remove the delay in 14.1.2 once the crash issue is resolved if (Gravity.HasValue && player.Role is FpcRole fpcRole) fpcRole.Gravity = Gravity.Value; Vector3 position = GetSpawnPosition(); @@ -627,7 +627,6 @@ public virtual void RemoveRole(Player player) TrackedPlayers.Remove(player); player.CustomInfo = string.Empty; player.InfoArea |= PlayerInfoArea.Role | PlayerInfoArea.Nickname; - player.Scale = Vector3.one; if (CustomAbilities is not null) { foreach (CustomAbility ability in CustomAbilities) diff --git a/EXILED/Exiled.Events/Handlers/Internal/Round.cs b/EXILED/Exiled.Events/Handlers/Internal/Round.cs index f81b0886b9..3ce8660bbe 100644 --- a/EXILED/Exiled.Events/Handlers/Internal/Round.cs +++ b/EXILED/Exiled.Events/Handlers/Internal/Round.cs @@ -29,7 +29,10 @@ namespace Exiled.Events.Handlers.Internal using InventorySystem.Items.Usables; using InventorySystem.Items.Usables.Scp244.Hypothermia; using PlayerRoles; + using PlayerRoles.FirstPersonControl; using PlayerRoles.RoleAssign; + using UnityEngine; + using Utils.Networking; using Utils.NonAllocLINQ; /// @@ -114,10 +117,10 @@ public static void OnVerified(VerifiedEventArgs ev) ev.Player.SendFakeSyncVar(room.RoomLightControllerNetIdentity, typeof(RoomLightController), nameof(RoomLightController.NetworkLightsEnabled), false); } - // TODO: Remove if this has been fixed for https://git.scpslgame.com/northwood-qa/scpsl-bug-reporting/-/issues/947 - if (ev.Player.TryGetEffect(out Hypothermia hypothermia)) + // Fix bug that player that Join do not receive information about other players Scale + foreach (Player player in ReferenceHub.AllHubs.Select(Player.Get)) { - hypothermia.SubEffects = hypothermia.SubEffects.Where(x => x.GetType() != typeof(PostProcessSubEffect)).ToArray(); + player.SetFakeScale(player.Scale, new List() { ev.Player }); } }