-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathShowDamage.cs
116 lines (98 loc) · 3.71 KB
/
ShowDamage.cs
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Admin;
using CounterStrikeSharp.API.Modules.Cvars;
using CounterStrikeSharp.API.Modules.Entities;
using CounterStrikeSharp.API.Modules.Utils;
using System.Numerics;
using System.Text;
namespace ShowDamage
{
class DamageDone
{
public float Health { get; set; }
public float Armor { get; set; }
}
public class ShowDamage : BasePlugin, IPluginConfig<Config>
{
public override string ModuleName => "AbNeR ShowDamage";
public override string ModuleVersion => "1.1.0";
public override string ModuleAuthor => "AbNeR_CSS";
public override string ModuleDescription => "Shows damage dealt to enemies in the center text";
Dictionary<int, DamageDone> damageDone = new();
ConVar? ffaEnabledConVar = null;
public bool FFAEnabled
{
get
{
if (ffaEnabledConVar is null)
return false;
return ffaEnabledConVar.GetPrimitiveValue<bool>();
}
}
public required Config Config { get; set; }
public void OnConfigParsed(Config config)
{
Config = config;
}
public override void Load(bool hotReload)
{
Console.WriteLine("Showdamage loaded");
ffaEnabledConVar = ConVar.Find("mp_teammates_are_enemies");
}
Action BuildCallback(int attackerUserId) =>
() =>
{
if (damageDone.ContainsKey(attackerUserId))
{
var player = Utilities.GetPlayerFromUserid(attackerUserId);
if (player is not null && player.IsValid)
{
var dmg = damageDone[attackerUserId];
if (dmg is not null)
{
StringBuilder builder = new();
builder.Append($"-{dmg.Health} HP");
if (dmg.Armor > 0 && Config.ShowArmorDmg)
builder.Append($"\n-{dmg.Armor} Armor");
player.PrintToCenter(builder.ToString());
}
}
damageDone.Remove(attackerUserId);
}
};
[GameEventHandler]
public HookResult EventPlayerHurt(EventPlayerHurt ev, GameEventInfo info)
{
if (ev.Attacker is null ||
ev.Userid is null ||
!ev.Attacker.IsValid ||
(ev.Attacker.TeamNum == ev.Userid.TeamNum && !FFAEnabled))
return HookResult.Continue;
int attackerUserId = ev.Attacker.UserId!.Value;
if (!string.IsNullOrEmpty(Config.AdminGroup) && !AdminManager.PlayerInGroup(ev.Attacker, Config.AdminGroup))
return HookResult.Continue;
if (Config.HideDamage)
{
ev.Attacker.PrintToCenter("*");
return HookResult.Continue;
}
if (damageDone.ContainsKey(attackerUserId))
{
DamageDone? dmg = damageDone[attackerUserId];
if (dmg is not null)
{
dmg.Health += ev.DmgHealth;
dmg.Armor += ev.DmgArmor;
}
}
else
{
damageDone.Add(attackerUserId, new DamageDone { Armor = ev.DmgArmor, Health = ev.DmgHealth });
AddTimer(0.1F, BuildCallback(attackerUserId), 0);
}
return HookResult.Continue;
}
}
}