62 lines
2.0 KiB
C#
62 lines
2.0 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 TeleportOnKill(IPlayerHud playerHud) : BasePower(playerHud)
|
|
{
|
|
public override int Id => 21;
|
|
public override string Name => "Teleport On Kill";
|
|
|
|
public override string Description => $"When you kill an enemy, you teleport to their location (needs at least 4 players)";
|
|
|
|
public override char ChatColor => ChatColors.Red;
|
|
|
|
public override string HtmlColor => "#FF0000";
|
|
public override int MinimumPlayersRequired => 4;
|
|
|
|
protected override void OnInitialize()
|
|
{
|
|
RegisterEventHandler<EventPlayerDeath>(OnPlayerDeath);
|
|
}
|
|
|
|
private HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
|
|
{
|
|
var attacker = @event.Attacker;
|
|
var victim = @event.Userid;
|
|
|
|
if (
|
|
!Ensure.Player(victim).IsValid().Check() ||
|
|
!Ensure.Player(attacker).IsValid().Check() ||
|
|
attacker == victim ||
|
|
!IsAssignedTo(attacker!))
|
|
{
|
|
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;
|
|
}
|
|
|
|
if (victim!.PlayerPawn?.Value != null && attacker!.PlayerPawn?.Value != null)
|
|
{
|
|
var victimPos = victim.PlayerPawn.Value.AbsOrigin;
|
|
// raise Z a bit to avoid getting stuck in the ground
|
|
if (victimPos != null)
|
|
{
|
|
victimPos.Z += 10;
|
|
attacker.PlayerPawn.Value.Teleport(victimPos, null, null);
|
|
}
|
|
}
|
|
|
|
return HookResult.Continue;
|
|
}
|
|
}
|