94 lines
3.3 KiB
C#
94 lines
3.3 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 FinalMission(IPlayerHud playerHud) : BasePower(playerHud)
|
|
{
|
|
public override int Id => 8;
|
|
public override string Name => "Final Mission";
|
|
|
|
public override string Description => $"Upon death, unleash a powerful explosion that eliminates all players within a specified radius, turning your sacrifice into a final act of devastation.";
|
|
|
|
public override char ChatColor => ChatColors.Purple;
|
|
|
|
public override string HtmlColor => "#F5CB42";
|
|
public override int MinimumPlayersRequired => 4;
|
|
|
|
private const float ExplosionRadius = 500.0f;
|
|
private const int ExplosionDamage = 999;
|
|
|
|
protected override void OnInitialize()
|
|
{
|
|
RegisterEventHandler<EventPlayerDeath>(OnPlayerDeath);
|
|
}
|
|
|
|
private HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
|
|
{
|
|
var player = @event.Userid;
|
|
if (!Ensure.Player(player).IsValid().Check() || !IsAssignedTo(player!))
|
|
{
|
|
return HookResult.Continue;
|
|
}
|
|
|
|
// Check for at least 4 valid (non-spectator, non-none) players total
|
|
var validPlayerCount = Utilities.GetPlayers().Count(p =>
|
|
p.IsValid && p.Team != CsTeam.None && p.Team != CsTeam.Spectator);
|
|
if (validPlayerCount < 4)
|
|
{
|
|
return HookResult.Continue;
|
|
}
|
|
|
|
var playerPawn = player!.PlayerPawn.Value;
|
|
var origin = playerPawn?.AbsOrigin;
|
|
if (playerPawn == null || origin == null)
|
|
{
|
|
return HookResult.Continue;
|
|
}
|
|
|
|
var explosionCenter = new Vector(origin.X, origin.Y, origin.Z);
|
|
Server.NextFrame(() =>
|
|
{
|
|
foreach (var target in Utilities.GetPlayers())
|
|
{
|
|
if (!Ensure.Player(target).IsValid().IsAlive().Check())
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var targetPawn = target.PlayerPawn.Value;
|
|
var targetOrigin = targetPawn?.AbsOrigin;
|
|
if (targetPawn == null || targetOrigin == null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var deltaX = targetOrigin.X - explosionCenter.X;
|
|
var deltaY = targetOrigin.Y - explosionCenter.Y;
|
|
var deltaZ = targetOrigin.Z - explosionCenter.Z;
|
|
var distanceSquared = deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
|
|
if (distanceSquared > ExplosionRadius * ExplosionRadius)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
targetPawn.Health = Math.Max(0, targetPawn.Health - ExplosionDamage);
|
|
Utilities.SetStateChanged(targetPawn, "CBaseEntity", "m_iHealth");
|
|
}
|
|
});
|
|
|
|
Server.PrintToChatAll($"{ChatColors.DarkRed}► {ChatColors.Green} {player.PlayerName}: {ChatColors.Lime}explodes!!!");
|
|
|
|
var fileNames = new[] { "radiobotfallback01", "radiobotfallback02", "radiobotfallback04" };
|
|
AddTimer(0.1f, () =>
|
|
{
|
|
var randomFile = fileNames[new Random().Next(fileNames.Length)];
|
|
player.ExecuteClientCommand($"play vo/agents/balkan/{randomFile}.vsnd");
|
|
});
|
|
|
|
return HookResult.Continue;
|
|
}
|
|
}
|