mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-25 12:52:17 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d88ce552f6 | ||
|
|
9f982d1e63 | ||
|
|
f01d4b0bf0 | ||
|
|
3a3f186673 |
34
Config.cs
34
Config.cs
@@ -1,11 +1,29 @@
|
|||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace WeaponPaints
|
namespace WeaponPaints
|
||||||
{
|
{
|
||||||
|
public class Messages
|
||||||
|
{
|
||||||
|
[JsonPropertyName("WebsiteMessageCommand")]
|
||||||
|
public string WebsiteMessageCommand { get; set; } = "Visit {WEBSITE} where you can change skins.";
|
||||||
|
[JsonPropertyName("SynchronizeMessageCommand")]
|
||||||
|
public string SynchronizeMessageCommand { get; set; } = "Type !wp to synchronize chosen skins.";
|
||||||
|
[JsonPropertyName("KnifeMessageCommand")]
|
||||||
|
public string KnifeMessageCommand { get; set; } = "Type !knife to open knife menu.";
|
||||||
|
[JsonPropertyName("CooldownRefreshCommand")]
|
||||||
|
public string CooldownRefreshCommand { get; set; } = "You can't refresh weapon paints right now.";
|
||||||
|
[JsonPropertyName("SuccessRefreshCommand")]
|
||||||
|
public string SuccessRefreshCommand { get; set; } = "Refreshing weapon paints.";
|
||||||
|
[JsonPropertyName("ChosenKnifeMenu")]
|
||||||
|
public string ChosenKnifeMenu { get; set; } = "You have chosen {KNIFE} as your knife.";
|
||||||
|
[JsonPropertyName("KnifeMenuTitle")]
|
||||||
|
public string KnifeMenuTitle { get; set; } = "Knife Menu.";
|
||||||
|
}
|
||||||
|
|
||||||
public class WeaponPaintsConfig : BasePluginConfig
|
public class WeaponPaintsConfig : BasePluginConfig
|
||||||
{
|
{
|
||||||
public override int Version { get; set; } = 1;
|
public override int Version { get; set; } = 2;
|
||||||
|
|
||||||
[JsonPropertyName("DatabaseHost")]
|
[JsonPropertyName("DatabaseHost")]
|
||||||
public string DatabaseHost { get; set; } = "";
|
public string DatabaseHost { get; set; } = "";
|
||||||
@@ -25,8 +43,14 @@ namespace WeaponPaints
|
|||||||
[JsonPropertyName("CmdRefreshCooldownSeconds")]
|
[JsonPropertyName("CmdRefreshCooldownSeconds")]
|
||||||
public int CmdRefreshCooldownSeconds { get; set; } = 60;
|
public int CmdRefreshCooldownSeconds { get; set; } = 60;
|
||||||
|
|
||||||
[JsonPropertyName("WebSite")]
|
[JsonPropertyName("Prefix")]
|
||||||
public string WebSite { get; set; } = "http://wp.example.com";
|
public string Prefix { get; set; } = "[WeaponPaints]";
|
||||||
|
|
||||||
|
[JsonPropertyName("Website")]
|
||||||
|
public string Website { get; set; } = "example.com/skins";
|
||||||
|
|
||||||
|
[JsonPropertyName("Messages")]
|
||||||
|
public Messages Messages { get; set; } = new Messages();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ using CounterStrikeSharp.API.Modules.Utils;
|
|||||||
using Nexd.MySQL;
|
using Nexd.MySQL;
|
||||||
using System.Runtime.ExceptionServices;
|
using System.Runtime.ExceptionServices;
|
||||||
using static CounterStrikeSharp.API.Core.Listeners;
|
using static CounterStrikeSharp.API.Core.Listeners;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
|
||||||
namespace WeaponPaints;
|
namespace WeaponPaints;
|
||||||
public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||||
@@ -22,7 +24,6 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
|
|
||||||
MySqlDb? MySql = null;
|
MySqlDb? MySql = null;
|
||||||
private DateTime[] commandCooldown = new DateTime[Server.MaxPlayers];
|
private DateTime[] commandCooldown = new DateTime[Server.MaxPlayers];
|
||||||
private static string PluginPrefix = $" {ChatColors.Green}[WeaponPaints]{ChatColors.White}";
|
|
||||||
private Dictionary<ulong, Dictionary<nint, int>> gPlayerWeaponPaints = new();
|
private Dictionary<ulong, Dictionary<nint, int>> gPlayerWeaponPaints = new();
|
||||||
private Dictionary<ulong, Dictionary<nint, int>> gPlayerWeaponSeed = new();
|
private Dictionary<ulong, Dictionary<nint, int>> gPlayerWeaponSeed = new();
|
||||||
private Dictionary<ulong, Dictionary<nint, float>> gPlayerWeaponWear = new();
|
private Dictionary<ulong, Dictionary<nint, float>> gPlayerWeaponWear = new();
|
||||||
@@ -243,14 +244,17 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
}
|
}
|
||||||
private void SetupMenus()
|
private void SetupMenus()
|
||||||
{
|
{
|
||||||
var giveItemMenu = new ChatMenu("Knife Menu");
|
var giveItemMenu = new ChatMenu(ReplaceTags(Config.Messages.KnifeMenuTitle));
|
||||||
var handleGive = (CCSPlayerController player, ChatMenuOption option) =>
|
var handleGive = (CCSPlayerController player, ChatMenuOption option) =>
|
||||||
{
|
{
|
||||||
if (knifeTypes.TryGetValue(option.Text, out var knife))
|
if (knifeTypes.TryGetValue(option.Text, out var knife))
|
||||||
{
|
{
|
||||||
Task.Run(() => SyncKnifeToDatabase((int)player.EntityIndex!.Value.Value, knife));
|
Task.Run(() => SyncKnifeToDatabase((int)player.EntityIndex!.Value.Value, knife));
|
||||||
g_playersKnife[(int)player.EntityIndex!.Value.Value] = knifeTypes[option.Text];
|
g_playersKnife[(int)player.EntityIndex!.Value.Value] = knifeTypes[option.Text];
|
||||||
player.PrintToChat($"You have chosen {option.Text} as your knife.");
|
if (!string.IsNullOrEmpty(Config.Messages.ChosenKnifeMenu)) {
|
||||||
|
string temp = $"{Config.Prefix} {Config.Messages.ChosenKnifeMenu}".Replace("{KNIFE}", option.Text);
|
||||||
|
player.PrintToChat(ReplaceTags(temp));
|
||||||
|
}
|
||||||
RemoveKnifeFromPlayer(player);
|
RemoveKnifeFromPlayer(player);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -264,23 +268,42 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
public void OnCommandRefresh(CCSPlayerController? player, CommandInfo command)
|
public void OnCommandRefresh(CCSPlayerController? player, CommandInfo command)
|
||||||
{
|
{
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
|
string temp = "";
|
||||||
int playerIndex = (int)player.EntityIndex!.Value.Value;
|
int playerIndex = (int)player.EntityIndex!.Value.Value;
|
||||||
if (DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds))
|
if (DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds))
|
||||||
{
|
{
|
||||||
commandCooldown[playerIndex] = DateTime.UtcNow;
|
commandCooldown[playerIndex] = DateTime.UtcNow;
|
||||||
Task.Run(async () => await GetWeaponPaintsFromDatabase(playerIndex));
|
Task.Run(async () => await GetWeaponPaintsFromDatabase(playerIndex));
|
||||||
player.PrintToChat($"{PluginPrefix} Refreshing weapon paints.");
|
if (!string.IsNullOrEmpty(Config.Messages.SuccessRefreshCommand)) {
|
||||||
|
temp = $"{Config.Prefix} {Config.Messages.SuccessRefreshCommand}";
|
||||||
|
player.PrintToChat(ReplaceTags(temp));
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
player.PrintToChat($"{PluginPrefix} You can't refresh weapon paints right now.");
|
if (!string.IsNullOrEmpty(Config.Messages.CooldownRefreshCommand)) {
|
||||||
|
temp = $"{Config.Prefix} {Config.Messages.CooldownRefreshCommand}";
|
||||||
|
player.PrintToChat(ReplaceTags(temp));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
[ConsoleCommand("css_ws", "weaponskins")]
|
[ConsoleCommand("css_ws", "weaponskins")]
|
||||||
public void OnCommandWS(CCSPlayerController? player, CommandInfo command)
|
public void OnCommandWS(CCSPlayerController? player, CommandInfo command)
|
||||||
{
|
{
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
player.PrintToChat($"{PluginPrefix} Visit {ChatColors.Purple}{Config.WebSite} {ChatColors.White}where you can change skins.");
|
|
||||||
player.PrintToChat($"{PluginPrefix} Type {ChatColors.Purple}!wp {ChatColors.White}in chat to synchronize chosen skins.");
|
string temp = "";
|
||||||
player.PrintToChat($"{PluginPrefix} Type {ChatColors.Purple}!knife {ChatColors.White}in chat to open knife menu.");
|
|
||||||
|
if (!string.IsNullOrEmpty(Config.Messages.WebsiteMessageCommand)) {
|
||||||
|
temp = $"{Config.Prefix} {Config.Messages.WebsiteMessageCommand}";
|
||||||
|
player.PrintToChat(ReplaceTags(temp));
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(Config.Messages.SynchronizeMessageCommand)) {
|
||||||
|
temp = $"{Config.Prefix} {Config.Messages.SynchronizeMessageCommand}";
|
||||||
|
player.PrintToChat(ReplaceTags(temp));
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(Config.Messages.KnifeMessageCommand)) {
|
||||||
|
temp = $"{Config.Prefix} {Config.Messages.KnifeMessageCommand}";
|
||||||
|
player.PrintToChat(ReplaceTags(temp));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public static CSkeletonInstance GetSkeletonInstance(CGameSceneNode node)
|
public static CSkeletonInstance GetSkeletonInstance(CGameSceneNode node)
|
||||||
{
|
{
|
||||||
@@ -377,6 +400,27 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string ReplaceTags(string message)
|
||||||
|
{
|
||||||
|
if (message.Contains('{'))
|
||||||
|
{
|
||||||
|
string modifiedValue = message;
|
||||||
|
modifiedValue = modifiedValue.Replace("{WEBSITE}", Config.Website);
|
||||||
|
foreach (FieldInfo field in typeof(ChatColors).GetFields())
|
||||||
|
{
|
||||||
|
string pattern = $"{{{field.Name}}}";
|
||||||
|
if (message.Contains(pattern, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
modifiedValue = modifiedValue.Replace(pattern, field.GetValue(null)!.ToString(), StringComparison.OrdinalIgnoreCase);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return modifiedValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
private static void Log(string message)
|
private static void Log(string message)
|
||||||
{
|
{
|
||||||
Console.BackgroundColor = ConsoleColor.DarkGray;
|
Console.BackgroundColor = ConsoleColor.DarkGray;
|
||||||
@@ -384,4 +428,4 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
|||||||
Console.WriteLine(message);
|
Console.WriteLine(message);
|
||||||
Console.ResetColor();
|
Console.ResetColor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user