-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFunPlayerShootExChange.cs
More file actions
48 lines (43 loc) · 1.96 KB
/
FunPlayerShootExChange.cs
File metadata and controls
48 lines (43 loc) · 1.96 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
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using CounterStrikeSharp.API;
namespace FunMatchPlugin;
public class FunPlayerShootExChange : FunBaseClass
{
public override string Decription => "Bullet ExChange 击中交换位置";
public FunPlayerShootExChange (FunMatchPlugin plugin): base(plugin){}
private BasePlugin.GameEventHandler<EventPlayerHurt>? EventPlayerHurtHandler;
public override void Fun(FunMatchPlugin plugin)
{
if (Enabled) return;
Enabled = true;
plugin.RegisterEventHandler <EventPlayerHurt>(EventPlayerHurtHandler = (@event, info) =>
{
if (Enabled == false) return HookResult.Stop;
//Console.WriteLine("Player Shoot ExChange Event");
//To Avoid VScode Warning "might be null"
if (@event is null) return HookResult.Continue;
if (@event.Attacker is null) return HookResult.Continue;
if (@event.Userid is null) return HookResult.Continue;
if (@event.Userid == @event.Attacker) return HookResult.Continue;
var attacker = @event.Attacker.OriginalControllerOfCurrentPawn.Get()!.PlayerPawn.Get();
var victim = @event.Userid.OriginalControllerOfCurrentPawn.Get()!.PlayerPawn.Get();
Vector PositionAttacker = new Vector(attacker!.AbsOrigin!.X,attacker.AbsOrigin.Y,attacker.AbsOrigin.Z);
Vector PositionVictim = new Vector(victim!.AbsOrigin!.X,victim.AbsOrigin.Y,victim.AbsOrigin.Z);
Server.NextFrame(() =>
{
victim.Teleport(PositionAttacker);
attacker.Teleport(PositionVictim);
});
return HookResult.Continue;
});
}
public override void RegisterCommand(FunMatchPlugin plugin)
{
}
public override void EndFun(FunMatchPlugin plugin)
{
plugin.DeregisterEventHandler<EventPlayerHurt> (EventPlayerHurtHandler!);
Enabled = false;
}
}