71 lines
2.4 KiB
C#
71 lines
2.4 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 RandomTeleport(IPlayerHud playerHud) : BasePower(playerHud)
|
|
{
|
|
public override int Id => 29;
|
|
public override string Name => "Random Teleport";
|
|
public override string Description => "Teleport to a random position on the map every time you get a kill!";
|
|
public override char ChatColor => ChatColors.Purple;
|
|
public override string HtmlColor => "#800080";
|
|
|
|
private readonly Random _random = new();
|
|
|
|
protected override void OnInitialize()
|
|
{
|
|
RegisterEventHandler<EventPlayerDeath>(OnPlayerDeath);
|
|
}
|
|
|
|
private HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
|
|
{
|
|
var attacker = @event.Attacker;
|
|
if (!Ensure.Player(attacker).IsValid().IsAlive().Check() || !IsAssignedTo(attacker!))
|
|
{
|
|
return HookResult.Continue;
|
|
}
|
|
|
|
var pawn = attacker!.PlayerPawn.Value;
|
|
if (pawn == null || !pawn.IsValid)
|
|
return HookResult.Continue;
|
|
|
|
// Find random valid player to teleport near
|
|
var validPlayers = Utilities.GetPlayers()
|
|
.Where(p => p.IsValid && p.PawnIsAlive && p != attacker)
|
|
.ToList();
|
|
|
|
if (validPlayers.Count > 0)
|
|
{
|
|
// Teleport near a random player
|
|
var targetPlayer = validPlayers[_random.Next(validPlayers.Count)];
|
|
var targetPos = targetPlayer.PlayerPawn.Value!.AbsOrigin!;
|
|
|
|
// Random offset of 100-300 units
|
|
var offset = new Vector(
|
|
(float)(_random.NextDouble() * 400 - 200),
|
|
(float)(_random.NextDouble() * 400 - 200),
|
|
50
|
|
);
|
|
|
|
pawn.Teleport(targetPos + offset, null, null);
|
|
}
|
|
else
|
|
{
|
|
// If no other players, teleport in a random direction from current position
|
|
var currentPos = pawn.AbsOrigin!;
|
|
var offset = new Vector(
|
|
(float)(_random.NextDouble() * 600 - 300),
|
|
(float)(_random.NextDouble() * 600 - 300),
|
|
100
|
|
);
|
|
pawn.Teleport(currentPos + offset, null, null);
|
|
}
|
|
|
|
return HookResult.Continue;
|
|
}
|
|
}
|