-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cs
More file actions
64 lines (53 loc) · 2.46 KB
/
Copy pathMain.cs
File metadata and controls
64 lines (53 loc) · 2.46 KB
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
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using static WeaponRestricter.Functions;
using static WeaponRestricter.Types;
using static WeaponRestricter.Utils;
namespace WeaponRestricter
{
public class WeaponRestrictPlugin : BasePlugin
{
public override string ModuleName => "WeaponRestrictPlugin";
public override string ModuleVersion => "1.0.2";
public override string ModuleAuthor => "FireBird";
public override void Load(bool hotReload)
{
LoadConfig(ModuleDirectory);
RegisterEventHandler<EventItemPurchase>(OnEventItemPurchase);
RegisterEventHandler<EventItemPickup>(OnEventItemPickup);
}
private HookResult OnEventItemPurchase(EventItemPurchase e, GameEventInfo info)
{
// Weapon is not restricted
Weapon? wep = FindWeaponByName(e.Weapon, _data_restricted);
if (wep == null) goto Skip;
// Weapon is pickable
PickableResult res = IsPickable(wep, e.Userid.Team);
if (res.pickable) goto Skip;
e.Userid.InGameMoneyServices!.Account += wep.price;
e.Userid.PrintToChat(ChatMessage($"{ChatColors.DarkBlue} Refunded {ChatColors.Lime}${wep.price}"));
Skip:
return HookResult.Continue;
}
private HookResult OnEventItemPickup(EventItemPickup e, GameEventInfo info)
{
// Weapon is not restricted
Weapon? wep = FindWeaponByIndex(e.Defindex, _data_restricted);
if (wep == null) goto Skip;
// Weapon is pickable
PickableResult res = IsPickable(wep, e.Userid.Team);
//e.Userid.PrintToChat($"Wep_Limit: {wep.limit} | Res_Limit: {res.limit} | Res_Count: {res.count} | Res_Pickable: {res.pickable}");
if (res.pickable) goto Skip;
foreach (var weapon in e.Userid.PlayerPawn.Value!.WeaponServices!.MyWeapons)
{
if (weapon.Value!.DesignerName != wep.designer_name) continue;
// Remove weapon & switch to previous weapon
weapon.Value.Remove();
e.Userid.ExecuteClientCommand("lastinv");
e.Userid.PrintToChat(ChatMessage($"{ChatColors.Red}Weapon {ChatColors.Magenta}{wep.name} {ChatColors.Red}is restricted to {ChatColors.Magenta}{res.limit} {ChatColors.Red}per team."));
}
Skip:
return HookResult.Continue;
}
}
}