From e4a9fb81b89fb51425c84f5b7c59a7c725a98384 Mon Sep 17 00:00:00 2001 From: PintTheDragon <64887885+PintTheDragon@users.noreply.github.com> Date: Sun, 4 Oct 2020 14:45:46 -0700 Subject: [PATCH] Add support for CustomNPCs --- SCPSwap/EventHandlers.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/SCPSwap/EventHandlers.cs b/SCPSwap/EventHandlers.cs index c64b795..3cc4053 100644 --- a/SCPSwap/EventHandlers.cs +++ b/SCPSwap/EventHandlers.cs @@ -214,7 +214,10 @@ public void OnConsoleCommand(SendingConsoleCommandEventArgs ev) return; } - swap = Player.List.FirstOrDefault(x => role == RoleType.Scp93953 ? x.Role == role || x.Role == RoleType.Scp93989 : x.Role == role); + Type npcClass = Loader.Plugins.FirstOrDefault(pl => pl.Name == "CustomNPCs")?.Assembly.GetType("NPCS.Npc"); + var npcs = ((IEnumerable) npcClass?.GetField("List")?.GetValue(null))?.Select(npc => (Player) npcClass?.GetField("NPCPlayer")?.GetValue(npc)); + + swap = npcs == null ? Player.List.FirstOrDefault(x => role == RoleType.Scp93953 ? x.Role == role || x.Role == RoleType.Scp93989 : x.Role == role) : Player.List.Where(p => !npcs.Any(p)).FirstOrDefault(x => role == RoleType.Scp93953 ? x.Role == role || x.Role == RoleType.Scp93989 : x.Role == role); if (swap != null) { reqCoroutines.Add(ev.Player, Timing.RunCoroutine(SendRequest(ev.Player, swap)));