-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFunChangeWeaponOnShoot.cs
More file actions
73 lines (66 loc) · 2.51 KB
/
FunChangeWeaponOnShoot.cs
File metadata and controls
73 lines (66 loc) · 2.51 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
65
66
67
68
69
70
71
72
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Entities.Constants;
using CounterStrikeSharp.API.Modules.Utils;
namespace FunMatchPlugin;
public class FunChangeWeaponOnShoot : FunBaseClass
{
public override string Decription => "Change Weapon OnShoot 射击换枪";
private BasePlugin.GameEventHandler<EventBulletImpact>? EventBulletImpactHandler=null;
private Random random = new Random();
public override void Fun(FunMatchPlugin plugin)
{
if (Enabled) return;
Enabled = true;
//EventPlayerShoot Not Working
plugin.RegisterEventHandler <EventBulletImpact>(EventBulletImpactHandler = (@event, info) =>
{
if (Enabled == false) return HookResult.Stop;
if (@event.Userid == null) return HookResult.Continue;
//200-209 300-312 400-410
//give random weapon ON shoot
var guntype = random.Next(2,5);
int guntype_add = 0;
switch (guntype)
{
case 2:
{
guntype_add = random.Next(0,10);
break;
}
case 3:
{
guntype_add = random.Next(0,13);
break;
}
case 4:
{
guntype_add = random.Next(0,11);
break;
}
}
CsItem csItem = (CsItem)(guntype * 100 + guntype_add);
var player = @event.Userid!.OriginalControllerOfCurrentPawn.Get();
var pawn = player!.PlayerPawn.Get();
var cur_weapon = pawn!.WeaponServices!.ActiveWeapon.Get();
if (cur_weapon is null) return HookResult.Continue;
if (cur_weapon.DesignerName == "weapon_c4" || cur_weapon.DesignerName == "weapon_knife" || cur_weapon.DesignerName == "weapon_knife_t")
return HookResult.Continue;
player!.DropActiveWeapon();
player!.GiveNamedItem(csItem);
Server.NextFrame(()=>{
cur_weapon!.Remove();
if (pawn!.WeaponServices!.ActiveWeapon.Get() is null)
{
player!.GiveNamedItem(CsItem.Knife);
}
});
return HookResult.Continue;
});
}
public override void EndFun(FunMatchPlugin plugin)
{
Enabled = false;
plugin.DeregisterEventHandler(EventBulletImpactHandler!);
}
}