Update readme & Rework NoRecoil
This commit is contained in:
parent
f73dd5a4df
commit
c58bff7150
7 changed files with 174 additions and 44 deletions
|
|
@ -487,7 +487,7 @@
|
|||
"returntosender": "Zwrot do Nadawcy",
|
||||
"returntosender_desc": "Pierwsze trafienie wroga powoduje, że wraca on na swój resp",
|
||||
|
||||
"rewind": "Cofnięcietruearmor",
|
||||
"rewind": "Cofnięcie",
|
||||
"rewind_desc": "Naciśnij [css_useSkill], aby zostawić znacznik i wkrótce do niego wrócić",
|
||||
"rewind_pending_info": "POWRÓT: {0}",
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ using CounterStrikeSharp.API;
|
|||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Utils;
|
||||
using src.utils;
|
||||
|
||||
using System.Collections.Concurrent;
|
||||
using static src.jRandomSkills;
|
||||
|
||||
|
|
@ -11,75 +12,164 @@ namespace src.player.skills
|
|||
{
|
||||
private const Skills skillName = Skills.NoRecoil;
|
||||
|
||||
private static readonly ConcurrentDictionary<uint, byte> holders = [];
|
||||
private static bool noSpreadActive;
|
||||
private const string NoSpreadConVar = "weapon_accuracy_nospread";
|
||||
|
||||
private static bool defaultNoSpread;
|
||||
private static readonly ConcurrentDictionary<uint, byte> holders = [];
|
||||
private static readonly ConcurrentDictionary<uint, string> originalNoSpreadValues = [];
|
||||
|
||||
public static void LoadSkill()
|
||||
{
|
||||
SkillUtils.RegisterSkill(skillName, SkillsInfo.GetValue<string>(skillName, "color"));
|
||||
defaultNoSpread = SkillUtils.CvarValue("weapon_accuracy_nospread", false);
|
||||
}
|
||||
|
||||
public static void NewRound()
|
||||
{
|
||||
foreach (var player in Utilities.GetPlayers())
|
||||
{
|
||||
if (player == null || !player.IsValid) continue;
|
||||
if (!holders.ContainsKey(player.Index)) continue;
|
||||
RestoreClientNoSpread(player);
|
||||
}
|
||||
|
||||
holders.Clear();
|
||||
ApplyNoSpread(false);
|
||||
originalNoSpreadValues.Clear();
|
||||
}
|
||||
|
||||
public static void EnableSkill(CCSPlayerController player)
|
||||
{
|
||||
if (player == null || !player.IsValid) return;
|
||||
if (!holders.TryAdd(player.Index, 0)) return;
|
||||
|
||||
holders.TryAdd(player.Index, 0);
|
||||
ApplyNoSpread(true);
|
||||
try
|
||||
{
|
||||
var currentValue = player.GetConVarValue(NoSpreadConVar);
|
||||
originalNoSpreadValues[player.Index] = string.IsNullOrWhiteSpace(currentValue) ? "0" : currentValue;
|
||||
}
|
||||
catch
|
||||
{
|
||||
originalNoSpreadValues[player.Index] = "0";
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
player.ReplicateConVar(NoSpreadConVar, "1");
|
||||
}
|
||||
catch { }
|
||||
|
||||
ResetWeaponState(player);
|
||||
ResetViewPunch(player);
|
||||
}
|
||||
|
||||
public static void DisableSkill(CCSPlayerController player)
|
||||
{
|
||||
if (player == null || !player.IsValid) return;
|
||||
|
||||
holders.TryRemove(player.Index, out _);
|
||||
if (holders.IsEmpty)
|
||||
ApplyNoSpread(false);
|
||||
|
||||
RestoreClientNoSpread(player);
|
||||
ResetWeaponState(player);
|
||||
ResetViewPunch(player);
|
||||
}
|
||||
|
||||
private static void ApplyNoSpread(bool enabled)
|
||||
private static void RestoreClientNoSpread(CCSPlayerController player)
|
||||
{
|
||||
if (noSpreadActive == enabled) return;
|
||||
if (player == null || !player.IsValid) return;
|
||||
var value = originalNoSpreadValues.TryGetValue(player.Index, out var originalValue)
|
||||
? originalValue : "0";
|
||||
|
||||
noSpreadActive = enabled;
|
||||
bool value = enabled || defaultNoSpread;
|
||||
Server.ExecuteCommand($"weapon_accuracy_nospread {(value ? 1 : 0)}");
|
||||
}
|
||||
|
||||
public static void OnTick()
|
||||
{
|
||||
foreach (var player in PlayerManager.GetTickPlayers())
|
||||
{
|
||||
if (!Instance.IsPlayerValid(player)) continue;
|
||||
var playerInfo = PlayerManager.GetPlayerByIndex(player!.Index);
|
||||
|
||||
if (playerInfo?.Skill == skillName)
|
||||
{
|
||||
var pawn = player.PlayerPawn.Value;
|
||||
if (pawn == null || !pawn.IsValid) continue;
|
||||
|
||||
if (pawn.AimPunchServices != null)
|
||||
{
|
||||
pawn.AimPunchServices.PredictableBaseTick = 0;
|
||||
pawn.AimPunchServices.PredictableBaseTickInterpAmount = 0;
|
||||
pawn.AimPunchServices.UnpredictableBaseTick = 0;
|
||||
}
|
||||
|
||||
if (pawn.CameraServices != null)
|
||||
{
|
||||
pawn.CameraServices.CsViewPunchAngleTick = 0;
|
||||
pawn.CameraServices.CsViewPunchAngleTickRatio = 0f;
|
||||
}
|
||||
}
|
||||
try {
|
||||
player.ReplicateConVar(NoSpreadConVar, value);
|
||||
originalNoSpreadValues.TryRemove(player.Index, out _);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
public static void WeaponFire(EventWeaponFire @event)
|
||||
{
|
||||
var player = PlayerManager.GetPlayerEvent(@event.Userid);
|
||||
if (player == null || !player.IsValid) return;
|
||||
if (!holders.ContainsKey(player.Index)) return;
|
||||
|
||||
var playerInfo = PlayerManager.GetPlayerByIndex(player.Index);
|
||||
if (playerInfo?.Skill != skillName) return;
|
||||
|
||||
ResetWeaponState(player);
|
||||
ResetViewPunch(player);
|
||||
}
|
||||
|
||||
private static void ResetWeaponState(CCSPlayerController player)
|
||||
{
|
||||
if (player == null || !player.IsValid) return;
|
||||
|
||||
var pawn = player.PlayerPawn.Value;
|
||||
if (pawn == null || !pawn.IsValid) return;
|
||||
|
||||
if (pawn.ShotsFired != 0)
|
||||
{
|
||||
pawn.ShotsFired = 0;
|
||||
Utilities.SetStateChanged(pawn, "CCSPlayerPawn", "m_iShotsFired");
|
||||
}
|
||||
|
||||
var weapon = pawn.WeaponServices?.ActiveWeapon.Value;
|
||||
if (weapon == null || !weapon.IsValid) return;
|
||||
|
||||
var csWeapon = weapon.As<CCSWeaponBase>();
|
||||
if (csWeapon == null || !csWeapon.IsValid) return;
|
||||
|
||||
if (csWeapon.AccuracyPenalty != 0f)
|
||||
{
|
||||
csWeapon.AccuracyPenalty = 0f;
|
||||
Utilities.SetStateChanged(weapon, "CCSWeaponBase", "m_fAccuracyPenalty");
|
||||
}
|
||||
|
||||
if (csWeapon.FlRecoilIndex != 0f)
|
||||
{
|
||||
csWeapon.FlRecoilIndex = 0f;
|
||||
Utilities.SetStateChanged(weapon, "CCSWeaponBase", "m_flRecoilIndex");
|
||||
}
|
||||
|
||||
if (csWeapon.IRecoilIndex != 0)
|
||||
{
|
||||
csWeapon.IRecoilIndex = 0;
|
||||
Utilities.SetStateChanged(weapon, "CCSWeaponBase", "m_iRecoilIndex");
|
||||
}
|
||||
|
||||
if (csWeapon.TurningInaccuracy != 0f)
|
||||
{
|
||||
csWeapon.TurningInaccuracy = 0f;
|
||||
Utilities.SetStateChanged(weapon, "CCSWeaponBase", "m_flTurningInaccuracy");
|
||||
}
|
||||
}
|
||||
|
||||
private static void ResetViewPunch(CCSPlayerController player)
|
||||
{
|
||||
if (player == null || !player.IsValid) return;
|
||||
|
||||
var pawn = player.PlayerPawn.Value;
|
||||
if (pawn == null || !pawn.IsValid) return;
|
||||
|
||||
var aim = pawn.AimPunchServices;
|
||||
if (aim != null)
|
||||
{
|
||||
Zero(aim.PredictableBaseAngle);
|
||||
Zero(aim.PredictableBaseAngleVel);
|
||||
Zero(aim.UnpredictableBaseAngle);
|
||||
Utilities.SetStateChanged(pawn, "CCSPlayerPawn", "m_pAimPunchServices");
|
||||
}
|
||||
|
||||
var camera = pawn.CameraServices;
|
||||
if (camera != null)
|
||||
{
|
||||
Zero(camera.CsViewPunchAngle);
|
||||
Utilities.SetStateChanged(pawn, "CBasePlayerPawn", "m_pCameraServices");
|
||||
}
|
||||
}
|
||||
|
||||
private static void Zero(QAngle? angle)
|
||||
{
|
||||
if (angle == null) return;
|
||||
angle.X = 0f;
|
||||
angle.Y = 0f;
|
||||
angle.Z = 0f;
|
||||
}
|
||||
|
||||
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#8a42f5", CsTeam onlyTeam = CsTeam.None, bool disableOnFreezeTime = false, bool needsTeammates = false, string requiredPermission = "", float? hudDuration = null, float? descriptionHudDuration = null, int maxPerServer = -1, Rarity rarity = Rarity.Common) : SkillsInfo.DefaultSkillInfo(skill, active, color, onlyTeam, disableOnFreezeTime, needsTeammates, requiredPermission, hudDuration, descriptionHudDuration, maxPerServer, rarity)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue