Skip to content

Commit

Permalink
Update v1.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
NockyCZ committed Jan 17, 2025
1 parent 306159b commit b4a461f
Show file tree
Hide file tree
Showing 16 changed files with 383 additions and 328 deletions.
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Build results
[Bb]in/
[Oo]bj/

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
*.sln

# OS-specific files
*.DS_Store
*.Thumbs.db

# Package files
*.nupkg
*.snupkg
58 changes: 31 additions & 27 deletions source/Deathmatch/API.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Modules.Utils;
using DeathmatchAPI;
using DeathmatchAPI.Events;
Expand Down Expand Up @@ -26,7 +27,7 @@ public void StartCustomMode(int modeId)
SetupCustomMode(modeId.ToString());
}

public void ChangeNextMode(int modeId)
public void SetNextMode(int modeId)
{
if (!Config.CustomModes.ContainsKey(modeId.ToString()))
throw new Exception($"A Custom mode with ID '{modeId}' cannot be set as next mode, because this mode does not exist!");
Expand All @@ -42,36 +43,12 @@ public void AddCustomMode(int modeId, ModeData mode)
Config.CustomModes.Add(modeId.ToString(), mode);
}

public void ChangeCheckDistance(int distance)
public void SetCheckEnemiesSpawnDistance(int distance)
{
CheckedEnemiesDistance = distance;
}

public void SetupCustomSpawns(string team, Dictionary<Vector, QAngle> spawns)
{
if (team.Equals("ct"))
{
spawnPositionsCT.Clear();
foreach (var spawn in spawns)
{
spawnPositionsCT.Add(spawn.Key, spawn.Value);
}
}
else if (team.Equals("t"))
{
spawnPositionsT.Clear();
foreach (var spawn in spawns)
{
spawnPositionsT.Add(spawn.Key, spawn.Value);
}
}
else
{
throw new Exception($"Invalid team name '{team}'! Allowed options: ct , t");
}
}

public void SwapHudMessageVisibility(bool visible)
public void SetHudMessageVisibility(bool visible)
{
VisibleHud = visible;
}
Expand All @@ -90,4 +67,31 @@ public Dictionary<string, ModeData> GetCustomModes()
{
return Config.CustomModes;
}

public int GetDefaultCheckDistance()
{
return Config.Gameplay.DistanceRespawn;
}

public void SetupCustomSpawns(List<SpawnData> spawns, bool clearSpawnsDictionary)
{
if (clearSpawnsDictionary)
{
spawnPositionsCT.Clear();
spawnPositionsT.Clear();
}

foreach (var data in spawns)
{
switch (data.Team)
{
case CsTeam.CounterTerrorist:
spawnPositionsCT[data.Position] = data.Angle;
break;
case CsTeam.Terrorist:
spawnPositionsT[data.Position] = data.Angle;
break;
}
}
}
}
7 changes: 0 additions & 7 deletions source/Deathmatch/Common/Classes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ namespace Deathmatch
{
public partial class Deathmatch
{
public class SpawnData
{
public required string team { get; set; }
public required string pos { get; set; }
public required string angle { get; set; }
}

public class DeathmatchPlayerData
{
public Dictionary<string, string> PrimaryWeapon { get; set; } = new();
Expand Down
15 changes: 13 additions & 2 deletions source/Deathmatch/Common/Collections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public partial class Deathmatch
public static Dictionary<Vector, QAngle> spawnPositionsCT = new();
public static Dictionary<Vector, QAngle> spawnPositionsT = new();
public static Dictionary<int, Vector> blockedSpawns = new();
public static PlayerCache<DeathmatchPlayerData> playerData = new();
public static Dictionary<int, DeathmatchPlayerData> playerData = new();
public static List<PreferencesData> Preferences = new();
public static List<CDynamicProp> savedSpawnsModel = new();
public static List<CPointWorldText> savedSpawnsVectorText = new();
Expand Down Expand Up @@ -51,6 +51,17 @@ public partial class Deathmatch
"negative", "enemydown", "sorry", "cheer", "compliment",
"thanks", "go_a", "go_b", "needrop", "deathcry"
};
};

readonly string[] PointsMessagesArray =
{
"Player_Point_Award_Killed_Enemy",
"Player_Point_Award_Killed_Enemy_Plural",
"Player_Point_Award_Assist_Enemy",
"Player_Point_Award_Assist_Enemy_Plural",
"Player_Point_Award_Killed_Enemy_Noweapon",
"Player_Point_Award_Killed_Enemy_Noweapon_Plural",
"Player_Point_Award_Picked_Up_Dogtag",
"Player_Point_Award_Picked_Up_Dogtag_Plural"
};
};
}
4 changes: 3 additions & 1 deletion source/Deathmatch/Configs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ public class Gameplay
[JsonPropertyName("Allow Buymenu")] public bool AllowBuyMenu { get; set; } = true;
[JsonPropertyName("Use Default Spawns")] public bool DefaultSpawns { get; set; } = false;
[JsonPropertyName("Respawn Players After New Mode")] public bool RespawnPlayersAtNewMode { get; set; } = false;
[JsonPropertyName("Spawn Protection Color")] public string SpawnProtectionColor { get; set; } = "#FFFFFF";
[JsonPropertyName("Fast Weapon Equip")] public bool FastWeaponEquip { get; set; } = true;
[JsonPropertyName("Spawn Protection Color")] public string SpawnProtectionColor { get; set; } = "";
}
public class General
{
Expand All @@ -172,6 +173,7 @@ public class General
[JsonPropertyName("Block Player ChatWheel")] public bool BlockPlayerChatWheel { get; set; } = true;
[JsonPropertyName("Remove Breakable Entities")] public bool RemoveBreakableEntities { get; set; } = true;
[JsonPropertyName("Remove Decals")] public bool RemoveDecals { get; set; } = true;
[JsonPropertyName("Remove Kill Points Message")] public bool RemovePointsMessage { get; set; } = true;
[JsonPropertyName("Force Map End")] public bool ForceMapEnd { get; set; } = false;
[JsonPropertyName("Restart Map On Plugin Load")] public bool RestartMapOnPluginLoad { get; set; } = false;
}
Expand Down
33 changes: 28 additions & 5 deletions source/Deathmatch/Deathmatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public partial class Deathmatch : BasePlugin, IPluginConfig<DeathmatchConfig>
{
public override string ModuleName => "Deathmatch Core";
public override string ModuleAuthor => "Nocky";
public override string ModuleVersion => "1.2.3";
public override string ModuleVersion => "1.2.4";

public void OnConfigParsed(DeathmatchConfig config)
{
Expand Down Expand Up @@ -110,7 +110,7 @@ public override void Load(bool hotReload)
}
SetupCustomMode(NextMode.ToString());
}
if (!string.IsNullOrEmpty(ActiveMode.CenterMessageText) && Config.CustomModes.TryGetValue(NextMode.ToString(),out var modeData))
if (!string.IsNullOrEmpty(ActiveMode.CenterMessageText) && Config.CustomModes.TryGetValue(NextMode.ToString(), out var modeData))
{
var time = TimeSpan.FromSeconds(RemainingTime);
var formattedTime = $"{time.Minutes}:{time.Seconds:D2}";//RemainingTime > 60 ? $"{time.Minutes}:{time.Seconds:D2}" : $"{time.Seconds}";
Expand All @@ -137,7 +137,7 @@ public override void Load(bool hotReload)
}
else
{
if (!GetPrefsValue(p.Slot, "HudMessages") || MenuManager.GetActiveMenu(p) != null)
if ((Config.PlayersPreferences.HudMessages.Enabled && !GetPrefsValue(p.Slot, "HudMessages")) || MenuManager.GetActiveMenu(p) != null)
continue;

if (!string.IsNullOrEmpty(ActiveMode.CenterMessageText))
Expand Down Expand Up @@ -179,6 +179,29 @@ public override void Load(bool hotReload)
}, HookMode.Pre);
}

if (Config.General.RemovePointsMessage)
{
HookUserMessage(124, um =>
{
if (IsCasualGamemode)
return HookResult.Continue;

for (int i = 0; i < um.GetRepeatedFieldCount("param"); i++)
{
var message = um.ReadString("param", i);
foreach (var msg in PointsMessagesArray)
{
if (message.Contains(msg))
{
return HookResult.Stop;
}
}

}
return HookResult.Continue;
}, HookMode.Pre);
}

if (hotReload)
{
Server.ExecuteCommand($"map {Server.MapName}");
Expand Down Expand Up @@ -206,7 +229,7 @@ public void SetupCustomMode(string modeId)
ActiveCustomMode = modeId;
NextMode = GetModeType();

if (Config.CustomModes.TryGetValue(NextMode.ToString(),out var modeData) && !string.IsNullOrEmpty(ActiveMode.CenterMessageText))
if (Config.CustomModes.TryGetValue(NextMode.ToString(), out var modeData) && !string.IsNullOrEmpty(ActiveMode.CenterMessageText))
{
ModeCenterMessage = ActiveMode.CenterMessageText.Replace("{NEXTMODE}", modeData.Name);
ModeCenterMessage = ModeCenterMessage.Replace("{REMAININGTIME}", RemainingTime.ToString());
Expand All @@ -215,7 +238,7 @@ public void SetupCustomMode(string modeId)

Server.NextFrame(() =>
{
DeathmatchAPI.Get()?.TriggerEvent(new OnCustomModeStarted(int.Parse(ActiveCustomMode)));
DeathmatchAPI.Get()?.TriggerEvent(new OnCustomModeStarted(int.Parse(ActiveCustomMode), ActiveMode));
});
}

Expand Down
1 change: 1 addition & 0 deletions source/Deathmatch/Deathmatch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit b4a461f

Please sign in to comment.