-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFunToTheMoon.cs
More file actions
72 lines (63 loc) · 3.63 KB
/
FunToTheMoon.cs
File metadata and controls
72 lines (63 loc) · 3.63 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
using CounterStrikeSharp.API.Modules.Cvars;
using CounterStrikeSharp.API.Modules.Utils;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API;
namespace FunMatchPlugin;
public class FunToTheMoon : FunBaseClass
{
public override string Decription => "To The Moon 月球低重力";
public FunToTheMoon(FunMatchPlugin plugin) : base(plugin){}
public float gravity = (float)(800 * 0.166);
public float BulletGiveAbsV = 100;
private BasePlugin.GameEventHandler<EventBulletImpact>? EventBulletImpactHandler;
private BasePlugin.GameEventHandler<EventPlayerHurt>? EventPlayerHurtHandler;
public override void Fun(FunMatchPlugin plugin)
{
if (Enabled) return;
Enabled = true;
ConVar.Find("sv_cheats")!.SetValue(true);
ConVar.Find("sv_gravity")!.SetValue(gravity);
ConVar.Find("sv_cheats")!.SetValue(false);
plugin.RegisterEventHandler <EventBulletImpact>(EventBulletImpactHandler = (@event, info) =>
{
if (Enabled == false) return HookResult.Stop;
if (@event.Userid is null) return HookResult.Continue;
var pawn = @event.Userid.OriginalControllerOfCurrentPawn.Get()!.PlayerPawn.Get();
Vector bulletPosition = new Vector(@event.X,@event.Y,@event.Z);
Vector playerPosition = pawn!.AbsOrigin!;
double V2 = Math.Pow(playerPosition.X-bulletPosition.X,2) + Math.Pow(playerPosition.Y-bulletPosition.Y,2) + Math.Pow(playerPosition.Z-bulletPosition.Z,2);
float Scale = (float)(BulletGiveAbsV /Math.Sqrt(V2));
pawn.AbsVelocity.X += (playerPosition.X-bulletPosition.X)*Scale;
pawn.AbsVelocity.Y += (playerPosition.Y-bulletPosition.Y)*Scale;
pawn.AbsVelocity.Z += (playerPosition.Z-bulletPosition.Z)*Scale;
return HookResult.Continue;
});
// if molotov hurt the player, will add V from Acctacker not from damage source... to be rewrite
plugin.RegisterEventHandler <EventPlayerHurt>(EventPlayerHurtHandler = (@event, info) =>
{
if (Enabled == false) return HookResult.Stop;
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);
double V2 = Math.Pow(PositionAttacker.X-PositionVictim.X,2) + Math.Pow(PositionAttacker.Y-PositionVictim.Y,2) + Math.Pow(PositionAttacker.Z-PositionVictim.Z,2);
float Scale = (float)(BulletGiveAbsV /Math.Sqrt(V2));
victim.AbsVelocity.X += (PositionVictim.X-PositionAttacker.X)*Scale;
victim.AbsVelocity.Y += (PositionVictim.Y-PositionAttacker.Y)*Scale;
victim.AbsVelocity.Z += (PositionVictim.Z-PositionAttacker.Z)*Scale;
return HookResult.Continue;
});
}
public override void EndFun(FunMatchPlugin plugin)
{
Enabled = false;
plugin.DeregisterEventHandler (EventBulletImpactHandler!);
plugin.DeregisterEventHandler (EventPlayerHurtHandler!);
ConVar.Find("sv_cheats")!.SetValue(true);
ConVar.Find("sv_gravity")!.SetValue((float)800);
ConVar.Find("sv_cheats")!.SetValue(false);
}
}