diff --git a/KnifeGiver.cs b/KnifeGiver.cs index 46500d0..3e6b6c0 100644 --- a/KnifeGiver.cs +++ b/KnifeGiver.cs @@ -1,4 +1,3 @@ -using System; using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Attributes; @@ -7,60 +6,67 @@ using CounterStrikeSharp.API.Modules.Cvars; using CounterStrikeSharp.API.Modules.Utils; -namespace KnifeGiver; -[MinimumApiVersion(175)] - -public class KnifeGiver : BasePlugin +namespace KnifeGiver { - public override string ModuleName => "WeaponsGiver"; - public override string ModuleAuthor => "ji"; - public override string ModuleDescription => "Ensures players in custom gamemodes spawn with starting weapons."; - public override string ModuleVersion => "build3"; - - public override void Load(bool hotReload) + [MinimumApiVersion(175)] + public class KnifeGiver : BasePlugin { - RegisterEventHandler(Event_PlayerSpawn, HookMode.Post); - RegisterEventHandler(Event_RoundPrestart, HookMode.Pre); - } + private string tPrimary; + private string tSecondary; + private string tMelee; + private string ctPrimary; + private string ctSecondary; + private string ctMelee; - public void GetVars() - { - var tPrimary = ConVar.Find("mp_t_default_primary").StringValue; - var tSecondary = ConVar.Find("mp_t_default_secondary").StringValue; - var tMelee = ConVar.Find("mp_t_default_melee").StringValue; + public override string ModuleName => "WeaponsGiver"; + public override string ModuleAuthor => "ji"; + public override string ModuleDescription => "Ensures players in custom gamemodes spawn with starting weapons."; + public override string ModuleVersion => "build3"; - var ctPrimary = ConVar.Find("mp_ct_default_primary").StringValue; - var ctSecondary = ConVar.Find("mp_ct_default_secondary").StringValue; - var ctMelee = ConVar.Find("mp_ct_default_melee").StringValue; - } + public override void Load(bool hotReload) + { + RegisterEventHandler(Event_PlayerSpawn, HookMode.Post); + RegisterEventHandler(Event_RoundPrestart, HookMode.Pre); + GetVars(); + } - private HookResult Event_RoundPrestart(EventRoundPrestart @event, GameEventInfo info) - { - GetVars(); - return HookResult.Continue; - } + public void GetVars() + { + tPrimary = ConVar.Find("mp_t_default_primary").StringValue; + tSecondary = ConVar.Find("mp_t_default_secondary").StringValue; + tMelee = ConVar.Find("mp_t_default_melee").StringValue; + ctPrimary = ConVar.Find("mp_ct_default_primary").StringValue; + ctSecondary = ConVar.Find("mp_ct_default_secondary").StringValue; + ctMelee = ConVar.Find("mp_ct_default_melee").StringValue; + } - private HookResult Event_PlayerSpawn(EventPlayerSpawn @event, GameEventInfo info) - { - var player = @event.Userid; - - if(!player.IsValid || !player.PlayerPawn.IsValid) return HookResult.Continue; + private HookResult Event_RoundPrestart(EventRoundPrestart @event, GameEventInfo info) + { + return HookResult.Continue; + } - switch((CsTeam)player.TeamNum) + private HookResult Event_PlayerSpawn(EventPlayerSpawn @event, GameEventInfo info) { - case CsTeam.Terrorist: - if(!String.IsNullOrEmpty(tPrimary)) player.GiveNamedItem(tPrimary); - if(!String.IsNullOrEmpty(tSecondary)) player.GiveNamedItem(tSecondary); - if(!String.IsNullOrEmpty(tMelee)) player.GiveNamedItem(tMelee); - break; + var player = @event.Userid; - case CsTeam.CounterTerrorist: - if(!String.IsNullOrEmpty(ctPrimary)) player.GiveNamedItem(ctPrimary); - if(!String.IsNullOrEmpty(ctSecondary)) player.GiveNamedItem(ctSecondary); - if(!String.IsNullOrEmpty(ctMelee)) player.GiveNamedItem(ctMelee); - break; - } + if(!player.IsValid || !player.PlayerPawn.IsValid) return HookResult.Continue; - return HookResult.Continue; + switch((CsTeam)player.TeamNum) + { + case CsTeam.Terrorist: + if(!String.IsNullOrEmpty(tPrimary)) player.GiveNamedItem(tPrimary); + if(!String.IsNullOrEmpty(tSecondary)) player.GiveNamedItem(tSecondary); + if(!String.IsNullOrEmpty(tMelee)) player.GiveNamedItem(tMelee); + break; + + case CsTeam.CounterTerrorist: + if(!String.IsNullOrEmpty(ctPrimary)) player.GiveNamedItem(ctPrimary); + if(!String.IsNullOrEmpty(ctSecondary)) player.GiveNamedItem(ctSecondary); + if(!String.IsNullOrEmpty(ctMelee)) player.GiveNamedItem(ctMelee); + break; + } + + return HookResult.Continue; + } } }