65 lines
2.1 KiB
C#
65 lines
2.1 KiB
C#
using CounterStrikeSharp.API;
|
|
using CounterStrikeSharp.API.Core;
|
|
using CounterStrikeSharp.API.Modules.Utils;
|
|
using Cs2SuperPowers.Players;
|
|
using Cs2SuperPowers.Players.PlayerValidations;
|
|
|
|
namespace Cs2SuperPowers.Powers;
|
|
|
|
public class ArmBreaker(IPlayerHud playerHud) : BasePower(playerHud)
|
|
{
|
|
public override int Id => 6;
|
|
public override string Name => "Arms Breaker";
|
|
|
|
public override string Description => $"You have 25% chance to disarm victim on hit.";
|
|
|
|
public override char ChatColor => ChatColors.LightBlue;
|
|
|
|
private readonly Random _random = new();
|
|
|
|
public override string HtmlColor => "#D6E6FF";
|
|
protected override void OnInitialize()
|
|
{
|
|
RegisterEventHandler<EventPlayerHurt>(OnPlayerHurt);
|
|
}
|
|
|
|
private HookResult OnPlayerHurt(EventPlayerHurt @event, GameEventInfo info)
|
|
{
|
|
var attacker = @event.Attacker;
|
|
var victim = @event.Userid;
|
|
|
|
if (
|
|
!Ensure.Player(victim).IsValid().IsAlive().Check() ||
|
|
!Ensure.Player(attacker).IsValid().Check() ||
|
|
attacker == victim ||
|
|
!IsAssignedTo(attacker!))
|
|
{
|
|
return HookResult.Continue;
|
|
}
|
|
|
|
// Check for at least 1 player in the opposing team
|
|
var attackerTeam = attacker!.Team;
|
|
var enemyCount = Utilities.GetPlayers().Count(p =>
|
|
p.IsValid && p.Team != CsTeam.None && p.Team != CsTeam.Spectator && p.Team != attackerTeam);
|
|
if (enemyCount < 1)
|
|
{
|
|
return HookResult.Continue;
|
|
}
|
|
|
|
if (_random.NextDouble() <= 0.25)
|
|
{
|
|
var weaponServices = victim!.PlayerPawn?.Value?.WeaponServices;
|
|
if (weaponServices?.MyWeapons == null) return HookResult.Continue;
|
|
|
|
foreach (var weapon in weaponServices.MyWeapons)
|
|
{
|
|
var weaponName = weapon.Value?.DesignerName;
|
|
if (weaponName != null && !weaponName.Contains("weapon_knife") && !weaponName.Contains("weapon_c4"))
|
|
{
|
|
victim.DropActiveWeapon();
|
|
}
|
|
}
|
|
}
|
|
return HookResult.Continue;
|
|
}
|
|
} |