From d617e42268941854007a7f1e2cba2cbb1d8bdb71 Mon Sep 17 00:00:00 2001 From: NockyCZ <63038995+NockyCZ@users.noreply.github.com> Date: Sat, 16 Mar 2024 15:04:35 +0100 Subject: [PATCH] v1.1.1 --- source/Deathmatch.cs | 2 +- source/Events.cs | 2 +- source/Functions/Players.cs | 5 +- source/Functions/Spawns.cs | 112 +++++++++++++++++------------------- 4 files changed, 59 insertions(+), 62 deletions(-) diff --git a/source/Deathmatch.cs b/source/Deathmatch.cs index 5c817cf..49c84d0 100644 --- a/source/Deathmatch.cs +++ b/source/Deathmatch.cs @@ -17,7 +17,7 @@ public partial class DeathmatchCore : BasePlugin, IPluginConfig "Deathmatch Core"; public override string ModuleAuthor => "Nocky"; - public override string ModuleVersion => "1.0.9"; + public override string ModuleVersion => "1.1.1"; public static DeathmatchCore Instance { get; set; } = new(); public class ModeInfo { diff --git a/source/Events.cs b/source/Events.cs index ae4b3c4..0deb656 100644 --- a/source/Events.cs +++ b/source/Events.cs @@ -84,7 +84,7 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info) CCSPlayerController attacker = @event.Attacker; info.DontBroadcast = true; - if (player == null && !player!.IsValid) + if (player == null || !player.IsValid) return HookResult.Continue; var timer = Config.PlayersSettings.RespawnTime; diff --git a/source/Functions/Players.cs b/source/Functions/Players.cs index 70859ba..2dd5792 100644 --- a/source/Functions/Players.cs +++ b/source/Functions/Players.cs @@ -317,10 +317,11 @@ public void GivePlayerWeapons(CCSPlayerController player, bool bNewMode) AddTimer(0.2f, () => { - if (player == null && !player!.IsValid) + if (player == null || !player.IsValid) return; - player!.InGameMoneyServices!.Account = 0; + if (player.InGameMoneyServices != null) + player.InGameMoneyServices.Account = 0; int slot = IsHaveWeaponFromSlot(player, slot: 0); if (slot == 1 || slot == 2) diff --git a/source/Functions/Spawns.cs b/source/Functions/Spawns.cs index 5a42a0c..578f493 100644 --- a/source/Functions/Spawns.cs +++ b/source/Functions/Spawns.cs @@ -7,6 +7,7 @@ using Newtonsoft.Json.Linq; using System.Numerics; using CounterStrikeSharp.API.Modules.Utils; +using CounterStrikeSharp.API.Modules.Timers; namespace Deathmatch { @@ -39,7 +40,7 @@ public void PerformRespawn(CCSPlayerController player, int team, bool IsBot) Vector position; QAngle angle; - if (GameRules().WarmupPeriod || !Config.Gameplay.CheckDistance || !g_bDefaultMapSpawnDisabled || Config.Gameplay.DefaultSpawns) + if (GameRules().WarmupPeriod || !Config.Gameplay.CheckDistance) { if (!IsBot) playerData[player].LastSpawn = randomSpawn.Key; @@ -48,6 +49,13 @@ public void PerformRespawn(CCSPlayerController player, int team, bool IsBot) position = ParseVector(randomSpawn.Key); angle = ParseQAngle(randomSpawn.Value); player.PlayerPawn.Value!.Teleport(position, angle, new Vector(0, 0, 0)); + spawnsDictionary.Remove(randomSpawn.Key); + + AddTimer(5.0f, () => + { + if (!spawnsDictionary.ContainsKey(randomSpawn.Key)) + spawnsDictionary.Add(randomSpawn.Key, randomSpawn.Value); + }, TimerFlags.STOP_ON_MAPCHANGE); return; } @@ -357,68 +365,14 @@ public void LoadMapSpawns(string filepath, bool mapstart) spawnPositionsT.Clear(); if (Config.Gameplay.DefaultSpawns) { - if (IsCasualGamemode) - { - foreach (var spawn in Utilities.FindAllEntitiesByDesignerName("info_player_counterterrorist")) - { - if (spawn == null) - return; - spawnPositionsCT.Add($"{spawn.AbsOrigin}", $"{spawn.AbsRotation}"); - } - foreach (var spawn in Utilities.FindAllEntitiesByDesignerName("info_player_terrorist")) - { - if (spawn == null) - return; - - spawnPositionsT.Add($"{spawn.AbsOrigin}", $"{spawn.AbsRotation}"); - } - } - else - { - int randomizer = 0; - foreach (var spawn in Utilities.FindAllEntitiesByDesignerName("info_deathmatch_spawn")) - { - randomizer++; - if (randomizer % 2 == 0) - { - if (spawn == null) - return; - spawnPositionsT.Add($"{spawn.AbsOrigin}", $"{spawn.AbsRotation}"); - } - else - { - if (spawn == null) - return; - spawnPositionsCT.Add($"{spawn.AbsOrigin}", $"{spawn.AbsRotation}"); - } - } - } - - g_iTotalCTSpawns = spawnPositionsCT.Count; - g_iTotalTSpawns = spawnPositionsT.Count; + addDefaultSpawnsToList(); } else { if (!File.Exists(filepath)) { SendConsoleMessage($"[Deathmatch] No spawn points found for this map! (Deathmatch/spawns/{Server.MapName}.json)", ConsoleColor.Red); - - foreach (var spawn in Utilities.FindAllEntitiesByDesignerName("info_player_counterterrorist")) - { - if (spawn == null) - return; - spawnPositionsCT.Add($"{spawn.AbsOrigin}", $"{spawn.AbsRotation}"); - } - foreach (var spawn in Utilities.FindAllEntitiesByDesignerName("info_player_terrorist")) - { - if (spawn == null) - return; - - spawnPositionsT.Add($"{spawn.AbsOrigin}", $"{spawn.AbsRotation}"); - } - - g_iTotalCTSpawns = spawnPositionsCT.Count; - g_iTotalTSpawns = spawnPositionsT.Count; + addDefaultSpawnsToList(); } else { @@ -487,12 +441,54 @@ private static Vector3 ParseVector3(string pos) return new Vector3(0, 0, 0); } - static double GetDistance(Vector v1, Vector v2) + private static double GetDistance(Vector v1, Vector v2) { double X = v1.X - v2.X; double Y = v1.Y - v2.Y; return Math.Sqrt(X * X + Y * Y); } + + public void addDefaultSpawnsToList() + { + if (IsCasualGamemode) + { + foreach (var spawn in Utilities.FindAllEntitiesByDesignerName("info_player_counterterrorist")) + { + if (spawn == null) + return; + spawnPositionsCT.Add($"{spawn.AbsOrigin}", $"{spawn.AbsRotation}"); + } + foreach (var spawn in Utilities.FindAllEntitiesByDesignerName("info_player_terrorist")) + { + if (spawn == null) + return; + spawnPositionsT.Add($"{spawn.AbsOrigin}", $"{spawn.AbsRotation}"); + } + } + else + { + int randomizer = 0; + foreach (var spawn in Utilities.FindAllEntitiesByDesignerName("info_deathmatch_spawn")) + { + randomizer++; + if (randomizer % 2 == 0) + { + if (spawn == null) + return; + spawnPositionsT.Add($"{spawn.AbsOrigin}", $"{spawn.AbsRotation}"); + } + else + { + if (spawn == null) + return; + spawnPositionsCT.Add($"{spawn.AbsOrigin}", $"{spawn.AbsRotation}"); + } + } + } + + g_iTotalCTSpawns = spawnPositionsCT.Count; + g_iTotalTSpawns = spawnPositionsT.Count; + } } } \ No newline at end of file