From 7a4a09ab9886a7a33ed71d7c0d11a44eda0dcefa Mon Sep 17 00:00:00 2001 From: SrLicht Date: Mon, 23 Sep 2024 21:35:52 -0300 Subject: [PATCH 1/5] Fix RoomSpawnpoint * Preventing use of TransformPoint(Offset) in Surface Room * Added more delay --- EXILED/Exiled.API/Features/Spawn/RoomSpawnPoint.cs | 5 +++++ EXILED/Exiled.CustomItems/Events/MapHandler.cs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/EXILED/Exiled.API/Features/Spawn/RoomSpawnPoint.cs b/EXILED/Exiled.API/Features/Spawn/RoomSpawnPoint.cs index 92e24e712f..a754195770 100644 --- a/EXILED/Exiled.API/Features/Spawn/RoomSpawnPoint.cs +++ b/EXILED/Exiled.API/Features/Spawn/RoomSpawnPoint.cs @@ -48,6 +48,11 @@ public override Vector3 Position { Room roomInstance = Features.Room.Get(Room) ?? throw new InvalidOperationException("The room instance could not be found."); + if (roomInstance.Type == RoomType.Surface) + { + return Offset != Vector3.zero ? Offset : roomInstance.Position; + } + return Offset != Vector3.zero ? roomInstance.transform.TransformPoint(Offset) : roomInstance.Position; } set => throw new InvalidOperationException("The position of this type of SpawnPoint cannot be changed."); diff --git a/EXILED/Exiled.CustomItems/Events/MapHandler.cs b/EXILED/Exiled.CustomItems/Events/MapHandler.cs index 4e0c2442f9..162a3132a8 100644 --- a/EXILED/Exiled.CustomItems/Events/MapHandler.cs +++ b/EXILED/Exiled.CustomItems/Events/MapHandler.cs @@ -18,7 +18,7 @@ internal sealed class MapHandler /// public void OnMapGenerated() { - Timing.CallDelayed(0.5f, () => // Delay its necessary for the spawnpoints of lockers and rooms to be generated. + Timing.CallDelayed(0.8f, () => // Delay its necessary for the spawnpoints of lockers and rooms to be generated. { foreach (CustomItem customItem in CustomItem.Registered) customItem?.SpawnAll(); From 42bf7d5faaf77e2aeed4d51157f6e87733205b94 Mon Sep 17 00:00:00 2001 From: SrLicht Date: Tue, 24 Sep 2024 15:23:53 -0300 Subject: [PATCH 2/5] Update EXILED/Exiled.API/Features/Spawn/RoomSpawnPoint.cs Co-authored-by: Alex Rouse --- EXILED/Exiled.API/Features/Spawn/RoomSpawnPoint.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/EXILED/Exiled.API/Features/Spawn/RoomSpawnPoint.cs b/EXILED/Exiled.API/Features/Spawn/RoomSpawnPoint.cs index a754195770..7336fd0837 100644 --- a/EXILED/Exiled.API/Features/Spawn/RoomSpawnPoint.cs +++ b/EXILED/Exiled.API/Features/Spawn/RoomSpawnPoint.cs @@ -49,9 +49,7 @@ public override Vector3 Position Room roomInstance = Features.Room.Get(Room) ?? throw new InvalidOperationException("The room instance could not be found."); if (roomInstance.Type == RoomType.Surface) - { return Offset != Vector3.zero ? Offset : roomInstance.Position; - } return Offset != Vector3.zero ? roomInstance.transform.TransformPoint(Offset) : roomInstance.Position; } From 5fa8fc83c2197799b870b829ee57e047562410b8 Mon Sep 17 00:00:00 2001 From: SrLicht Date: Tue, 24 Sep 2024 16:29:31 -0300 Subject: [PATCH 3/5] Using WaitingForPlayers * Thanks Alex Co-Authored-By: Alex Rouse --- EXILED/Exiled.CustomItems/CustomItems.cs | 4 ++-- EXILED/Exiled.CustomItems/Events/MapHandler.cs | 11 ++++------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/EXILED/Exiled.CustomItems/CustomItems.cs b/EXILED/Exiled.CustomItems/CustomItems.cs index 855186c002..207f55b6f4 100644 --- a/EXILED/Exiled.CustomItems/CustomItems.cs +++ b/EXILED/Exiled.CustomItems/CustomItems.cs @@ -35,7 +35,7 @@ public override void OnEnabled() roundHandler = new MapHandler(); playerHandler = new PlayerHandler(); - Exiled.Events.Handlers.Map.Generated += roundHandler.OnMapGenerated; + Exiled.Events.Handlers.Server.WaitingForPlayers += roundHandler.OnWaitingForPlayers; Exiled.Events.Handlers.Player.ChangingItem += playerHandler.OnChangingItem; @@ -50,7 +50,7 @@ public override void OnEnabled() /// public override void OnDisabled() { - Exiled.Events.Handlers.Map.Generated -= roundHandler!.OnMapGenerated; + Exiled.Events.Handlers.Server.WaitingForPlayers -= roundHandler!.OnWaitingForPlayers; Exiled.Events.Handlers.Player.ChangingItem -= playerHandler!.OnChangingItem; diff --git a/EXILED/Exiled.CustomItems/Events/MapHandler.cs b/EXILED/Exiled.CustomItems/Events/MapHandler.cs index 162a3132a8..78ea155c07 100644 --- a/EXILED/Exiled.CustomItems/Events/MapHandler.cs +++ b/EXILED/Exiled.CustomItems/Events/MapHandler.cs @@ -15,14 +15,11 @@ namespace Exiled.CustomItems.Events /// internal sealed class MapHandler { - /// - public void OnMapGenerated() + /// + public void OnWaitingForPlayers() { - Timing.CallDelayed(0.8f, () => // Delay its necessary for the spawnpoints of lockers and rooms to be generated. - { - foreach (CustomItem customItem in CustomItem.Registered) - customItem?.SpawnAll(); - }); + foreach (CustomItem customItem in CustomItem.Registered) + customItem?.SpawnAll(); } } } \ No newline at end of file From 2beed769946fa2dbdd2114813b8f4d562b4131db Mon Sep 17 00:00:00 2001 From: SrLicht Date: Sat, 5 Oct 2024 14:58:45 -0300 Subject: [PATCH 4/5] Update MapHandler.cs After so much testing for a while, if CustomItems spawn too early they are not properly registered and spawn but without being custom items, also the locker spawn does not work because the base game did not finish generating all the lockers on the map yet, by adding this delay all those problems were eliminated. I also thought it was fair to add a Try catch Log.Error in case there is any error when spawning custom items, currently if there is any you have no way of knowing. Translated with DeepL.com (free version) --- EXILED/Exiled.CustomItems/Events/MapHandler.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/EXILED/Exiled.CustomItems/Events/MapHandler.cs b/EXILED/Exiled.CustomItems/Events/MapHandler.cs index 78ea155c07..6a5da5d604 100644 --- a/EXILED/Exiled.CustomItems/Events/MapHandler.cs +++ b/EXILED/Exiled.CustomItems/Events/MapHandler.cs @@ -7,6 +7,7 @@ namespace Exiled.CustomItems.Events { + using Exiled.API.Features; using Exiled.CustomItems.API.Features; using MEC; @@ -18,8 +19,20 @@ internal sealed class MapHandler /// public void OnWaitingForPlayers() { - foreach (CustomItem customItem in CustomItem.Registered) - customItem?.SpawnAll(); + Timing.CallDelayed(2, () => // The delay is necessary because the generation of the lockers takes time, due to the way they are made in the base game. + { + foreach (CustomItem customItem in CustomItem.Registered) + { + try + { + customItem?.SpawnAll(); + } + catch (System.Exception e) + { + Log.Error($"Error on spawning custom item {customItem?.Name} ({customItem?.Id}) | {e.Message}"); + } + } + }); } } } \ No newline at end of file From 2a5e6af702b1eaecf13f08cbf81cc38dbf50f71c Mon Sep 17 00:00:00 2001 From: SrLicht Date: Sun, 6 Oct 2024 12:18:07 -0300 Subject: [PATCH 5/5] Update EXILED/Exiled.CustomItems/Events/MapHandler.cs Co-authored-by: Alex Rouse --- EXILED/Exiled.CustomItems/Events/MapHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EXILED/Exiled.CustomItems/Events/MapHandler.cs b/EXILED/Exiled.CustomItems/Events/MapHandler.cs index 6a5da5d604..61993e03cb 100644 --- a/EXILED/Exiled.CustomItems/Events/MapHandler.cs +++ b/EXILED/Exiled.CustomItems/Events/MapHandler.cs @@ -29,7 +29,7 @@ public void OnWaitingForPlayers() } catch (System.Exception e) { - Log.Error($"Error on spawning custom item {customItem?.Name} ({customItem?.Id}) | {e.Message}"); + Log.Error($"There was an error while spawning the custom item '{customItem?.Name}' ({customItem?.Id}) | {e.Message}"); } } });