Refactored command handling to improve player and skill lookup logic, replaced some list operations with direct queries, and updated method signatures for clarity and null safety. The vote system was reworked to support more robust vote tracking, cooldowns, and localized chat messages. Language files were updated to add new vote-related translations. Various code style and nullability improvements were made throughout the plugin.
92 lines
No EOL
4 KiB
C#
92 lines
No EOL
4 KiB
C#
using CounterStrikeSharp.API;
|
|
using CounterStrikeSharp.API.Core;
|
|
using CounterStrikeSharp.API.Modules.Entities.Constants;
|
|
using CounterStrikeSharp.API.Modules.Utils;
|
|
using CS2TraceRay.Class;
|
|
using CS2TraceRay.Struct;
|
|
using jRandomSkills.src.player;
|
|
using System.Numerics;
|
|
using static jRandomSkills.jRandomSkills;
|
|
using Vector = CounterStrikeSharp.API.Modules.Utils.Vector;
|
|
|
|
namespace jRandomSkills
|
|
{
|
|
public class LongZeus : ISkill
|
|
{
|
|
private const Skills skillName = Skills.LongZeus;
|
|
private static readonly float maxDistance = Config.GetValue<float>(skillName, "maxDistance");
|
|
|
|
public unsafe static void LoadSkill()
|
|
{
|
|
SkillUtils.RegisterSkill(skillName, Config.GetValue<string>(skillName, "color"));
|
|
|
|
Instance.RegisterEventHandler<EventRoundFreezeEnd>((@event, info) =>
|
|
{
|
|
Instance.AddTimer(0.1f, () =>
|
|
{
|
|
foreach (var player in Utilities.GetPlayers())
|
|
{
|
|
if (!Instance.IsPlayerValid(player)) continue;
|
|
var playerInfo = Instance.SkillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
|
|
if (playerInfo?.Skill != skillName) continue;
|
|
EnableSkill(player);
|
|
}
|
|
});
|
|
|
|
return HookResult.Continue;
|
|
});
|
|
|
|
Instance.RegisterEventHandler<EventWeaponFire>((@event, info) =>
|
|
{
|
|
var player = @event.Userid;
|
|
if (!Instance.IsPlayerValid(player)) return HookResult.Continue;
|
|
|
|
var playerInfo = Instance.SkillPlayer.FirstOrDefault(p => p.SteamID == player?.SteamID);
|
|
if (playerInfo?.Skill != skillName) return HookResult.Continue;
|
|
|
|
var pawn = player!.PlayerPawn.Value;
|
|
if (pawn == null || !pawn.IsValid || pawn.AbsOrigin == null || pawn.WeaponServices == null) return HookResult.Continue;
|
|
|
|
var activeWeapon = pawn.WeaponServices.ActiveWeapon.Value;
|
|
if (activeWeapon == null || !activeWeapon.IsValid || activeWeapon.DesignerName != "weapon_taser") return HookResult.Continue;
|
|
|
|
Vector eyePos = new(pawn.AbsOrigin.X, pawn.AbsOrigin.Y, pawn.AbsOrigin.Z + pawn.ViewOffset.Z);
|
|
Vector endPos = eyePos + SkillUtils.GetForwardVector(pawn.EyeAngles) * maxDistance;
|
|
|
|
Ray ray = new(Vector3.Zero);
|
|
CTraceFilter filter = new(pawn.Index, pawn.Index)
|
|
{
|
|
m_nObjectSetMask = 0xf,
|
|
m_nCollisionGroup = (byte)CollisionGroup.COLLISION_GROUP_PLAYER_MOVEMENT,
|
|
m_nInteractsWith = pawn.GetInteractsWith(),
|
|
m_nInteractsExclude = 0,
|
|
m_nBits = 11,
|
|
m_bIterateEntities = true,
|
|
m_bHitTriggers = false,
|
|
m_nInteractsAs = 0x40000
|
|
};
|
|
|
|
filter.m_nHierarchyIds[0] = pawn.GetHierarchyId();
|
|
filter.m_nHierarchyIds[1] = 0;
|
|
CGameTrace trace = TraceRay.TraceHull(eyePos, endPos, filter, ray);
|
|
|
|
if (!trace.HitPlayer(out CCSPlayerController? target) || target == null)
|
|
return HookResult.Continue;
|
|
|
|
if (target.Handle == player.Handle) return HookResult.Continue;
|
|
SkillUtils.TakeHealth(target.PlayerPawn.Value, 9999);
|
|
return HookResult.Continue;
|
|
});
|
|
}
|
|
|
|
public static void EnableSkill(CCSPlayerController player)
|
|
{
|
|
SkillUtils.TryGiveWeapon(player, CsItem.Zeus);
|
|
}
|
|
|
|
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#6effc7", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false, float maxDistance = 4096f) : Config.DefaultSkillInfo(skill, active, color, onlyTeam, needsTeammates)
|
|
{
|
|
public float MaxDistance { get; set; } = maxDistance;
|
|
}
|
|
}
|
|
} |