Skip to content

Commit

Permalink
v1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
NockyCZ committed Mar 16, 2024
1 parent c492cbf commit d617e42
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 62 deletions.
2 changes: 1 addition & 1 deletion source/Deathmatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public partial class DeathmatchCore : BasePlugin, IPluginConfig<DeathmatchConfig
{
public override string ModuleName => "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
{
Expand Down
2 changes: 1 addition & 1 deletion source/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions source/Functions/Players.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
112 changes: 54 additions & 58 deletions source/Functions/Spawns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Newtonsoft.Json.Linq;
using System.Numerics;
using CounterStrikeSharp.API.Modules.Utils;
using CounterStrikeSharp.API.Modules.Timers;

namespace Deathmatch
{
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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<CInfoPlayerTerrorist>("info_player_counterterrorist"))
{
if (spawn == null)
return;
spawnPositionsCT.Add($"{spawn.AbsOrigin}", $"{spawn.AbsRotation}");
}
foreach (var spawn in Utilities.FindAllEntitiesByDesignerName<CInfoPlayerTerrorist>("info_player_terrorist"))
{
if (spawn == null)
return;

spawnPositionsT.Add($"{spawn.AbsOrigin}", $"{spawn.AbsRotation}");
}
}
else
{
int randomizer = 0;
foreach (var spawn in Utilities.FindAllEntitiesByDesignerName<CInfoDeathmatchSpawn>("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<CInfoPlayerTerrorist>("info_player_counterterrorist"))
{
if (spawn == null)
return;
spawnPositionsCT.Add($"{spawn.AbsOrigin}", $"{spawn.AbsRotation}");
}
foreach (var spawn in Utilities.FindAllEntitiesByDesignerName<CInfoPlayerTerrorist>("info_player_terrorist"))
{
if (spawn == null)
return;

spawnPositionsT.Add($"{spawn.AbsOrigin}", $"{spawn.AbsRotation}");
}

g_iTotalCTSpawns = spawnPositionsCT.Count;
g_iTotalTSpawns = spawnPositionsT.Count;
addDefaultSpawnsToList();
}
else
{
Expand Down Expand Up @@ -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<CInfoPlayerTerrorist>("info_player_counterterrorist"))
{
if (spawn == null)
return;
spawnPositionsCT.Add($"{spawn.AbsOrigin}", $"{spawn.AbsRotation}");
}
foreach (var spawn in Utilities.FindAllEntitiesByDesignerName<CInfoPlayerTerrorist>("info_player_terrorist"))
{
if (spawn == null)
return;
spawnPositionsT.Add($"{spawn.AbsOrigin}", $"{spawn.AbsRotation}");
}
}
else
{
int randomizer = 0;
foreach (var spawn in Utilities.FindAllEntitiesByDesignerName<CInfoDeathmatchSpawn>("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;
}
}
}

0 comments on commit d617e42

Please sign in to comment.