-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFunDropWeaponOnShoot.cs
More file actions
43 lines (39 loc) · 1.64 KB
/
FunDropWeaponOnShoot.cs
File metadata and controls
43 lines (39 loc) · 1.64 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
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Entities.Constants;
using CounterStrikeSharp.API.Modules.Utils;
namespace FunMatchPlugin;
public class FunDropWeaponOnShoot : FunBaseClass
{
public override string Decription => "Drop Weapon OnShoot 射击丢枪";
private BasePlugin.GameEventHandler<EventBulletImpact>? EventBulletImpactHandler=null;
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;
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();
Server.NextFrame(()=>{
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!);
}
}