Skip to content

Commit

Permalink
Update v1.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
NockyCZ committed Dec 28, 2024
1 parent cb91a1b commit 6628418
Show file tree
Hide file tree
Showing 12 changed files with 374 additions and 263 deletions.
7 changes: 7 additions & 0 deletions source/Deathmatch/Common/Classes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@ public class DeathmatchPlayerData
public Dictionary<string, string> PrimaryWeapon { get; set; } = new();
public Dictionary<string, string> SecondaryWeapon { get; set; } = new();
public Dictionary<string, bool> Preferences { get; set; } = new();
public Dictionary<int, DamageData> DamageInfo { get; set; } = new();
public bool SpawnProtection { get; set; } = false;
public int KillStreak { get; set; } = 0;
public float BlockRandomWeaponsIntegeration { get; set; } = 0;
}

public class DamageData
{
public int Damage { get; set; } = 0;
public int Hits { get; set; } = 0;
}

public class RestrictData
{
public int CT { get; set; }
Expand Down
19 changes: 17 additions & 2 deletions source/Deathmatch/Configs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ public class Gameplay
[JsonPropertyName("Check Enemies Distance")] public bool CheckDistance { get; set; } = true;
[JsonPropertyName("Distance From Enemies for Respawn")] public int DistanceRespawn { get; set; } = 500;
[JsonPropertyName("Default Weapons")] public int DefaultModeWeapons { get; set; } = 2;
[JsonPropertyName("Include Restricted Weapons As Defaults")] public bool RemoveRestrictedWeapons { get; set; } = true;
[JsonPropertyName("Switch Weapons")] public bool SwitchWeapons { get; set; } = true;
[JsonPropertyName("Allow Buymenu")] public bool AllowBuyMenu { get; set; } = true;
[JsonPropertyName("Use Default Spawns")] public bool DefaultSpawns { get; set; } = false;
Expand All @@ -172,8 +171,9 @@ public class General
[JsonPropertyName("Block Player Ping")] public bool BlockPlayerPing { get; set; } = true;
[JsonPropertyName("Block Player ChatWheel")] public bool BlockPlayerChatWheel { get; set; } = true;
[JsonPropertyName("Remove Breakable Entities")] public bool RemoveBreakableEntities { get; set; } = true;
[JsonPropertyName("Remove Decals After Death")] public bool RemoveDecals { get; set; } = true;
[JsonPropertyName("Remove Decals")] public bool RemoveDecals { 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;
}
public class CustomCommands
{
Expand All @@ -189,6 +189,7 @@ public class PlayersPreferences
[JsonPropertyName("Hit Sound")] public HitSound HitSound { get; set; } = new HitSound();
[JsonPropertyName("Only Headshot")] public OnlyHS OnlyHS { get; set; } = new OnlyHS();
[JsonPropertyName("Hud Messages")] public HudMessages HudMessages { get; set; } = new HudMessages();
[JsonPropertyName("Damage Info")] public DamageInfo DamageInfo { get; set; } = new DamageInfo();
}
// sounds/ui/beepclear.vsnd_c

Expand All @@ -197,13 +198,15 @@ public class OnlyHS
[JsonPropertyName("Enabled")] public bool Enabled { get; set; } = true;
[JsonPropertyName("Default value")] public bool DefaultValue { get; set; } = false;
[JsonPropertyName("Only for VIP")] public bool OnlyVIP { get; set; } = false;
[JsonPropertyName("Command Shortcuts")] public List<string> Shotcuts { get; set; } = new() { "hs", "onlyhs" };
}

public class HudMessages
{
[JsonPropertyName("Enabled")] public bool Enabled { get; set; } = true;
[JsonPropertyName("Default value")] public bool DefaultValue { get; set; } = true;
[JsonPropertyName("Only for VIP")] public bool OnlyVIP { get; set; } = false;
[JsonPropertyName("Command Shortcuts")] public List<string> Shotcuts { get; set; } = new() { "hud" };
}
public class HitSound
{
Expand All @@ -218,13 +221,15 @@ public class HitSound
[JsonPropertyName("Sound path")] public string Path { get; set; } = "sounds/ui/csgo_ui_contract_type2.vsnd_c";
[JsonPropertyName("Default value")] public bool DefaultValue { get; set; } = false;
[JsonPropertyName("Only for VIP")] public bool OnlyVIP { get; set; } = false;
[JsonPropertyName("Command Shortcuts")] public List<string> Shotcuts { get; set; } = new();
}
public class KnifeKillSound
{
[JsonPropertyName("Enabled")] public bool Enabled { get; set; } = true;
[JsonPropertyName("Sound path")] public string Path { get; set; } = "sounds/ui/armsrace_final_kill_knife.vsnd_c";
[JsonPropertyName("Default value")] public bool DefaultValue { get; set; } = false;
[JsonPropertyName("Only for VIP")] public bool OnlyVIP { get; set; } = false;
[JsonPropertyName("Command Shortcuts")] public List<string> Shotcuts { get; set; } = new();
}
public class KillSound
{
Expand All @@ -240,13 +245,23 @@ public class KillSound
[JsonPropertyName("Sound path")] public string Path { get; set; } = "sounds/ui/armsrace_kill_01.vsnd_c";
[JsonPropertyName("Default value")] public bool DefaultValue { get; set; } = false;
[JsonPropertyName("Only for VIP")] public bool OnlyVIP { get; set; } = false;
[JsonPropertyName("Command Shortcuts")] public List<string> Shotcuts { get; set; } = new();
}
public class HSKillSound
{
[JsonPropertyName("Enabled")] public bool Enabled { get; set; } = true;
[JsonPropertyName("Sound path")] public string Path { get; set; } = "sounds/buttons/bell1.vsnd_c";
[JsonPropertyName("Default value")] public bool DefaultValue { get; set; } = false;
[JsonPropertyName("Only for VIP")] public bool OnlyVIP { get; set; } = false;
[JsonPropertyName("Command Shortcuts")] public List<string> Shotcuts { get; set; } = new();
}

public class DamageInfo
{
[JsonPropertyName("Enabled")] public bool Enabled { get; set; } = true;
[JsonPropertyName("Default value")] public bool DefaultValue { get; set; } = false;
[JsonPropertyName("Only for VIP")] public bool OnlyVIP { get; set; } = false;
[JsonPropertyName("Command Shortcuts")] public List<string> Shotcuts { get; set; } = new() { "damage", "dmg" };
}

public class PlayersSettings
Expand Down
74 changes: 45 additions & 29 deletions source/Deathmatch/Deathmatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using CounterStrikeSharp.API.Core.Capabilities;
using DeathmatchAPI.Helpers;
using static DeathmatchAPI.Events.IDeathmatchEventsAPI;
using System.Runtime.InteropServices;
using static CounterStrikeSharp.API.Core.Listeners;

namespace Deathmatch;
Expand All @@ -19,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.2";
public override string ModuleVersion => "1.2.3";

public void OnConfigParsed(DeathmatchConfig config)
{
Expand All @@ -36,6 +35,7 @@ public override void Load(bool hotReload)
if (Config.SaveWeapons)
_ = CreateDatabaseConnection();

SetupDeathmatchMenus();
string[] Shortcuts = Config.CustomCommands.CustomShortcuts.Split(',');
string[] WSelect = Config.CustomCommands.WeaponSelectCmds.Split(',');
string[] DeathmatchMenus = Config.CustomCommands.DeatmatchMenuCmds.Split(',');
Expand All @@ -51,6 +51,11 @@ public override void Load(bool hotReload)
AddCustomCommands(cmd, "", 2);
foreach (var cmd in DeathmatchMenus)
AddCustomCommands(cmd, "", 3);
foreach (var preference in Preferences.Where(x => x.CommandShortcuts.Any()))
{
foreach (var cmd in preference.CommandShortcuts)
AddCustomCommands(cmd, preference.Name, 4, preference.vipOnly);
}
foreach (string radioName in RadioMessagesList)
AddCommandListener(radioName, OnPlayerRadioMessage);

Expand All @@ -69,12 +74,12 @@ public override void Load(bool hotReload)
if (!mapLoaded)
{
mapLoaded = true;
bool RoundTerminated = false;
DefaultMapSpawnDisabled = false;
playerData.Clear();
AddTimer(3.0f, () =>
{
LoadCustomConfigFile();
SetupDeathmatchMenus();
SetupCustomMode(Config.Gameplay.MapStartMode.ToString());
SetupDeathMatchConfigValues();
RemoveEntities();
Expand All @@ -92,44 +97,37 @@ public override void Load(bool hotReload)

if (RemainingTime == 0)
{
if (Config.General.ForceMapEnd)
{
var timelimit = Config.Gameplay.GameLength * 60;
var gameStart = GameRules().GameStartTime;
var currentTime = Server.CurrentTime;
var timeleft = timelimit - (currentTime - gameStart);
if (timeleft <= 0 && !RoundTerminated)
{
GameRules().TerminateRound(0.1f, RoundEndReason.RoundDraw);
}
}
SetupCustomMode(NextMode.ToString());
}
if (!string.IsNullOrEmpty(ActiveMode.CenterMessageText) && Config.CustomModes.ContainsKey(NextMode.ToString()))
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}";

var NextModeData = Config.CustomModes[NextMode.ToString()];
ModeCenterMessage = ActiveMode.CenterMessageText.Replace("{REMAININGTIME}", formattedTime);
ModeCenterMessage = ModeCenterMessage.Replace("{NEXTMODE}", NextModeData.Name);
ModeCenterMessage = ModeCenterMessage.Replace("{NEXTMODE}", modeData.Name);
}
}
}, TimerFlags.REPEAT | TimerFlags.STOP_ON_MAPCHANGE);
}
if (Config.General.ForceMapEnd)
{
bool RoundTerminated = false;
var timelimit = Config.Gameplay.GameLength * 60;
AddTimer(10.0f, () =>
{
var gameStart = GameRules().GameStartTime;
var currentTime = Server.CurrentTime;
var timeleft = timelimit - (currentTime - gameStart);
if (timeleft <= 0 && !RoundTerminated)
{
RoundTerminated = true;
GameRules().TerminateRound(0.1f, RoundEndReason.RoundDraw);
}

}, TimerFlags.REPEAT | TimerFlags.STOP_ON_MAPCHANGE);
}
}
});
RegisterListener<OnTick>(() =>
{
if (VisibleHud)
{
foreach (var p in Utilities.GetPlayers().Where(p => playerData.ContainsPlayer(p)))
foreach (var p in Utilities.GetPlayers())
{
if (ActiveEditor == p)
{
Expand All @@ -139,7 +137,7 @@ public override void Load(bool hotReload)
}
else
{
if (!playerData[p].Preferences.TryGetValue("HudMessages", out var hudMessage) || !hudMessage || MenuManager.GetActiveMenu(p) != null)
if (!GetPrefsValue(p.Slot, "HudMessages") || MenuManager.GetActiveMenu(p) != null)
continue;

if (!string.IsNullOrEmpty(ActiveMode.CenterMessageText))
Expand Down Expand Up @@ -171,6 +169,25 @@ public override void Load(bool hotReload)
}
}
});

if (Config.General.RemoveDecals)
{
HookUserMessage(411, um =>
{
um.Recipients.Clear();
return HookResult.Continue;
}, HookMode.Pre);
}

if (hotReload)
{
Server.ExecuteCommand($"map {Server.MapName}");
}
else
{
if (Config.General.RestartMapOnPluginLoad)
Server.ExecuteCommand($"map {Server.MapName}");
}
}

public override void Unload(bool hotReload)
Expand All @@ -189,10 +206,9 @@ public void SetupCustomMode(string modeId)
ActiveCustomMode = modeId;
NextMode = GetModeType();

if (Config.CustomModes.ContainsKey(NextMode.ToString()) && !string.IsNullOrEmpty(ActiveMode.CenterMessageText))
if (Config.CustomModes.TryGetValue(NextMode.ToString(),out var modeData) && !string.IsNullOrEmpty(ActiveMode.CenterMessageText))
{
var NextModeData = Config.CustomModes[NextMode.ToString()];
ModeCenterMessage = ActiveMode.CenterMessageText.Replace("{NEXTMODE}", NextModeData.Name);
ModeCenterMessage = ActiveMode.CenterMessageText.Replace("{NEXTMODE}", modeData.Name);
ModeCenterMessage = ModeCenterMessage.Replace("{REMAININGTIME}", RemainingTime.ToString());
}
SetupDeathmatchConfiguration(ActiveMode, bNewmode);
Expand All @@ -212,7 +228,7 @@ public void SetupDeathmatchConfiguration(ModeData mode, bool isNewMode)

Server.ExecuteCommand($"mp_free_armor {mode.Armor};mp_damage_headshot_only {mode.OnlyHS};mp_ct_default_primary \"\";mp_t_default_primary \"\";mp_ct_default_secondary \"\";mp_t_default_secondary \"\"");

if (mode.ExecuteCommands.Count > 0)
if (mode.ExecuteCommands.Any())
{
foreach (var cmd in mode.ExecuteCommands)
Server.ExecuteCommand(cmd);
Expand Down
2 changes: 1 addition & 1 deletion source/Deathmatch/Deathmatch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.282" />
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.290" />
<PackageReference Include="MysqlConnector" Version="2.3.7" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<ProjectReference Include="..\DeathmatchAPI\DeathmatchAPI.csproj" />
Expand Down
Loading

0 comments on commit 6628418

Please sign in to comment.