Skip to content

Commit

Permalink
Support FFA
Browse files Browse the repository at this point in the history
  • Loading branch information
abnerfs committed Nov 18, 2023
1 parent 7053acb commit 92abb96
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions ShowDamage.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Cvars;
using CounterStrikeSharp.API.Modules.Entities;
using CounterStrikeSharp.API.Modules.Utils;
using System.Text;

namespace ShowDamage
Expand All @@ -16,33 +18,52 @@ public class ShowDamage : BasePlugin
{
public override string ModuleName => "AbNeR ShowDamage";

public override string ModuleVersion => "1.0.0";
public override string ModuleVersion => "1.0.1";

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 override void Load(bool hotReload)
{
Console.WriteLine("Showdamage loaded");

ffaEnabledConVar = ConVar.Find("mp_teammates_are_enemies");
}

[GameEventHandler]
public HookResult EventPlayerHurt(EventPlayerHurt ev, GameEventInfo info)
{
if (ev.Attacker is null ||
ev.Userid is null ||
ev.Attacker.TeamNum == ev.Userid.TeamNum)
!ev.Attacker.IsValid ||
(ev.Attacker.TeamNum == ev.Userid.TeamNum && !FFAEnabled))
return HookResult.Continue;

int attackerUserId = ev.Attacker.UserId!.Value;
if (damageDone.ContainsKey(attackerUserId))
{
var dmg = damageDone[attackerUserId];
dmg.Health += ev.DmgHealth;
dmg.Armor += ev.DmgArmor;
if(dmg is not null)
{
dmg.Health += ev.DmgHealth;
dmg.Armor += ev.DmgArmor;
}
}
else
{
Expand Down

0 comments on commit 92abb96

Please sign in to comment.