forked from jithatsonei/WeaponsGiver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WeaponsGiver.cs
78 lines (68 loc) · 3.16 KB
/
WeaponsGiver.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes;
using CounterStrikeSharp.API.Modules.Cvars;
using CounterStrikeSharp.API.Modules.Utils;
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 = "";
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 => "build7";
public override void Load(bool hotReload)
{
RegisterEventHandler<EventPlayerSpawn>(Event_PlayerSpawn, HookMode.Post);
RegisterEventHandler<EventRoundPrestart>(Event_RoundPrestart, HookMode.Pre);
}
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 ?? "";
}
private HookResult Event_RoundPrestart(EventRoundPrestart @event, GameEventInfo info)
{
GetVars();
return HookResult.Continue;
}
private HookResult Event_PlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
{
var player = @event.Userid;
if(!player.IsValid || player.Connected != PlayerConnectedState.PlayerConnected)
return HookResult.Continue;
Server.RunOnTick(Server.TickCount + 1, () => GiveWeapons(player));
return HookResult.Continue;
}
private void GiveWeapons(CCSPlayerController player)
{
if(!player.IsValid || !player.PlayerPawn.IsValid) return;
if (player.Connected != PlayerConnectedState.PlayerConnected) return;
player.RemoveWeapons();
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);
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;
}
}
}
}