fighting crashes #1

This commit is contained in:
Juzlus 2026-04-28 18:58:21 +02:00
parent 10dbf6629e
commit 0fb3d63cd8
145 changed files with 677278 additions and 1703 deletions

View file

@ -1,9 +1,11 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Entities;
using CounterStrikeSharp.API.Modules.Timers;
using CounterStrikeSharp.API.Modules.Utils;
using src.utils;
using System.Collections.Concurrent;
using static src.jRandomSkills;
using Timer = CounterStrikeSharp.API.Modules.Timers.Timer;
namespace src.player.skills
{
@ -11,6 +13,7 @@ namespace src.player.skills
{
private const Skills skillName = Skills.Phoenix;
private static readonly object setLock = new();
private static readonly ConcurrentDictionary<ulong, Timer> timers = [];
public static void LoadSkill()
{
@ -29,14 +32,75 @@ namespace src.player.skills
{
lock (setLock)
{
ulong steamID = player.SteamID;
int team = player.TeamNum;
if (team != 2 && team != 3) return;
player.Respawn();
ulong steamId = player.SteamID;
Instance.AddTimer(.2f, () => {
var player = Utilities.GetPlayerFromSteamId(steamId);
if (player == null || !player.IsValid) return;
Server.NextFrame(() => {
lock (setLock)
{
var player = Utilities.GetPlayerFromSteamId(steamID);
if (player == null || !player.IsValid || !player.PlayerPawn.IsValid) return;
player.Respawn();
var pawn = player.PlayerPawn.Value;
if (pawn == null || !pawn.IsValid) return;
bool isBlock = team != player.TeamNum || player.TeamChanged;
player.Respawn();
if (isBlock)
{
pawn.Flags |= (uint)Flags_t.FL_FROZEN;
pawn.Teleport(new Vector(0, 0, -1000), new QAngle(90, 0, 0));
bool isFreezeTime = Instance.GameRules != null && Instance.GameRules.FreezePeriod == true;
if (!isFreezeTime)
{
Server.NextFrame(() =>
{
if (pawn == null || !pawn.IsValid) return;
pawn.CommitSuicide(false, true);
});
return;
}
ulong steamId = player.SteamID;
if (!timers.ContainsKey(player.SteamID))
{
var timer = Instance.AddTimer(1f, () =>
{
if (player == null || !player.IsValid || pawn == null || !pawn.IsValid)
{
if (timers.TryRemove(steamId, out var t))
t.Kill();
return;
}
bool isFreezeTime = Instance.GameRules != null && Instance.GameRules.FreezePeriod == true;
if (!isFreezeTime)
{
if (timers.TryRemove(steamId, out var t))
t.Kill();
pawn.CommitSuicide(false, true);
return;
}
}, TimerFlags.STOP_ON_MAPCHANGE | TimerFlags.REPEAT);
timers.TryAdd(player.SteamID, timer);
}
return;
}
}
});
SkillUtils.PrintToChat(player, player.GetTranslation("phoenix_respawn"));
@ -55,7 +119,7 @@ namespace src.player.skills
border: !Utilities.GetPlayers().Any(p => p.Team == player.Team && !p.IsBot && p != player) ? "tb" : "t");
}
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#ff5C0A", CsTeam onlyTeam = CsTeam.None, bool disableOnFreezeTime = false, bool needsTeammates = false, string requiredPermission = "", float chanceFrom = .2f, float chanceTo = .4f) : SkillsInfo.DefaultSkillInfo(skill, active, color, onlyTeam, disableOnFreezeTime, needsTeammates, requiredPermission)
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#ff5C0A", CsTeam onlyTeam = CsTeam.None, bool disableOnFreezeTime = false, bool needsTeammates = false, string requiredPermission = "", int maxPerServer = -1, Rarity rarity = Rarity.Common, float chanceFrom = .2f, float chanceTo = .4f) : SkillsInfo.DefaultSkillInfo(skill, active, color, onlyTeam, disableOnFreezeTime, needsTeammates, requiredPermission, maxPerServer, rarity)
{
public float ChanceFrom { get; set; } = chanceFrom;
public float ChanceTo { get; set; } = chanceTo;