From 44c692b0930244ab5f6b1b8df83edd3f958d91d8 Mon Sep 17 00:00:00 2001
From: NockyCZ <63038995+NockyCZ@users.noreply.github.com>
Date: Sat, 9 Mar 2024 17:39:51 +0100
Subject: [PATCH] v1.0.9
---
source/Configs.cs | 5 ---
source/Deathmatch.cs | 2 +-
source/Events.cs | 6 +++-
source/Functions/Spawns.cs | 72 +++++++++++++++++++++++++++++++-------
4 files changed, 66 insertions(+), 19 deletions(-)
diff --git a/source/Configs.cs b/source/Configs.cs
index 3da2228..b61553e 100644
--- a/source/Configs.cs
+++ b/source/Configs.cs
@@ -174,7 +174,6 @@ public static void CreateOrLoadCustomModes(string filepath)
["only_hs"] = false,
["allow_knife_damage"] = true,
["random_weapons"] = false,
- ["allow_center_message"] = false,
["center_message_text"] = "",
["primary_weapons"] = new JArray { "weapon_aug", "weapon_sg556", "weapon_xm1014", "weapon_ak47", "weapon_famas", "weapon_galilar", "weapon_m4a1", "weapon_m4a1_silencer", "weapon_mp5sd", "weapon_mp7", "weapon_p90" },
["secondary_weapons"] = new JArray { "weapon_usp_silencer", "weapon_p250", "weapon_glock", "weapon_fiveseven", "weapon_hkp2000", "weapon_deagle" }
@@ -187,7 +186,6 @@ public static void CreateOrLoadCustomModes(string filepath)
["only_hs"] = true,
["allow_knife_damage"] = false,
["random_weapons"] = false,
- ["allow_center_message"] = true,
["center_message_text"] = "Only Headshot",
["primary_weapons"] = new JArray { "weapon_aug", "weapon_sg556", "weapon_xm1014", "weapon_ak47", "weapon_famas", "weapon_galilar", "weapon_m4a1", "weapon_m4a1_silencer", "weapon_mp5sd", "weapon_mp7", "weapon_p90" },
["secondary_weapons"] = new JArray { "weapon_usp_silencer", "weapon_p250", "weapon_glock", "weapon_fiveseven", "weapon_hkp2000", "weapon_deagle" },
@@ -200,7 +198,6 @@ public static void CreateOrLoadCustomModes(string filepath)
["only_hs"] = false,
["allow_knife_damage"] = true,
["random_weapons"] = false,
- ["allow_center_message"] = true,
["center_message_text"] = "Only Deagle",
["primary_weapons"] = new JArray { },
["secondary_weapons"] = new JArray { "weapon_deagle" },
@@ -213,7 +210,6 @@ public static void CreateOrLoadCustomModes(string filepath)
["only_hs"] = false,
["allow_knife_damage"] = true,
["random_weapons"] = false,
- ["allow_center_message"] = true,
["center_message_text"] = "Only Pistols",
["primary_weapons"] = new JArray { },
["secondary_weapons"] = new JArray { "weapon_usp_silencer", "weapon_p250", "weapon_glock", "weapon_cz75a", "weapon_elite", "weapon_fiveseven", "weapon_tec9", "weapon_hkp2000" }
@@ -226,7 +222,6 @@ public static void CreateOrLoadCustomModes(string filepath)
["only_hs"] = false,
["allow_knife_damage"] = true,
["random_weapons"] = true,
- ["allow_center_message"] = true,
["center_message_text"] = "Only SMG (Random Weapons)",
["primary_weapons"] = new JArray { "weapon_p90", "weapon_bizon", "weapon_mp5sd", "weapon_mp7", "weapon_mp9", "weapon_mac10", "weapon_ump45" },
["secondary_weapons"] = new JArray { }
diff --git a/source/Deathmatch.cs b/source/Deathmatch.cs
index 80d24d7..5c817cf 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.8";
+ public override string ModuleVersion => "1.0.9";
public static DeathmatchCore Instance { get; set; } = new();
public class ModeInfo
{
diff --git a/source/Events.cs b/source/Events.cs
index fbe56dd..ae4b3c4 100644
--- a/source/Events.cs
+++ b/source/Events.cs
@@ -101,7 +101,11 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
timer = AdminManager.PlayerHasPermissions(player, Config.PlayersSettings.VIPFlag) ? Config.PlayersSettings.RespawnTimeVIP : Config.PlayersSettings.RespawnTime;
@event.FireEventToClient(player);
}
- AddTimer(timer, () => { PerformRespawn(player, player.TeamNum, IsBot); }, TimerFlags.STOP_ON_MAPCHANGE);
+ AddTimer(timer, () =>
+ {
+ if (player != null && player.IsValid && !player.PawnIsAlive)
+ PerformRespawn(player, player.TeamNum, IsBot);
+ }, TimerFlags.STOP_ON_MAPCHANGE);
if (attacker != player && playerData.ContainsPlayer(attacker) && attacker.PlayerPawn.Value != null)
{
diff --git a/source/Functions/Spawns.cs b/source/Functions/Spawns.cs
index de8cd30..5a42a0c 100644
--- a/source/Functions/Spawns.cs
+++ b/source/Functions/Spawns.cs
@@ -21,14 +21,21 @@ public void PerformRespawn(CCSPlayerController player, int team, bool IsBot)
return;
var spawnsDictionary = team == (byte)CsTeam.Terrorist ? spawnPositionsT : spawnPositionsCT;
+
var spawnsList = spawnsDictionary.ToList();
if (!IsBot)
spawnsList.RemoveAll(x => x.Key == playerData[player].LastSpawn);
- Random random = new Random();
- spawnsList = spawnsList.OrderBy(x => random.Next()).ToList();
+ if (spawnsList.Count == 0)
+ {
+ player.Respawn();
+ SendConsoleMessage("[Deathmatch] Spawns list is empty, you got something wrong!", ConsoleColor.Red);
+ return;
+ }
- var randomSpawn = spawnsList.FirstOrDefault();
+ Random random = new Random();
+ int selectRadnomSpawn = random.Next(0, spawnsList.Count);
+ var randomSpawn = spawnsList.ElementAt(selectRadnomSpawn);
Vector position;
QAngle angle;
@@ -44,6 +51,7 @@ public void PerformRespawn(CCSPlayerController player, int team, bool IsBot)
return;
}
+ spawnsList = spawnsList.OrderBy(x => random.Next()).ToList();
var closestDistances = CalculateClosestDistances(player, spawnsList);
var Spawn = spawnsList.FirstOrDefault(spawn =>
@@ -349,18 +357,41 @@ public void LoadMapSpawns(string filepath, bool mapstart)
spawnPositionsT.Clear();
if (Config.Gameplay.DefaultSpawns)
{
- foreach (var spawn in Utilities.FindAllEntitiesByDesignerName("info_player_counterterrorist"))
+ if (IsCasualGamemode)
{
- if (spawn == null)
- return;
- spawnPositionsCT.Add($"{spawn.AbsOrigin}", $"{spawn.AbsRotation}");
+ 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}");
+ }
}
- foreach (var spawn in Utilities.FindAllEntitiesByDesignerName("info_player_terrorist"))
+ else
{
- if (spawn == null)
- return;
-
- spawnPositionsT.Add($"{spawn.AbsOrigin}", $"{spawn.AbsRotation}");
+ 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;
@@ -371,6 +402,23 @@ public void LoadMapSpawns(string filepath, bool mapstart)
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;
}
else
{