Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Mar 27, 2024
1 parent 013c30d commit 24e250b
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions WeaponsGiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,32 @@ namespace WeaponsGiver
[MinimumApiVersion(198)]
public class WeaponsGiver : BasePlugin
{
private string tPrimary;
private string tSecondary;
private string tMelee;
private string ctPrimary;
private string ctSecondary;
private string ctMelee;
private string tPrimary = "";
private string tSecondary = "";
private string tMelee = "";
private string ctPrimary = "";
private string ctSecondary = "";
private string ctMelee = "";

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 => "build6";
public override string ModuleVersion => "build7";

public override void Load(bool hotReload)
{
RegisterEventHandler<EventPlayerSpawn>(Event_PlayerSpawn, HookMode.Post);
RegisterEventHandler<EventRoundPrestart>(Event_RoundPrestart, HookMode.Pre);
}

public void GetVars()
private 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;

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_RoundPrestart(EventRoundPrestart @event, GameEventInfo info)
Expand All @@ -46,7 +45,10 @@ private HookResult Event_RoundPrestart(EventRoundPrestart @event, GameEventInfo

private HookResult Event_PlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
{
Server.RunOnTick(Server.TickCount + 1, () => GiveWeapons(@event.Userid));
var player = @event.Userid;
if(!player.IsValid || player.Connected != PlayerConnectedState.PlayerConnected)
return HookResult.Continue;
Server.RunOnTick(Server.TickCount + 1, () => GiveWeapons(player));
return HookResult.Continue;
}

Expand All @@ -55,18 +57,18 @@ private void GiveWeapons(CCSPlayerController player)
if(!player.IsValid || !player.PlayerPawn.IsValid) return;
if (player.Connected != PlayerConnectedState.PlayerConnected) return;

switch((CsTeam)player.TeamNum)
switch(player.Team)
{
case CsTeam.Terrorist:
if(!String.IsNullOrEmpty(tPrimary)) player.GiveNamedItem(tPrimary);
if(!String.IsNullOrEmpty(tSecondary)) player.GiveNamedItem(tSecondary);
if(!String.IsNullOrEmpty(tMelee)) player.GiveNamedItem(tMelee);
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);
if(!string.IsNullOrEmpty(ctPrimary)) player.GiveNamedItem(ctPrimary);
if(!string.IsNullOrEmpty(ctSecondary)) player.GiveNamedItem(ctSecondary);
if(!string.IsNullOrEmpty(ctMelee)) player.GiveNamedItem(ctMelee);
break;
}
}
Expand Down

0 comments on commit 24e250b

Please sign in to comment.