Skip to content

Commit

Permalink
Update KnifeGiver.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
jithatsonei authored Feb 28, 2024
1 parent 6a4d5cc commit 9e528c8
Showing 1 changed file with 52 additions and 46 deletions.
98 changes: 52 additions & 46 deletions KnifeGiver.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes;
Expand All @@ -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<EventPlayerSpawn>(Event_PlayerSpawn, HookMode.Post);
RegisterEventHandler<EventRoundPrestart>(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<EventPlayerSpawn>(Event_PlayerSpawn, HookMode.Post);
RegisterEventHandler<EventRoundPrestart>(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;
}
}
}

0 comments on commit 9e528c8

Please sign in to comment.