From 288104c3782285ea2180cffeb3aa2bb0c10f7158 Mon Sep 17 00:00:00 2001 From: SrLicht Date: Mon, 17 Jul 2023 08:48:36 -0300 Subject: [PATCH 1/3] Adding Player.Scale * Added NetworkIdentity in Player.cs * Added Scale in Player.cs *It is now possible to change the size of a player from NWAPI. * Added SpawnMessage method in Server.cs # Credits This method was taken from https://github.com/Axwabo/AdminTools-NWAPI/blob/master/AdminTools/EventHandlers.cs#L154 which in is a fork of Exiled RemoteAdmin --- NwPluginAPI/Core/Player.cs | 33 +++++++++++++++++++++++++++++++-- NwPluginAPI/Core/Server.cs | 7 +++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/NwPluginAPI/Core/Player.cs b/NwPluginAPI/Core/Player.cs index 47475e0..9181552 100644 --- a/NwPluginAPI/Core/Player.cs +++ b/NwPluginAPI/Core/Player.cs @@ -572,6 +572,37 @@ public string DisplayNickname /// public string IpAddress => ReferenceHub.characterClassManager.connectionToClient.address; + /// + /// Gets or sets player's scale. + /// + public Vector3 Scale + { + get => ReferenceHub.transform.localScale; + set + { + if (value == Scale) + return; + + try + { + ReferenceHub.transform.localScale = value; + foreach(var player in GetPlayers()) + { + Server.SpawnMessage?.Invoke(null, new object[] { NetworkIdentity, player.Connection }); + } + } + catch (Exception e) + { + Log.Error($"Error on {nameof(Scale)}: {e}"); + } + } + } + + /// + /// Gets player . + /// + public NetworkIdentity NetworkIdentity => ReferenceHub.networkIdentity; + /// /// Gets or sets the player's current role. /// @@ -679,7 +710,6 @@ public ItemBase CurrentItem /// public RoomIdentifier Room => RoomIdUtils.RoomAtPosition(GameObject.transform.position); - /// /// Get player current zone. /// @@ -713,7 +743,6 @@ public string RoleName set => ReferenceHub.serverRoles.SetText(value); } - /// /// Gets the player unit name. /// diff --git a/NwPluginAPI/Core/Server.cs b/NwPluginAPI/Core/Server.cs index 41e5643..dec4d50 100644 --- a/NwPluginAPI/Core/Server.cs +++ b/NwPluginAPI/Core/Server.cs @@ -10,6 +10,7 @@ namespace PluginAPI.Core using RoundRestarting; using static BanHandler; using static Broadcast; + using System.Reflection; /// /// Represents the server. @@ -17,6 +18,7 @@ namespace PluginAPI.Core public class Server : Player { private static Server _instance; + private static MethodInfo _sendSpawnMessage; /// /// The instance. @@ -104,6 +106,11 @@ public static int ReservedSlots /// public static PermissionsHandler PermissionsHandler => ServerStatic.GetPermissionsHandler(); + /// + /// Gets cached .SendSpawnMessage private method. + /// + public static MethodInfo SpawnMessage => _sendSpawnMessage ??= typeof(NetworkServer).GetMethod("SendSpawnMessage", BindingFlags.NonPublic | BindingFlags.Static); + /// /// Get actual ticks per second of the server. /// From e2e91ea09ead102c8e40f7ce2c54c34866511634 Mon Sep 17 00:00:00 2001 From: SrLicht Date: Mon, 17 Jul 2023 08:49:52 -0300 Subject: [PATCH 2/3] boop --- NwPluginAPI/Core/Player.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NwPluginAPI/Core/Player.cs b/NwPluginAPI/Core/Player.cs index 9181552..5420eb5 100644 --- a/NwPluginAPI/Core/Player.cs +++ b/NwPluginAPI/Core/Player.cs @@ -599,7 +599,7 @@ public Vector3 Scale } /// - /// Gets player . + /// Gets player's . /// public NetworkIdentity NetworkIdentity => ReferenceHub.networkIdentity; From 19e000219fad23819413e9b63c1ef4d730814591 Mon Sep 17 00:00:00 2001 From: SrLicht Date: Tue, 18 Jul 2023 19:07:36 -0300 Subject: [PATCH 3/3] Fixing --- NwPluginAPI/Core/Player.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NwPluginAPI/Core/Player.cs b/NwPluginAPI/Core/Player.cs index 5420eb5..d2d79aa 100644 --- a/NwPluginAPI/Core/Player.cs +++ b/NwPluginAPI/Core/Player.cs @@ -577,7 +577,7 @@ public string DisplayNickname /// public Vector3 Scale { - get => ReferenceHub.transform.localScale; + get => GameObject.transform.localScale; set { if (value == Scale) @@ -585,7 +585,7 @@ public Vector3 Scale try { - ReferenceHub.transform.localScale = value; + GameObject.transform.localScale = value; foreach(var player in GetPlayers()) { Server.SpawnMessage?.Invoke(null, new object[] { NetworkIdentity, player.Connection });