Skip to content

Commit

Permalink
roles with hats
Browse files Browse the repository at this point in the history
  • Loading branch information
moddedmcplayer committed Nov 3, 2022
1 parent f85b9cf commit e1fda80
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
7 changes: 7 additions & 0 deletions hats/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ public class Config : IConfig
RoleType.Scp096
};

public bool EnableAutoGiveHat { get; set; } = false;
[Description("Roles that will be given a hat on spawn, if EnableAutoGiveHat is true")]
public Dictionary<RoleType, string> RolesWithHats { get; set; } = new Dictionary<RoleType, string>()
{
[RoleType.ClassD] = "Name",
};

public List<HatConfig> Hats { get; set; }= new List<HatConfig>()
{
new HatConfig()
Expand Down
15 changes: 15 additions & 0 deletions hats/EventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace hats
{
using Exiled.API.Enums;
using Exiled.API.Features;

public class EventHandler
{
Expand Down Expand Up @@ -49,5 +50,19 @@ public void UsedItem(UsedItemEventArgs ev)
ev.Player.ShowHint("Removed hat since you used 268.");
}
}

public void Spawned(SpawnedEventArgs ev)
{
if (!cfg.EnableAutoGiveHat)
return;
if (!cfg.RolesWithHats.ContainsKey(ev.Player.Role.Type))
return;
if(!API.Hats.ContainsKey(cfg.RolesWithHats[ev.Player.Role.Type]))
{
Log.Warn($"Could not find hat: {cfg.RolesWithHats[ev.Player.Role.Type]} for role: {ev.Player.Role.Type}");
return;
}
ev.Player.AddHat(API.Hats[cfg.RolesWithHats[ev.Player.Role.Type]]);
}
}
}
4 changes: 3 additions & 1 deletion hats/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Plugin : Plugin<Config>
{
public override string Author { get; } = "Rowpann SCP";
public override string Name { get; } = "hats";
public override Version Version { get; } = new Version(1, 4, 3);
public override Version Version { get; } = new Version(1, 5, 0);
public override Version RequiredExiledVersion { get; } = new Version(5, 2, 0);

public static Plugin Singleton;
Expand All @@ -28,6 +28,7 @@ public override void OnEnabled()
Player.Left += Handler.OnLeave;
Player.Died += Handler.Died;
Player.UsedItem += Handler.UsedItem;
Player.Spawned += Handler.Spawned;

base.OnEnabled();
}
Expand All @@ -38,6 +39,7 @@ public override void OnDisabled()
Player.Left -= Handler.OnLeave;
Player.Died -= Handler.Died;
Player.UsedItem -= Handler.UsedItem;
Player.Spawned -= Handler.Spawned;

Singleton = null;
Handler = null;
Expand Down

0 comments on commit e1fda80

Please sign in to comment.