Skip to content

Commit 14b11d6

Browse files
committed
Update v1.2.9
1 parent d4e6a0d commit 14b11d6

File tree

11 files changed

+98
-63
lines changed

11 files changed

+98
-63
lines changed

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ Designed for <a href="https://github.com/roflmuffin/CounterStrikeSharp">CounterS
7676
"Allow Buymenu": true,
7777
"Respawn Players After New Mode": false,
7878
"Fast Weapon Equip": true,
79-
"Spawn Protection Color": ""
79+
"Spawn Protection Color": "",
80+
"Display All Kill Feed": false
8081
},
8182
"Spawn System": {
8283
"Spawns Method": 0,
@@ -105,7 +106,15 @@ Designed for <a href="https://github.com/roflmuffin/CounterStrikeSharp">CounterS
105106
"Custom Commands": {
106107
"Deatmatch Menu Commands": "dm,deathmatch",
107108
"Weapons Select Commands": "gun,weapon,w,g",
108-
"Weapons Select Shortcuts": "weapon_ak47:ak,weapon_m4a1:m4,weapon_m4a1_silencer:m4a1,weapon_awp:awp,weapon_usp_silencer:usp,weapon_glock:glock,weapon_deagle:deagle"
109+
"Weapons Select Shortcuts": {
110+
"ak": "weapon_ak47",
111+
"m4": "weapon_m4a1",
112+
"m4a1": "weapon_m4a1_silencer",
113+
"awp": "weapon_awp",
114+
"usp": "weapon_usp_silencer",
115+
"glock": "weapon_glock",
116+
"deagle": "weapon_deagle"
117+
}
109118
},
110119
"Players Gameplay Settings": {
111120
"VIP Flag": "@css/vip",

source/Deathmatch/API.cs

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
using DeathmatchAPI;
66
using DeathmatchAPI.Events;
77
using DeathmatchAPI.Helpers;
8+
using Newtonsoft.Json;
9+
using Newtonsoft.Json.Linq;
810
using static DeathmatchAPI.Preferences;
911

1012
namespace Deathmatch;
@@ -92,25 +94,11 @@ public bool GetDefaultCheckSpawnVisibility()
9294
public void SetupCustomSpawns(List<SpawnData> spawns, bool clearSpawnsDictionary)
9395
{
9496
if (clearSpawnsDictionary)
95-
{
96-
/*foreach (var data in spawnPoints)
97-
{
98-
var entity = data.Entity;
99-
if (entity != null && entity.IsValid)
100-
entity.AcceptInput("Kill");
101-
102-
}*/
103-
spawnPoints.Clear();
104-
}
97+
spawnPoints = spawns;
98+
else
99+
spawnPoints = spawnPoints.Concat(spawns).ToList();
105100

106-
spawnPoints = spawns;
107-
foreach (var data in spawnPoints)
108-
{
109-
if (data.Entity != null && data.Entity.IsValid)
110-
continue;
111-
data.Entity = CreateSpawnEntity(data.Position, data.Angle, data.Team);
112-
}
113-
RemoveUnusedSpawns();
101+
DisableDefaultSpawns();
114102
}
115103

116104
public Preference? RegisterPreference(string name, PreferencesBooleanData data, bool vipOnly = false)
@@ -211,4 +199,45 @@ public void AddMenuOption(string name, Categorie? category, Action<CCSPlayerCont
211199
{
212200
Menu.AddOption(name, category, onChoose);
213201
}
202+
203+
public List<SpawnData> GetActiveSpawns()
204+
{
205+
return spawnPoints;
206+
}
207+
208+
public List<SpawnData> GetDefaultSpawns()
209+
{
210+
if (Config.SpawnSystem.SpawnsMethod >= 1)
211+
{
212+
return spawnPoints;
213+
}
214+
else if (!File.Exists(SpawnsPath))
215+
{
216+
return spawnPoints;
217+
}
218+
else
219+
{
220+
var jsonContent = File.ReadAllText(SpawnsPath);
221+
JObject jsonData = JsonConvert.DeserializeObject<JObject>(jsonContent)!;
222+
223+
var spawns = new List<SpawnData>();
224+
foreach (var teamData in jsonData["spawnpoints"]!)
225+
{
226+
var team = teamData["team"]?.ToString() == "ct" ? CsTeam.CounterTerrorist : CsTeam.Terrorist;
227+
var pos = ParseVector(teamData["pos"]!.ToString());
228+
var angle = ParseQAngle(teamData["angle"]!.ToString());
229+
230+
var spawn = new SpawnData()
231+
{
232+
Team = team,
233+
Position = pos,
234+
Angle = angle,
235+
};
236+
237+
CreateSpawnEntity(pos, angle, team);
238+
spawns.Add(spawn);
239+
}
240+
return spawns;
241+
}
242+
}
214243
}

source/Deathmatch/Common/Globals.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public partial class Deathmatch
2323
public static bool CheckSpawnVisibility;
2424
public static bool IsCasualGamemode;
2525
public static bool DefaultMapSpawnDisabled = false;
26+
public static string SpawnsPath = "";
2627
public static ModeData ActiveMode = new();
2728
}
2829
}

source/Deathmatch/Configs.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ public class Gameplay
173173
[JsonPropertyName("Respawn Players After New Mode")] public bool RespawnPlayersAtNewMode { get; set; } = false;
174174
[JsonPropertyName("Fast Weapon Equip")] public bool FastWeaponEquip { get; set; } = true;
175175
[JsonPropertyName("Spawn Protection Color")] public string SpawnProtectionColor { get; set; } = "";
176+
[JsonPropertyName("Display All Kill Feed")] public bool DisplayAllKillFeed { get; set; } = false;
176177
}
177178
public class General
178179
{

source/Deathmatch/Deathmatch.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public partial class Deathmatch : BasePlugin, IPluginConfig<DeathmatchConfig>
2020
{
2121
public override string ModuleName => "Deathmatch Core";
2222
public override string ModuleAuthor => "Nocky";
23-
public override string ModuleVersion => "1.2.8a";
23+
public override string ModuleVersion => "1.2.9";
2424

2525
public void OnConfigParsed(DeathmatchConfig config)
2626
{
@@ -75,6 +75,7 @@ public override void Load(bool hotReload)
7575

7676
AddTimer(3.0f, () =>
7777
{
78+
SpawnsPath = ModuleDirectory + $"/spawns/{mapName}.json";
7879
SetupCustomMode(Config.Gameplay.MapStartMode.ToString());
7980
SetupDeathMatchConfigValues();
8081
RemoveEntities();

source/Deathmatch/Events.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
9090
{
9191
var player = @event.Userid;
9292
var attacker = @event.Attacker;
93-
info.DontBroadcast = true;
93+
if (Config.Gameplay.DisplayAllKillFeed)
94+
info.DontBroadcast = true;
9495

9596
if (player == null || !player.IsValid)
9697
return HookResult.Continue;
@@ -126,7 +127,9 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
126127
}
127128
}
128129
timer = IsVIP ? Config.PlayersSettings.VIP.RespawnTime : Config.PlayersSettings.NonVIP.RespawnTime;
129-
@event.FireEventToClient(player);
130+
131+
if (Config.Gameplay.DisplayAllKillFeed)
132+
@event.FireEventToClient(player);
130133
}
131134

132135
playersWaitingForRespawn[player] = (timer, Server.CurrentTime);
@@ -205,7 +208,9 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
205208
string armor = ActiveMode.Armor == 1 ? "item_kevlar" : "item_assaultsuit";
206209
attacker.GiveNamedItem(armor);
207210
}
208-
@event.FireEventToClient(attacker);
211+
212+
if (Config.Gameplay.DisplayAllKillFeed)
213+
@event.FireEventToClient(attacker);
209214
}
210215
return HookResult.Continue;
211216
}

source/Deathmatch/Functions/Commands.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,11 @@ public void OnEditor_CMD(CCSPlayerController player, CommandInfo info)
167167
OpenEditorMenu(player);
168168
}
169169

170-
[ConsoleCommand("css_test", "")]
170+
/*[ConsoleCommand("css_test", "")]
171171
[CommandHelper(whoCanExecute: CommandUsage.CLIENT_ONLY)]
172172
public void test_CMD(CCSPlayerController player, CommandInfo info)
173173
{
174-
player.PrintToCenter("čus");
175-
/*var targetString = info.GetArg(1);
174+
var targetString = info.GetArg(1);
176175
var target = Utilities.GetPlayers().FirstOrDefault(p => p.PlayerName.Contains(targetString));
177176
if (target == null)
178177
{
@@ -181,7 +180,7 @@ public void test_CMD(CCSPlayerController player, CommandInfo info)
181180
}
182181
183182
var result = CanSeeSpawn(player.PlayerPawn.Value, target.PlayerPawn.Value.AbsOrigin);
184-
info.ReplyToCommand($"result {target.PlayerName}: {result}");*/
185-
}
183+
info.ReplyToCommand($"result {target.PlayerName}: {result}");
184+
}*/
186185
}
187186
}

source/Deathmatch/Functions/Menus.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,28 @@ public void OpenEditorMenu(CCSPlayerController? player)
3636
{
3737
AddNewSpawnPoint(player.PlayerPawn.Value?.AbsOrigin!, player.PlayerPawn.Value?.AbsRotation!, CsTeam.CounterTerrorist);
3838
player.PrintToChat($"{Localizer["Chat.Prefix"]} Spawn for the {ChatColors.DarkBlue}CT team{ChatColors.Default} has been added. (Total: {ChatColors.Green}{spawnPoints.Count(x => x.Team == CsTeam.CounterTerrorist)}{ChatColors.Default})");
39-
RemoveUnusedSpawns();
39+
DisableDefaultSpawns();
4040
OpenEditorMenu(player);
4141
});
4242
Menu.AddMenuOption($"Add T Spawn ({tSpawns})", (player, opt) =>
4343
{
4444
AddNewSpawnPoint(player.PlayerPawn.Value?.AbsOrigin!, player.PlayerPawn.Value?.AbsRotation!, CsTeam.Terrorist);
4545
player.PrintToChat($"{Localizer["Chat.Prefix"]} Spawn for the {ChatColors.Orange}T team{ChatColors.Default} has been added. (Total: {ChatColors.Green}{spawnPoints.Count(x => x.Team == CsTeam.Terrorist)}{ChatColors.Default})");
46-
RemoveUnusedSpawns();
46+
DisableDefaultSpawns();
4747
OpenEditorMenu(player);
4848
});
4949

5050
Menu.AddMenuOption("Remove the Nearest Spawn", (player, opt) =>
5151
{
5252
RemoveNearestSpawnPoint(player.PlayerPawn.Value!.AbsOrigin);
5353
player.PrintToChat($"{Localizer["Chat.Prefix"]} The nearest spawn point has been removed!");
54-
RemoveUnusedSpawns();
54+
DisableDefaultSpawns();
5555
OpenEditorMenu(player);
5656
});
5757

5858
Menu.AddMenuOption("<font class='fontSize-m' color='cyan'>Save Spawns</font>", (player, opt) =>
5959
{
6060
SaveSpawnsFile();
61-
LoadMapSpawns(ModuleDirectory + $"/spawns/{Server.MapName}.json");
6261
player.PrintToChat($"{Localizer["Chat.Prefix"]} Spawns have been successfully saved!");
6362
RemoveSpawnModels();
6463
MenuManager.CloseActiveMenu(player);

source/Deathmatch/Functions/Spawns.cs

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void PerformRespawn(CCSPlayerController player, CsTeam team)
103103
}
104104

105105
SendConsoleMessage($"[Deathmatch] Player {player.PlayerName} was respawned, but no available spawn point was found!", ConsoleColor.DarkYellow);
106-
return null;
106+
return spawnsList.FirstOrDefault();
107107
}
108108

109109
public void SaveSpawnsFile()
@@ -138,7 +138,6 @@ public void AddNewSpawnPoint(Vector posValue, QAngle angleValue, CsTeam team)
138138
{
139139
if (!DefaultMapSpawnDisabled)
140140
{
141-
DefaultMapSpawnDisabled = true;
142141
spawnPoints.Clear();
143142
}
144143

@@ -227,29 +226,24 @@ public void ShowAllSpawnPoints()
227226
}
228227
}
229228

230-
public static void RemoveUnusedSpawns(bool defaultSpawns = false)
229+
public static void DisableDefaultSpawns()
231230
{
231+
if (DefaultMapSpawnDisabled)
232+
return;
233+
232234
var spawns = Utilities.FindAllEntitiesByDesignerName<SpawnPoint>("info_player_counterterrorist").Concat(Utilities.FindAllEntitiesByDesignerName<SpawnPoint>("info_player_terrorist")).Concat(Utilities.FindAllEntitiesByDesignerName<SpawnPoint>("info_deathmatch_spawn"));
233235
int DMSpawns = 0;
234236
foreach (var entity in spawns)
235237
{
236238
if (entity == null || !entity.IsValid)
237239
continue;
238240

239-
if (spawnPoints.Any(x => x.Entity == entity))
240-
entity.AcceptInput("SetEnabled");
241-
else
242-
{
243-
entity.AcceptInput("SetDisabled");
244-
DMSpawns++;
245-
}
241+
entity.AcceptInput("SetDisabled");
242+
DMSpawns++;
246243
}
247244

248-
if (defaultSpawns)
249-
{
250-
SendConsoleMessage($"[Deathmatch] Total {DMSpawns} Default Spawns disabled!", ConsoleColor.Green);
251-
DefaultMapSpawnDisabled = true;
252-
}
245+
SendConsoleMessage($"[Deathmatch] Total {DMSpawns} Default Spawns disabled!", ConsoleColor.Green);
246+
DefaultMapSpawnDisabled = true;
253247
}
254248

255249
/*public static void CreateCustomMapSpawns()
@@ -284,7 +278,7 @@ public static void RemoveUnusedSpawns(bool defaultSpawns = false)
284278
}
285279
}*/
286280

287-
public SpawnPoint? CreateSpawnEntity(Vector Postion, QAngle Angle, CsTeam team)
281+
public void CreateSpawnEntity(Vector Postion, QAngle Angle, CsTeam team)
288282
{
289283
var entityName = "info_deathmatch_spawn";
290284
if (IsCasualGamemode)
@@ -294,11 +288,10 @@ public static void RemoveUnusedSpawns(bool defaultSpawns = false)
294288
if (entity == null)
295289
{
296290
SendConsoleMessage($"[Deathmatch] Failed to create spawn point!", ConsoleColor.DarkYellow);
297-
return null;
291+
return;
298292
}
299293
entity.Teleport(Postion, Angle, new Vector(0, 0, 0));
300294
entity.DispatchSpawn();
301-
return entity;
302295
}
303296

304297
public void LoadMapSpawns(string filePath)
@@ -317,6 +310,7 @@ public void LoadMapSpawns(string filePath)
317310
}
318311
else
319312
{
313+
DisableDefaultSpawns();
320314
SendConsoleMessage($"[Deathmatch] Loading Custom Map Spawns..", ConsoleColor.DarkYellow);
321315

322316
var jsonContent = File.ReadAllText(filePath);
@@ -333,13 +327,13 @@ public void LoadMapSpawns(string filePath)
333327
Team = team,
334328
Position = pos,
335329
Angle = angle,
336-
Entity = CreateSpawnEntity(pos, angle, team)
337330
};
331+
338332
spawnPoints.Add(spawn);
333+
CreateSpawnEntity(pos, angle, team);
339334
}
340335

341336
SendConsoleMessage($"[Deathmatch] Total Loaded Custom Spawns: CT {spawnPoints.Count(x => x.Team == CsTeam.CounterTerrorist)} | T {spawnPoints.Count(x => x.Team == CsTeam.Terrorist)}", ConsoleColor.Green);
342-
RemoveUnusedSpawns(true);
343337
}
344338
}
345339

@@ -403,8 +397,7 @@ public void addDefaultSpawnsToList()
403397
{
404398
Position = spawn.AbsOrigin,
405399
Angle = spawn.AbsRotation,
406-
Team = CsTeam.CounterTerrorist,
407-
Entity = spawn
400+
Team = CsTeam.CounterTerrorist
408401
};
409402
spawnPoints.Add(data);
410403
}
@@ -417,8 +410,7 @@ public void addDefaultSpawnsToList()
417410
{
418411
Position = spawn.AbsOrigin,
419412
Angle = spawn.AbsRotation,
420-
Team = CsTeam.Terrorist,
421-
Entity = spawn
413+
Team = CsTeam.Terrorist
422414
};
423415
spawnPoints.Add(data);
424416
}
@@ -438,8 +430,7 @@ public void addDefaultSpawnsToList()
438430
{
439431
Position = spawn.AbsOrigin,
440432
Angle = spawn.AbsRotation,
441-
Team = CsTeam.Terrorist,
442-
Entity = spawn
433+
Team = CsTeam.Terrorist
443434
};
444435
spawnPoints.Add(data);
445436
}
@@ -451,8 +442,7 @@ public void addDefaultSpawnsToList()
451442
{
452443
Position = spawn.AbsOrigin,
453444
Angle = spawn.AbsRotation,
454-
Team = CsTeam.CounterTerrorist,
455-
Entity = spawn
445+
Team = CsTeam.CounterTerrorist
456446
};
457447
spawnPoints.Add(data);
458448
}

source/DeathmatchAPI/DeathmatchAPI.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public interface IDeathmatchAPI
3030
public int GetDefaultCheckDistance();
3131
public bool GetDefaultCheckSpawnVisibility();
3232
public void ToggleSpawnsDisplay(bool visible);
33+
public List<SpawnData> GetActiveSpawns();
34+
public List<SpawnData> GetDefaultSpawns();
3335
public Dictionary<string, ModeData> GetCustomModes();
3436
public event EventHandler<IDeathmatchEventsAPI> DeathmatchEventHandlers;
3537
public void TriggerEvent(IDeathmatchEventsAPI @event);

0 commit comments

Comments
 (0)