diff --git a/Components/Scp507Component.cs b/Components/Scp507Component.cs index 2385044..51d1f5d 100644 --- a/Components/Scp507Component.cs +++ b/Components/Scp507Component.cs @@ -1,5 +1,4 @@ using Exiled.API.Features; -using Exiled.CustomRoles.API.Features; using UnityEngine; namespace Scp_507.Components diff --git a/Config.cs b/Config.cs index 03a9c82..4d9bd4b 100644 --- a/Config.cs +++ b/Config.cs @@ -9,6 +9,9 @@ public class Config : IConfig public bool IsEnabled { get; set; } = true; public bool Debug { get; set; } = false; + [Description("Scp507: Spawn chance")] + public byte Scp507SpawnChance { get; set; } = 75; + [Description("Scp507 Teleporter: Minimum time (seconds)")] public uint Scp507TeleporterMin { get; set; } = 2; diff --git a/CustomRoles/Scp507.cs b/CustomRoles/Scp507.cs index fa2a734..d91b518 100644 --- a/CustomRoles/Scp507.cs +++ b/CustomRoles/Scp507.cs @@ -92,6 +92,7 @@ private IEnumerator Teleporter(Player pl) { players.Add(pl); } + Room room = Room.List.Where(r => !Plugin.StupidRooms.Contains(r.Type)).GetRandomValue(); newPosition = room.Position + new Vector3(0, 1.2f); diff --git a/Events/PlayerHandler.cs b/Events/PlayerHandler.cs new file mode 100644 index 0000000..28c7357 --- /dev/null +++ b/Events/PlayerHandler.cs @@ -0,0 +1,22 @@ +using Exiled.API.Features; +using Exiled.Events.EventArgs.Player; +using PlayerRoles; +using System.Linq; +using UnityEngine; + +namespace Scp_507.Events +{ + public static class PlayerHandler + { + public static void OnChangingRole(ChangingRoleEventArgs ev) + { + if (ev.Player.IsNPC || ev.Player.IsHost) return; + if (ev.Reason != Exiled.API.Enums.SpawnReason.RoundStart) return; + if (ev.Player.Role.Type != RoleTypeId.Scientist) return; + if (Player.List.Where(r => !r.IsNPC && !r.IsHost).Any(Plugin.Instance.Config.Scp507.Check)) return; + if (Random.Range(0, 100) <= Plugin.Instance.Config.Scp507SpawnChance) return; + + Plugin.Instance.Config.Scp507.AddRole(ev.Player); + } + } +} diff --git a/Plugin.cs b/Plugin.cs index 80840d8..eaa59cd 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -1,6 +1,7 @@ using Exiled.API.Enums; using Exiled.API.Features; using Exiled.CustomRoles.API; +using Scp_507.Events; using System; using System.Collections.Generic; @@ -22,16 +23,30 @@ public override void OnEnabled() Instance.Config.Scp507.Register(); + SubscribeEvents(); + base.OnEnabled(); } public override void OnDisabled() { + UnsubscribeEvents(); + Instance.Config.Scp507.Unregister(); Instance = null; base.OnDisabled(); } + + private void SubscribeEvents() + { + Exiled.Events.Handlers.Player.ChangingRole += PlayerHandler.OnChangingRole; + } + + private void UnsubscribeEvents() + { + Exiled.Events.Handlers.Player.ChangingRole -= PlayerHandler.OnChangingRole; + } } } diff --git a/Scp-507.csproj b/Scp-507.csproj index 112955e..bf91853 100644 --- a/Scp-507.csproj +++ b/Scp-507.csproj @@ -66,6 +66,7 @@ +