Skip to content

Commit

Permalink
Player::FakeScale (#88)
Browse files Browse the repository at this point in the history
* uwu

* FIX

* Set scale

* Consistency

* yep

* vlad suggestions

* vlad 2.0

* that

---------

Co-authored-by: Misaka-ZeroTwo <[email protected]>
  • Loading branch information
Misfiy and Misaka-ZeroTwo authored Nov 9, 2024
1 parent 65c081e commit a4ebd2b
Showing 1 changed file with 51 additions and 17 deletions.
68 changes: 51 additions & 17 deletions EXILED/Exiled.API/Features/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -715,23 +715,7 @@ public ScpSpawnPreferences.SpawnPreferences ScpPreferences
public Vector3 Scale
{
get => ReferenceHub.transform.localScale;
set
{
if (value == Scale)
return;

try
{
ReferenceHub.transform.localScale = value;

foreach (Player target in List)
Server.SendSpawnMessage?.Invoke(null, new object[] { NetworkIdentity, target.Connection });
}
catch (Exception exception)
{
Log.Error($"{nameof(Scale)} error: {exception}");
}
}
set => SetScale(value, List);
}

/// <summary>
Expand Down Expand Up @@ -2070,6 +2054,56 @@ public void Disconnect(string reason = null) =>
/// </summary>
public void ResetStamina() => Stamina = StaminaStat.MaxValue;

/// <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)
{
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}");
}
}

/// <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<Player> viewers)
{
Vector3 currentScale = Scale;

if (fakeScale == currentScale)
return;

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}");
}
}

/// <summary>
/// Gets a user's SCP preference.
/// </summary>
Expand Down

0 comments on commit a4ebd2b

Please sign in to comment.