Skip to content

Commit

Permalink
Update v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
NockyCZ committed Sep 17, 2024
1 parent c1b2620 commit 1229fa3
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 23 deletions.
2 changes: 1 addition & 1 deletion source/Deathmatch/Configs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ 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; } = "#000000";
[JsonPropertyName("Spawn Protection Color")] public string SpawnProtectionColor { get; set; } = "#FFFFFF";
}
public class General
{
Expand Down
3 changes: 1 addition & 2 deletions source/Deathmatch/Deathmatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@

namespace Deathmatch;

[MinimumApiVersion(216)]
public partial class Deathmatch : BasePlugin, IPluginConfig<DeathmatchConfig>
{
public override string ModuleName => "Deathmatch Core";
public override string ModuleAuthor => "Nocky";
public override string ModuleVersion => "1.1.9";
public override string ModuleVersion => "1.2.0";

public void OnConfigParsed(DeathmatchConfig config)
{
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.239" />
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.264" />
<PackageReference Include="MysqlConnector" Version="2.3.7" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<ProjectReference Include="..\DeathmatchAPI\DeathmatchAPI.csproj" />
Expand Down
19 changes: 11 additions & 8 deletions source/Deathmatch/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,23 @@ public HookResult OnPlayerHurt(EventPlayerHurt @event, GameEventInfo info)
if (player == null || !player.IsValid || attacker == player)
return HookResult.Continue;

if (playerData.ContainsPlayer(attacker))
if (attacker != null && attacker.IsValid && playerData.ContainsPlayer(attacker))
{
if (ActiveMode.OnlyHS)
{
if (@event.Hitgroup == 1 && playerData[attacker].Preferences["HitSound"] && (!@event.Weapon.Contains("knife") || !@event.Weapon.Contains("bayonet")))
if (@event.Hitgroup == 1 && playerData[attacker].Preferences.TryGetValue("HitSound", out var value) & value && (!@event.Weapon.Contains("knife") || !@event.Weapon.Contains("bayonet")))
attacker!.ExecuteClientCommand("play " + Config.PlayersPreferences.HitSound.Path);
}
else
{
if (@event.Hitgroup != 1 && player.PlayerPawn.IsValid)
{
if (playerData[attacker].Preferences["OnlyHS"])
if (playerData[attacker].Preferences.TryGetValue("OnlyHS", out var hsValue) & hsValue)
{
player.PlayerPawn.Value!.Health = player.PlayerPawn.Value.Health >= 100 ? 100 : player.PlayerPawn.Value.Health + @event.DmgHealth;
player.PlayerPawn.Value.ArmorValue = player.PlayerPawn.Value.ArmorValue >= 100 ? 100 : player.PlayerPawn.Value.ArmorValue + @event.DmgArmor;
}
else if (playerData[attacker].Preferences["HitSound"] && (!@event.Weapon.Contains("knife") || !@event.Weapon.Contains("bayonet")))
else if (playerData[attacker].Preferences.TryGetValue("HitSound", out var hitValue) & hitValue && (!@event.Weapon.Contains("knife") || !@event.Weapon.Contains("bayonet")))
attacker!.ExecuteClientCommand("play " + Config.PlayersPreferences.HitSound.Path);
}
}
Expand Down Expand Up @@ -151,17 +151,20 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
PerformRespawn(player, player.Team);
}, TimerFlags.STOP_ON_MAPCHANGE);

if (attacker != player && playerData.ContainsPlayer(attacker) && attacker!.PlayerPawn.Value != null)
if (attacker != null && attacker.IsValid && attacker != player && playerData.ContainsPlayer(attacker) && attacker!.PlayerPawn.Value != null)
{
playerData[attacker].KillStreak++;
bool IsHeadshot = @event.Headshot;
bool IsKnifeKill = @event.Weapon.Contains("knife");

if (IsHeadshot && playerData[attacker].Preferences["HeadshotKillSound"])
bool TryGetPreference(string key, out bool value) =>
playerData[attacker].Preferences.TryGetValue(key, out value) && value;

if (IsHeadshot && TryGetPreference("HeadshotKillSound", out var headshotValue))
attacker.ExecuteClientCommand("play " + Config.PlayersPreferences.HSKillSound.Path);
else if (IsKnifeKill && playerData[attacker].Preferences["KnifeKillSound"])
else if (IsKnifeKill && TryGetPreference("KnifeKillSound", out var knifeValue))
attacker.ExecuteClientCommand("play " + Config.PlayersPreferences.KnifeKillSound.Path);
else if (playerData[attacker].Preferences["KillSound"])
else if (Config.PlayersPreferences.KillSound.Enabled && TryGetPreference("KillSound", out var killValue))
attacker.ExecuteClientCommand("play " + Config.PlayersPreferences.KillSound.Path);

var Health = IsHeadshot
Expand Down
6 changes: 3 additions & 3 deletions source/Deathmatch/Functions/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private void AddCustomCommands(string command, string weapon_name, int type)
case 1:
AddCommand(cmdName, $"Weapon Shortcut: {weapon_name}", (player, info) =>
{
if (!playerData.ContainsPlayer(player))
if (player != null && player.IsValid && !playerData.ContainsPlayer(player))
return;

if (ActiveMode.RandomWeapons)
Expand All @@ -34,7 +34,7 @@ private void AddCustomCommands(string command, string weapon_name, int type)
case 2:
AddCommand(cmdName, "Select a weapon by command", (player, info) =>
{
if (!playerData.ContainsPlayer(player))
if (player != null && player.IsValid && !playerData.ContainsPlayer(player))
return;
if (ActiveMode.RandomWeapons)
{
Expand All @@ -49,7 +49,7 @@ private void AddCustomCommands(string command, string weapon_name, int type)
case 3:
AddCommand(cmdName, "Opens a Deathmatch menu", (player, info) =>
{
if (!playerData.ContainsPlayer(player))
if (player != null && player.IsValid && !playerData.ContainsPlayer(player))
return;

if (Preferences.Count == 0)
Expand Down
6 changes: 3 additions & 3 deletions source/Deathmatch/Functions/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ public async Task CreateTable()
using var cmd = new MySqlCommand(
@"CREATE TABLE IF NOT EXISTS dm_players (
steamid VARCHAR(32) PRIMARY KEY UNIQUE NOT NULL,
primary_weapons JSON DEFAULT NULL,
secondary_weapons JSON DEFAULT NULL,
preferences JSON DEFAULT NULL
primary_weapons TEXT DEFAULT NULL,
secondary_weapons TEXT DEFAULT NULL,
preferences TEXT DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;", connection);
await cmd.ExecuteNonQueryAsync();
}
Expand Down
6 changes: 3 additions & 3 deletions source/Deathmatch/Functions/Players.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public void GivePlayerWeapons(CCSPlayerController player, bool bNewMode, bool gi
playerData[player].SpawnProtection = true;
AddTimer(timer, () =>
{
if (playerData.ContainsPlayer(player))
if (player != null && player.IsValid && playerData.ContainsPlayer(player))
{
playerData[player].SpawnProtection = false;
if (string.IsNullOrEmpty(Config.Gameplay.SpawnProtectionColor))
Expand Down Expand Up @@ -464,9 +464,9 @@ public T this[CCSPlayerController? controller]
}
}

public bool ContainsPlayer(CCSPlayerController? player)
public bool ContainsPlayer(CCSPlayerController player)
{
if (player == null || !player.IsValid || !player.PlayerPawn.IsValid || player.SteamID.ToString().Length != 17)
if (player.SteamID.ToString().Length != 17)
return false;

if (player.IsBot || player.IsHLTV)
Expand Down
15 changes: 13 additions & 2 deletions source/Deathmatch/Functions/Spawns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,13 @@ public void ShowAllSpawnPoints()
if (model == null || textVector == null)
continue;

model.SetModel("characters/models/shared/animsets/animset_uiplayer.vmdl");
//model.SetModel("characters/models/shared/animsets/animset_uiplayer.vmdl");
//model.SetModel("characters/models/ctm_fbi/ctm_fbi_variantf.vmdl");
model.SetModel("characters/models/ctm_sas/ctm_sas.vmdl");
//
model.UseAnimGraph = false;
model.AcceptInput("SetAnimation", value: "tools_preview");
//
model.DispatchSpawn();
model.Render = Color.FromArgb(255, 0, 102, 255);
model.Glow.GlowColorOverride = Color.Blue;
Expand Down Expand Up @@ -250,7 +256,12 @@ public void ShowAllSpawnPoints()
if (model == null || textVector == null)
continue;

model.SetModel("characters/models/shared/animsets/animset_uiplayer.vmdl");
//model.SetModel("characters/models/shared/animsets/animset_uiplayer.vmdl");
model.SetModel("characters/models/tm_leet/tm_leet_variantb.vmdl");
//
model.UseAnimGraph = false;
model.AcceptInput("SetAnimation", value: "tools_preview");
//
model.DispatchSpawn();
model.Render = Color.FromArgb(255, 255, 0, 0);
model.Glow.GlowColorOverride = Color.Red;
Expand Down

0 comments on commit 1229fa3

Please sign in to comment.