From 33230911f0541a9954f46321ca59635afbc7ab6a Mon Sep 17 00:00:00 2001 From: rayzer Date: Tue, 14 Jun 2022 18:06:10 -0500 Subject: [PATCH] CustomItem support --- ShootingRange/API/SpectatorRange.cs | 28 +++++++++++++++++++++++++--- ShootingRange/Config.cs | 20 ++++++++++---------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/ShootingRange/API/SpectatorRange.cs b/ShootingRange/API/SpectatorRange.cs index 9143a2b..f55013d 100644 --- a/ShootingRange/API/SpectatorRange.cs +++ b/ShootingRange/API/SpectatorRange.cs @@ -1,12 +1,18 @@ -using UnityEngine; +using System; + +using UnityEngine; using MEC; +using Mirror; + using Exiled.API.Enums; using Exiled.API.Features; using Exiled.API.Features.Toys; using Exiled.API.Extensions; -using Mirror; +using Exiled.CustomItems.API.Features; + +using Object = UnityEngine.Object; namespace ShootingRange.API { @@ -45,8 +51,24 @@ public bool TryAdmit(Player player) player.SetRole(RoleType.Tutorial); Timing.CallDelayed(0.5f, () => { + foreach (string str in PluginMain.Singleton.Config.RangerInventory) + { + if (Enum.TryParse(str, out ItemType type)) + { + player.AddItem(type); + continue; + } + + if (CustomItem.TryGet(str, out CustomItem item)) + { + item.Give(player, false); + continue; + } + + Log.Error($"Your config is not set up properly! (Could not find item {str})"); + } + player.Position = Spawn; - player.AddItem(PluginMain.Singleton.Config.RangerInventory); player.Health = 100000; player.ChangeAppearance(RoleType.ChaosConscript); player.Broadcast(PluginMain.Singleton.Config.RangeGreeting); diff --git a/ShootingRange/Config.cs b/ShootingRange/Config.cs index d4fc8f1..43b2020 100644 --- a/ShootingRange/Config.cs +++ b/ShootingRange/Config.cs @@ -23,17 +23,17 @@ public class Config : IConfig public Vector4 RangeLocation { get; set; } = default; [Description("Determines if the above location will be used or not")] public bool UseRangeLocation { get; set; } = false; - [Description("The items one will spawn with on the range")] - public List RangerInventory { get; set; } = new() + [Description("The items one will spawn with on the range (may be ItemType or the name of a CustomItem")] + public List RangerInventory { get; set; } = new() { - ItemType.GunAK, - ItemType.GunCOM18, - ItemType.GunCrossvec, - ItemType.GunE11SR, - ItemType.GunFSP9, - ItemType.GunLogicer, - ItemType.GunRevolver, - ItemType.GunShotgun + "GunAK", + "GunCOM18", + "GunCrossvec", + "GunE11SR", + "GunFSP9", + "GunLogicer", + "GunRevolver", + "GunShotgun", }; [Description("Player broadcast that appears when a player dies or joins as a spectator (This will not show if force_spectators is true)")] public PlayerBroadcast DeathBroadcast { get; set; } = new()