Skip to content

Commit

Permalink
Update v1.1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
NockyCZ committed Sep 15, 2024
1 parent 2fa82b2 commit fd0ad9f
Show file tree
Hide file tree
Showing 16 changed files with 885 additions and 570 deletions.
7 changes: 6 additions & 1 deletion source/Deathmatch/API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public void TriggerEvent(IDeathmatchEventsAPI @event)
DeathmatchEventHandlers?.Invoke(this, @event);
}

public void RegisterNewPreference(PreferencesData preferencesData)
{
Preferences.Add(preferencesData);
}

public void StartCustomMode(int modeId)
{
if (!CustomModes.ContainsKey(modeId.ToString()))
Expand Down Expand Up @@ -73,7 +78,7 @@ public void SwapHudMessageVisibility(bool visible)

public int GetActiveModeId()
{
return ActiveCustomMode;
return int.Parse(ActiveCustomMode);
}

public int GetActiveModeRemainingTime()
Expand Down
22 changes: 11 additions & 11 deletions source/Deathmatch/Common/Classes.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
using DeathmatchAPI.Helpers;
using Vector = CounterStrikeSharp.API.Modules.Utils.Vector;

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 string PrimaryWeapon { get; set; } = "";
public string SecondaryWeapon { get; set; } = "";
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 string LastPrimaryWeapon { get; set; } = "";
public string LastSecondaryWeapon { get; set; } = "";
public bool SpawnProtection { get; set; } = false;
public int KillStreak { get; set; } = 0;
public required bool KillSound { get; set; }
public required bool HSKillSound { get; set; }
public required bool KnifeKillSound { get; set; }
public required bool HitSound { get; set; }
public required bool OnlyHS { get; set; }
public required bool HudMessages { get; set; }
public Vector LastSpawn { get; set; } = new Vector();
//public (Vector, QAngle) BlockedSpawn { get; set; } = new();
public int OpenedMenu { get; set; } = 0;
public float BlockRandomWeaponsIntegeration { get; set; } = 0;
}

Expand Down
8 changes: 5 additions & 3 deletions source/Deathmatch/Common/Collections.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using DeathmatchAPI.Helpers;
using Vector = CounterStrikeSharp.API.Modules.Utils.Vector;
Expand All @@ -10,10 +11,11 @@ public partial class Deathmatch
public static Dictionary<string, Dictionary<string, Dictionary<RestrictType, RestrictData>>> RestrictedWeapons = new();
public static Dictionary<Vector, QAngle> spawnPositionsCT = new();
public static Dictionary<Vector, QAngle> spawnPositionsT = new();
public static Dictionary<int, (Vector, QAngle)> blockedSpawns = new();
public static Dictionary<int, Vector> blockedSpawns = new();
public static PlayerCache<DeathmatchPlayerData> playerData = new PlayerCache<DeathmatchPlayerData>();
public static List<(string, bool, int)> PrefsMenuSounds = new();
public static List<(string, bool, int)> PrefsMenuFunctions = new();
public static List<PreferencesData> Preferences = new();
public static List<CDynamicProp> savedSpawnsModel = new();
public static List<CPointWorldText> savedSpawnsVectorText = new();

readonly Dictionary<string, string> weaponSelectMapping = new Dictionary<string, string>
{
Expand Down
6 changes: 3 additions & 3 deletions source/Deathmatch/Common/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ public partial class Deathmatch
private static readonly Random Random = new Random();
public static PluginCapability<IDeathmatchAPI> DeathmatchAPI { get; } = new("deathmatch");
public DeathmatchConfig Config { get; set; } = new();
public static CCSPlayerController? ActiveEditor = null;
public static int NextMode;
public static string ModeCenterMessage = "";
public static int ActiveCustomMode = 0;
public static string ActiveCustomMode = "";
public static int ModeTimer = 0;
public static int RemainingTime = 500;
public static bool IsActiveEditor = false;
public static bool VisibleHud = true;
public static int CheckedEnemiesDistance = 500;
public static bool IsCasualGamemode;
public static bool DefaultMapSpawnDisabled = false;
public static bool IsLinuxServer;
public static ModeData? ActiveMode;
public static ModeData ActiveMode = new();
public MemoryFunctionWithReturn<CCSPlayer_ItemServices, CEconItemView, AcquireMethod, NativeObject, AcquireResult>? CCSPlayer_CanAcquireFunc;
public MemoryFunctionWithReturn<int, string, CCSWeaponBaseVData>? GetCSWeaponDataFromKeyFunc;
}
Expand Down
49 changes: 36 additions & 13 deletions source/Deathmatch/Configs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace Deathmatch;

public class DeathmatchConfig : BasePluginConfig
{
[JsonPropertyName("Save Players Weapons")] public bool SaveWeapons { get; set; } = false;
[JsonPropertyName("Database Connection")] public Database Database { get; set; } = new Database();
[JsonPropertyName("Gameplay Settings")] public Gameplay Gameplay { get; set; } = new Gameplay();
[JsonPropertyName("General Settings")] public General General { get; set; } = new General();
[JsonPropertyName("Sounds Settings")] public SoundSettings SoundSettings { get; set; } = new SoundSettings();
Expand Down Expand Up @@ -122,6 +124,15 @@ public class DeathmatchConfig : BasePluginConfig
[JsonPropertyName("Weapons Restrict")] public WeaponsRestrict WeaponsRestrict { get; set; } = new WeaponsRestrict();
}

public class Database
{
[JsonPropertyName("Host")] public string Host { get; set; } = "";
[JsonPropertyName("Port")] public uint Port { get; set; } = 3306;
[JsonPropertyName("User")] public string User { get; set; } = "";
[JsonPropertyName("Database")] public string DatabaseName { get; set; } = "";
[JsonPropertyName("Password")] public string Password { get; set; } = "";
}

public class SoundSettings
{
[JsonPropertyName("Weapon Cant Equip Sound")] public string CantEquipSound { get; set; } = "sounds/ui/weapon_cant_buy.vsnd_c";
Expand Down Expand Up @@ -235,19 +246,31 @@ public class HSKillSound

public class PlayersSettings
{
[JsonPropertyName("VIP_flag")] public string VIPFlag { get; set; } = "@css/vip";
[JsonPropertyName("respawn_time")] public float RespawnTime { get; set; } = 1.5f;
[JsonPropertyName("VIP_respawn_time")] public float RespawnTimeVIP { get; set; } = 1.1f;
[JsonPropertyName("spawn_protection_time")] public float ProtectionTime { get; set; } = 1.1f;
[JsonPropertyName("VIP_spawn_protection_time")] public float ProtectionTimeVIP { get; set; } = 1.2f;
[JsonPropertyName("reffil_ammo_kill")] public bool RefillAmmo { get; set; } = false;
[JsonPropertyName("VIP_reffil_ammo_kill")] public bool RefillAmmoVIP { get; set; } = true;
[JsonPropertyName("reffil_ammo_headshot")] public bool RefillAmmoHS { get; set; } = true;
[JsonPropertyName("VIP_reffil_ammo_headshot")] public bool RefillAmmoHSVIP { get; set; } = true;
[JsonPropertyName("refill_health_kill")] public int KillHealth { get; set; } = 20;
[JsonPropertyName("VIP_refill_health_kill")] public int KillHealthVIP { get; set; } = 25;
[JsonPropertyName("refill_health_headshot")] public int HeadshotHealth { get; set; } = 40;
[JsonPropertyName("VIP_refill_health_headshot")] public int HeadshotHealthVIP { get; set; } = 50;
[JsonPropertyName("VIP Flag")] public string VIPFlag { get; set; } = "@css/vip";
[JsonPropertyName("Non VIP Players")] public NonVIP NonVIP { get; set; } = new();
[JsonPropertyName("VIP Players")] public VIP VIP { get; set; } = new();
}

public class NonVIP
{
[JsonPropertyName("Respawn Time")] public float RespawnTime { get; set; } = 1.5f;
[JsonPropertyName("Spawn Protection Time")] public float ProtectionTime { get; set; } = 1.1f;
[JsonPropertyName("Reffil Ammo Kill")] public bool RefillAmmo { get; set; } = false;
[JsonPropertyName("Reffil Ammo Headshot")] public bool RefillAmmoHS { get; set; } = false;
[JsonPropertyName("Reffil Ammo in All Weapons")] public bool ReffilAllWeapons { get; set; } = false;
[JsonPropertyName("Reffil Health Kill")] public int KillHealth { get; set; } = 20;
[JsonPropertyName("Reffil Health Headshot")] public int HeadshotHealth { get; set; } = 40;
}

public class VIP
{
[JsonPropertyName("Respawn Time")] public float RespawnTime { get; set; } = 1.1f;
[JsonPropertyName("Spawn Protection Time")] public float ProtectionTime { get; set; } = 1.2f;
[JsonPropertyName("Reffil Ammo Kill")] public bool RefillAmmo { get; set; } = false;
[JsonPropertyName("Reffil Ammo Headshot")] public bool RefillAmmoHS { get; set; } = false;
[JsonPropertyName("Reffil Ammo in All Weapons")] public bool ReffilAllWeapons { get; set; } = false;
[JsonPropertyName("Reffil Health Kill")] public int KillHealth { get; set; } = 25;
[JsonPropertyName("Reffil Health Headshot")] public int HeadshotHealth { get; set; } = 50;
}

public class WeaponsRestrict
Expand Down
56 changes: 34 additions & 22 deletions source/Deathmatch/Deathmatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@

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.8";
public override string ModuleVersion => "1.1.9";

public void OnConfigParsed(DeathmatchConfig config)
{
Expand All @@ -42,6 +43,8 @@ public override void Load(bool hotReload)

LoadCustomModes();
LoadWeaponsRestrict();
if (Config.SaveWeapons)
_ = CreateDatabaseConnection();

string[] Shortcuts = Config.CustomCommands.CustomShortcuts.Split(',');
string[] WSelect = Config.CustomCommands.WeaponSelectCmds.Split(',');
Expand All @@ -65,15 +68,18 @@ public override void Load(bool hotReload)
AddCommandListener("player_ping", OnPlayerPing);
AddCommandListener("autobuy", OnRandomWeapons);

AddCommandListener("say", OnPlayerSay);
AddCommandListener("say_team", OnPlayerSay);

bool mapLoaded = false;
RegisterListener<OnMapEnd>(() => { mapLoaded = false; blockedSpawns.Clear(); });
RegisterListener<OnMapEnd>(() => { mapLoaded = false; });
RegisterListener<OnMapStart>(mapName =>
{
blockedSpawns.Clear();
if (!mapLoaded)
{
mapLoaded = true;
DefaultMapSpawnDisabled = false;
blockedSpawns.Clear();
AddTimer(3.0f, () =>
{
LoadCustomConfigFile();
Expand All @@ -88,7 +94,7 @@ public override void Load(bool hotReload)
{
AddTimer(1.0f, () =>
{
if (!GameRules().WarmupPeriod && ActiveMode != null)
if (!GameRules().WarmupPeriod)
{
ModeTimer++;
RemainingTime = ActiveMode.Interval - ModeTimer;
Expand Down Expand Up @@ -128,27 +134,32 @@ public override void Load(bool hotReload)
}
}
});
RegisterListener<OnServerPrecacheResources>((manifest) =>
{
manifest.AddResource("characters/models/shared/animsets/animset_uiplayer.vmdl");

});
RegisterListener<OnTick>(() =>
{
if (VisibleHud)
{
if (IsActiveEditor)
foreach (var p in Utilities.GetPlayers().Where(p => playerData.ContainsPlayer(p)))
{
foreach (var p in Utilities.GetPlayers().Where(p => !p.IsBot && !p.IsHLTV && AdminManager.PlayerHasPermissions(p, "@css/root")))
if (!playerData[p].Preferences.ContainsKey("HudMessages") || !playerData[p].Preferences["HudMessages"])
continue;

if (ActiveEditor == p)
{
string CTSpawns = $"<font class='fontSize-m' color='cyan'>CT Spawns:</font> <font class='fontSize-m' color='green'>{spawnPositionsCT.Count}</font>";
string TSpawns = $"<font class='fontSize-m' color='orange'>T Spawns:</font> <font class='fontSize-m' color='green'>{spawnPositionsT.Count}</font>";
p.PrintToCenterHtml($"<font class='fontSize-l' color='red'>Spawns Editor</font><br>{CTSpawns}<br>{TSpawns}<br>");
var ctSpawns = DefaultMapSpawnDisabled ? spawnPositionsCT.Count : 0;
var tSpawns = DefaultMapSpawnDisabled ? spawnPositionsT.Count : 0;
p.PrintToCenterHtml($"<font class='fontSize-l' color='red'>Spawns Editor</font><br><font class='fontSize-m' color='green'>!1</font> Add CT Spawn (Total: <font color='lime'>{ctSpawns}</font>)<br><font class='fontSize-m' color='green'>!2</font> Add T Spawn (Total: <font color='lime'>{tSpawns}</font>)<br><font class='fontSize-m' color='green'>!3</font> Remove the Nearest Spawn<br><br><font class='fontSize-m' color='green'>!4</font> <font class='fontSize-m' color='cyan'>Save Spawns</font><br> ");
}
}
else
{
foreach (var p in Utilities.GetPlayers().Where(p => playerData.ContainsPlayer(p) && playerData[p].HudMessages))
else
{
if (!playerData[p].HudMessages)
if (MenuManager.GetActiveMenu(p) != null)
continue;

if (ActiveMode != null && !string.IsNullOrEmpty(ActiveMode.CenterMessageText) && MenuManager.GetActiveMenu(p) == null)
if (!string.IsNullOrEmpty(ActiveMode.CenterMessageText))
{
if (Config.Gameplay.HudType == 1)
p.PrintToCenterHtml(ModeCenterMessage);
Expand Down Expand Up @@ -196,7 +207,7 @@ public void SetupCustomMode(string modeId)
if (modeId.Equals(ActiveCustomMode.ToString()))
bNewmode = false;

ActiveCustomMode = int.Parse(modeId);
ActiveCustomMode = modeId;
NextMode = GetModeType();

if (CustomModes.ContainsKey(NextMode.ToString()) && !string.IsNullOrEmpty(ActiveMode.CenterMessageText))
Expand All @@ -209,7 +220,7 @@ public void SetupCustomMode(string modeId)

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

Expand Down Expand Up @@ -307,7 +318,7 @@ public void LoadCustomModes()
dynamic deserializedJson = JsonConvert.DeserializeObject(jsonData)!;
var modes = deserializedJson["Custom Modes"].ToObject<Dictionary<string, ModeData>>();
CustomModes = new Dictionary<string, ModeData>(modes);
SendConsoleMessage($"[Deathmatch] Loaded {CustomModes.Count()} Custom Modes", ConsoleColor.Green);
SendConsoleMessage($"[Deathmatch] Loaded {CustomModes.Count} Custom Modes", ConsoleColor.Green);

}
catch (Exception ex)
Expand All @@ -329,7 +340,7 @@ public void LoadWeaponsRestrict()
dynamic deserializedJson = JsonConvert.DeserializeObject(jsonData)!;
var weapons = deserializedJson["Weapons Restrict"]["Weapons"].ToObject<Dictionary<string, Dictionary<string, Dictionary<RestrictType, RestrictData>>>>();
RestrictedWeapons = new(weapons);
SendConsoleMessage($"[Deathmatch] Total Restricted Weapons: {RestrictedWeapons.Count()}", ConsoleColor.Green);
SendConsoleMessage($"[Deathmatch] Total Restricted Weapons: {RestrictedWeapons.Count}", ConsoleColor.Green);
/*foreach (var item in RestrictedWeapons)
{
SendConsoleMessage(item.Key, ConsoleColor.Magenta);
Expand Down Expand Up @@ -385,19 +396,20 @@ public int GetModeType()
{
if (Config.Gameplay.IsCustomModes)
{
var modeId = int.Parse(ActiveCustomMode);
if (Config.Gameplay.RandomSelectionOfModes)
{
int iRandomMode;
do
{
iRandomMode = Random.Next(0, CustomModes.Count);
} while (iRandomMode == ActiveCustomMode);
} while (iRandomMode == modeId);
return iRandomMode;
}
else
{
if (ActiveCustomMode + 1 != CustomModes.Count && ActiveCustomMode + 1 < CustomModes.Count)
return ActiveCustomMode + 1;
if (modeId + 1 != CustomModes.Count && modeId + 1 < CustomModes.Count)
return modeId + 1;
return 0;
}
}
Expand Down
1 change: 1 addition & 0 deletions source/Deathmatch/Deathmatch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

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

0 comments on commit fd0ad9f

Please sign in to comment.