52 lines
1.4 KiB
C#
52 lines
1.4 KiB
C#
using CounterStrikeSharp.API.Core;
|
|
using CounterStrikeSharp.API.Modules.Utils;
|
|
using Cs2SuperPowers.Players;
|
|
using Cs2SuperPowers.Players.PlayerValidations;
|
|
|
|
namespace Cs2SuperPowers.Powers;
|
|
|
|
public class IronBody(IPlayerHud playerHud) : BasePower(playerHud)
|
|
{
|
|
public override int Id => 18;
|
|
public override string Name => "Iron Body";
|
|
|
|
public override string Description => $"You can only be killed by headshots.";
|
|
|
|
public override char ChatColor => ChatColors.LightPurple;
|
|
|
|
public override string HtmlColor => "#8B4513";
|
|
|
|
protected override void OnInitialize()
|
|
{
|
|
RegisterEventHandler<EventPlayerHurt>(OnPlayerHurt);
|
|
}
|
|
|
|
private HookResult OnPlayerHurt(EventPlayerHurt @event, GameEventInfo info)
|
|
{
|
|
var attacker = @event.Attacker;
|
|
var victim = @event.Userid;
|
|
if (@event.Hitgroup == (int)HitGroup_t.HITGROUP_HEAD)
|
|
{
|
|
return HookResult.Continue;
|
|
}
|
|
|
|
if (
|
|
!Ensure.Player(victim).IsValid().Check() ||
|
|
!Ensure.Player(attacker).IsValid().Check() ||
|
|
attacker == victim ||
|
|
!IsAssignedTo(victim!))
|
|
{
|
|
return HookResult.Continue;
|
|
}
|
|
|
|
var playerPawn = victim!.PlayerPawn.Value;
|
|
var newHealth = playerPawn!.Health + @event.DmgHealth;
|
|
|
|
if (newHealth > 100)
|
|
newHealth = 100;
|
|
|
|
playerPawn.Health = newHealth;
|
|
return HookResult.Stop;
|
|
}
|
|
}
|