Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 59 additions & 19 deletions EXILED/Exiled.API/Features/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,8 @@ public ScpSpawnPreferences.SpawnPreferences ScpPreferences
/// </summary>
public Vector3 Scale
{
get => ReferenceHub.transform.localScale;
set => SetScale(value, List);
get => Role is FpcRole fpcRole ? fpcRole.FirstPersonController.FpcModule.Motor.ScaleController.Scale : Vector3.one;
set => SetScale(value);
}

/// <summary>
Expand Down Expand Up @@ -2064,18 +2064,52 @@ public void Disconnect(string reason = null) =>
/// Sets the scale of a player on the server side.
/// </summary>
/// <param name="scale">The scale to set.</param>
/// <param name="viewers">Who should see the updated scale.</param>
public void SetScale(Vector3 scale, IEnumerable<Player> viewers)
public void SetScale(Vector3 scale)
{
if (scale == Scale)
return;
try
{
if (Role is not FpcRole fpcRole)
{
Log.Error($"{nameof(SetScale)} error: {nameof(Role)} {Role} is not a {nameof(FpcRole)}, cannot set scale.");
return;
}

fpcRole.FirstPersonController.FpcModule.Motor.ScaleController.Scale = scale;
}
catch (Exception exception)
{
Log.Error($"{nameof(SetScale)} error: {exception}");
}
}

/// <summary>
/// Sets the scale of a player on the server side.
/// </summary>
/// <param name="scale">The scale to set.</param>
/// <param name="viewers">Who should see the updated scale.</param>
public void SetScale(Vector3 scale, IEnumerable<Player> viewers) => SetScale(scale, viewers.Select(p => p.ReferenceHub));

/// <summary>
/// Sets the scale of a player on the server side.
/// </summary>
/// <param name="scale">The scale to set.</param>
/// <param name="viewers">Who should see the updated scale.</param>
public void SetScale(Vector3 scale, IEnumerable<ReferenceHub> viewers)
{
try
{
ReferenceHub.transform.localScale = scale;
if (Role is not FpcRole fpcRole)
{
Log.Error($"{nameof(SetScale)} error: {nameof(Role)} {Role} is not a {nameof(FpcRole)}, cannot set scale.");
return;
}

if (fpcRole.FirstPersonController.FpcModule.Motor.ScaleController.Scale == scale)
return;

foreach (Player target in viewers)
Server.SendSpawnMessage?.Invoke(null, new object[] { NetworkIdentity, target.Connection });
fpcRole.FirstPersonController.FpcModule.Motor.ScaleController._scale = scale;
ReferenceHub.transform.localScale = scale;
new SyncedScaleMessages.ScaleMessage(scale, ReferenceHub).SendToHubsConditionally(h => viewers.Contains(h));
}
catch (Exception exception)
{
Expand All @@ -2088,22 +2122,28 @@ public void SetScale(Vector3 scale, IEnumerable<Player> viewers)
/// </summary>
/// <param name="fakeScale">The scale to set to.</param>
/// <param name="viewers">Who should see the fake scale.</param>
public void SetFakeScale(Vector3 fakeScale, IEnumerable<Player> viewers)
{
Vector3 currentScale = Scale;
public void SetFakeScale(Vector3 fakeScale, IEnumerable<Player> viewers) => SetFakeScale(fakeScale, viewers.Select(p => p.ReferenceHub));

/// <summary>
/// Sets the scale of the player for other players.
/// </summary>
/// <param name="fakeScale">The scale to set to.</param>
/// <param name="viewers">Who should see the fake scale.</param>
public void SetFakeScale(Vector3 fakeScale, IEnumerable<ReferenceHub> viewers)
{
try
{
ReferenceHub.transform.localScale = fakeScale;

foreach (Player target in viewers)
Server.SendSpawnMessage.Invoke(null, new object[] { NetworkIdentity, target.Connection });
if (Role is not FpcRole fpcRole)
{
Log.Error($"{nameof(SetFakeScale)} error: {nameof(Role)} {Role} is not a {nameof(FpcRole)}, cannot set fake scale.");
return;
}

ReferenceHub.transform.localScale = currentScale;
new SyncedScaleMessages.ScaleMessage(fakeScale, ReferenceHub).SendToHubsConditionally(h => viewers.Contains(h));
}
catch (Exception ex)
catch (Exception exception)
{
Log.Error($"{nameof(SetFakeScale)}: {ex}");
Log.Error($"{nameof(SetFakeScale)} error: {exception}");
}
}

Expand Down
Loading