Files
CS2-SuperPowers/Powers/ExplosiveBullets.cs
T
2026-07-26 23:47:38 +02:00

71 lines
2.2 KiB
C#

using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using Cs2SuperPowers.Players;
using Cs2SuperPowers.Utils;
using Cs2SuperPowers.Players.PlayerValidations;
namespace Cs2SuperPowers.Powers;
public class ExplosiveBullets(IPlayerHud playerHud) : BasePower(playerHud)
{
public override int Id => 30;
public override string Name => "Explosive Bullets";
public override string Description => "Every bullet hit causes a small explosion.";
public override char ChatColor => ChatColors.Orange;
public override string HtmlColor => "#FF4500";
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(attacker).IsValid().Check() ||
!Ensure.Player(victim).IsValid().Check() ||
attacker == victim ||
!IsAssignedTo(attacker!))
{
return HookResult.Continue;
}
if (string.IsNullOrWhiteSpace(@event.Weapon) || @event.Weapon.Contains("grenade", StringComparison.OrdinalIgnoreCase))
{
return HookResult.Continue;
}
var attackerPawn = attacker!.PlayerPawn.Value;
var victimPawn = victim!.PlayerPawn.Value;
if (victimPawn == null || attackerPawn == null)
return HookResult.Continue;
var pos = victimPawn.AbsOrigin;
if (pos == null)
return HookResult.Continue;
pos.Z += 20;
// Create explosion with a small grenade at victim's position
var ang = new QAngle(0, 0, 0);
var velocity = new Vector(0, 0, 0);
var grenade = GrenadeSpawner.CreateGrenade(pos, ang, velocity, attackerPawn);
// Detonate it immediately
Server.NextFrame(() =>
{
if (grenade != null && grenade.IsValid)
{
grenade.AcceptInput("InitializeSpawnFromWorld", attackerPawn, attackerPawn);
grenade.DetonateTime = 0;
}
});
return HookResult.Continue;
}
}