Compare commits

...

31 Commits

Author SHA1 Message Date
Nereziel
b5a4577af1 Update README.md 2023-11-15 22:15:38 +01:00
Nereziel
ba93e4a3aa Update build.yml 2023-11-15 21:22:24 +01:00
Nereziel
7d435da9d1 Update build.yml 2023-11-15 21:19:48 +01:00
Nereziel
50008cf74a Merge pull request #32 from daffyyyy/enhancement/website-skins
Website now use json file to load skins
2023-11-15 20:52:20 +01:00
Dawid Bepierszcz
4b9b169483 Update database.sql, remove weapon_paints 2023-11-15 20:47:16 +01:00
Dawid Bepierszcz
25d251deff Skins in json format 2023-11-15 20:45:55 +01:00
Dawid Bepierszcz
d8f7798f9f New utils class 2023-11-15 20:44:46 +01:00
Dawid Bepierszcz
fb023aff5b Update index.php to base on json 2023-11-15 20:44:18 +01:00
Dawid Bepierszcz
6c91e20a4d Delete website/skins.json
Not needed
2023-11-15 20:43:28 +01:00
Nereziel
93dae346d0 Merge pull request #31 from daffyyyy/patch-giving_knife
Improve knife giving
2023-11-15 18:20:48 +01:00
Dawid Bepierszcz
8e0b1cc99a Update WeaponPaints.cs
respecting the team
2023-11-15 18:18:31 +01:00
Dawid Bepierszcz
c99acbcdb3 Update WeaponPaints.cs
Improved knife giving
And small changes to the code
2023-11-15 18:03:37 +01:00
Nereziel
8beaee94da Merge pull request #28 from daffyyyy/improvement-website-2
Weapon paint  images locally
2023-11-15 16:43:59 +01:00
Nereziel
62238b4446 Merge pull request #27 from daffyyyy/fix-visibility_skins
Weird fix of skin visibility, but at the moment it works xD
2023-11-15 15:03:29 +01:00
Nereziel
03f194ac4e Added discord server 2023-11-15 13:14:12 +01:00
Nereziel
d88ce552f6 Merge pull request #30 from daffyyyy/improvement-config_messages
Add messages to config
2023-11-15 13:08:53 +01:00
Dawid Bepierszcz
9f982d1e63 Update Config.cs 2023-11-15 13:03:16 +01:00
Dawid Bepierszcz
f01d4b0bf0 Update WeaponPaints.cs 2023-11-15 12:52:07 +01:00
Dawid Bepierszcz
3a3f186673 Update Config.cs 2023-11-15 12:51:01 +01:00
daffyyyy
e775b05f9f Upload paint images
Added paint images
2023-11-14 23:13:55 +01:00
Dawid Bepierszcz
b09b97bbd5 Update database.sql
Paints image locally
2023-11-14 23:06:10 +01:00
Dawid Bepierszcz
e441ccc601 Update WeaponPaints.cs
Weird fix of skin visibility, but at the moment it works xD
2023-11-14 22:49:59 +01:00
Nereziel
dc7fb183f9 update 2023-11-14 22:17:43 +01:00
Nereziel
5a5b120674 change knife give handling 2023-11-14 19:54:22 +01:00
Nereziel
5a24f3b9fa bots had no knife 2023-11-14 19:08:17 +01:00
Nereziel
1527eea686 Update README.md 2023-11-14 16:56:18 +01:00
Nereziel
953788c327 Update README.md 2023-11-14 16:52:00 +01:00
Nereziel
837b000126 Merge pull request #24 from daffyyyy/hotfix-1
Update WeaponPaints.cs
2023-11-14 16:42:41 +01:00
Nereziel
87a78b01b4 Merge branch 'main' into hotfix-1 2023-11-14 16:41:06 +01:00
Nereziel
f7c914a267 missing exception 2023-11-14 16:37:47 +01:00
Dawid Bepierszcz
2c0fad230d Update WeaponPaints.cs
Temporary fix for player loading
2023-11-14 15:45:50 +01:00
1703 changed files with 280 additions and 115540 deletions

View File

@@ -34,13 +34,16 @@ jobs:
${{ env.OUTPUT_PATH }}/CounterStrikeSharp.API.dll \ ${{ env.OUTPUT_PATH }}/CounterStrikeSharp.API.dll \
${{ env.OUTPUT_PATH }}/McMaster.NETCore.Plugins.dll \ ${{ env.OUTPUT_PATH }}/McMaster.NETCore.Plugins.dll \
${{ env.OUTPUT_PATH }}/Microsoft.DotNet.PlatformAbstractions.dll \ ${{ env.OUTPUT_PATH }}/Microsoft.DotNet.PlatformAbstractions.dll \
${{ env.OUTPUT_PATH }}/Microsoft.Extensions.DependencyModel.dll ${{ env.OUTPUT_PATH }}/Microsoft.Extensions.DependencyModel.dll \
- name: Zip - name: Zip
uses: thedoctor0/zip-release@0.7.5 uses: thedoctor0/zip-release@0.7.5
with: with:
type: 'zip' type: 'zip'
filename: '${{ env.PROJECT_NAME }}.zip' filename: '${{ env.PROJECT_NAME }}.zip'
path: ${{ env.OUTPUT_PATH }} path: ${{ env.OUTPUT_PATH }}
- name: Clean files Website
run: |
rm -rf website/img/
- name: Zip - name: Zip
uses: thedoctor0/zip-release@0.7.5 uses: thedoctor0/zip-release@0.7.5
with: with:
@@ -54,4 +57,4 @@ jobs:
name: "Build ${{ env.BUILD_NUMBER }}" name: "Build ${{ env.BUILD_NUMBER }}"
tag: "build-${{ env.BUILD_NUMBER }}" tag: "build-${{ env.BUILD_NUMBER }}"
body: | body: |
Place the plugin in game/csgo/addons/counterstrikesharp/plugins/WeaponPaints Place the plugin in game/csgo/addons/counterstrikesharp/plugins/WeaponPaints

View File

@@ -1,32 +1,56 @@
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; } = "localhost"; public string DatabaseHost { get; set; } = "";
[JsonPropertyName("DatabasePort")] [JsonPropertyName("DatabasePort")]
public int DatabasePort { get; set; } = 3306; public int DatabasePort { get; set; } = 3306;
[JsonPropertyName("DatabaseUser")] [JsonPropertyName("DatabaseUser")]
public string DatabaseUser { get; set; } = "dbuser"; public string DatabaseUser { get; set; } = "";
[JsonPropertyName("DatabasePassword")] [JsonPropertyName("DatabasePassword")]
public string DatabasePassword { get; set; } = "dbuserpw"; public string DatabasePassword { get; set; } = "";
[JsonPropertyName("DatabaseName")] [JsonPropertyName("DatabaseName")]
public string DatabaseName { get; set; } = "dbname"; public string DatabaseName { get; set; } = "";
[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();
} }
} }

View File

@@ -1,18 +1,22 @@
# cs2-WeaponPaints # cs2-WeaponPaints
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/E1E2G0P2O) or [Donate on Steam](https://steamcommunity.com/tradeoffer/new/?partner=41515647&token=gW2W-nXE)
### Use this plugin at your own risk! Using this may lead to GSLT ban or something else Valve come with. [Valve Server guidelines](https://blog.counter-strike.net/index.php/server_guidelines/)
### Description ### Description
Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin for [CSSharp](https://docs.cssharp.dev/). Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin for [CSSharp](https://docs.cssharp.dev/).
There will be a lot of frequent changes which may break functionality or compatibility. You have been warned!
## Created [Discord server](https://discord.gg/mwEQppJ5AT) where you can discus about plugin.
### Consider to donate instead of buying from unknown sources.
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/E1E2G0P2O) or [Donate on Steam](https://steamcommunity.com/tradeoffer/new/?partner=41515647&token=gW2W-nXE)
### Features ### Features
- changes only paint, seed, wear on weapons - changes only paint, seed and wear on weapons and knives
- mysql based - mysql based
- data sync on player connect or playe - data sync on player connect
- Added command `!wp` to refresh skins (with cooldown in second can be configured) - Added command `!wp` to refresh skins (with cooldown in second can be configured)
- Added command `!ws` to show website - Added command `!ws` to show website
- Added command `!knife` to show menu with knives
- Knife change is now limited to have these cvars empty `mp_t_default_melee ""` and `mp_ct_default_melee ""`
### CS2 server: ### CS2 server:
- compile and copy plugin to plugins. Info here [https://docs.cssharp.dev/guides/hello-world-plugin/](https://docs.cssharp.dev/guides/hello-world-plugin/) - compile and copy plugin to plugins. Info here [https://docs.cssharp.dev/guides/hello-world-plugin/](https://docs.cssharp.dev/guides/hello-world-plugin/)
@@ -20,11 +24,14 @@ Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin
- in `addons/counterstrikesharp/configs/core.json` set **FollowCS2ServerGuidelines** to **false** - in `addons/counterstrikesharp/configs/core.json` set **FollowCS2ServerGuidelines** to **false**
### Web install: ### Web install:
- copy website to web server - requires PHP min v7.3 (tested on php ver `8.2.3` and nginx webserver)
- copy website to web server (img folder not needed)
- import `database.sql` to mysql - import `database.sql` to mysql
- get steam api key [https://steamcommunity.com/dev/apikey](https://steamcommunity.com/dev/apikey) - get steam api key [https://steamcommunity.com/dev/apikey](https://steamcommunity.com/dev/apikey)
- fill in database credentials and api key in `class/config.php` - fill in database credentials and api key in `class/config.php`
- visit website and login via steam - visit website and login via steam
### Use this plugin at your own risk! Using this may lead to GSLT ban or something else Valve come with. [Valve Server guidelines](https://blog.counter-strike.net/index.php/server_guidelines/)
### Preview ### Preview
![preview](https://github.com/Nereziel/cs2-WeaponPaints/blob/main/website/preview.png?raw=true) ![preview](https://github.com/Nereziel/cs2-WeaponPaints/blob/main/website/preview.png?raw=true)

View File

@@ -1,4 +1,4 @@
using CounterStrikeSharp.API; using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration; using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Commands; using CounterStrikeSharp.API.Modules.Commands;
@@ -8,6 +8,9 @@ using CounterStrikeSharp.API.Modules.Menu;
using CounterStrikeSharp.API.Modules.Utils; 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 System.Reflection;
namespace WeaponPaints; namespace WeaponPaints;
public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig> public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
@@ -21,11 +24,10 @@ 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();
private Dictionary<int, string> g_playersKife = new(); private Dictionary<int, string> g_playersKnife = new();
private static readonly Dictionary<string, string> knifeTypes = new() private static readonly Dictionary<string, string> knifeTypes = new()
{ {
{ "m9", "weapon_knife_m9_bayonet" }, { "m9", "weapon_knife_m9_bayonet" },
@@ -67,7 +69,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
SetGlobalExceptionHandler(); SetGlobalExceptionHandler();
MySql = new MySqlDb(Config.DatabaseHost, Config.DatabaseUser, Config.DatabasePassword, Config.DatabaseName!, Config.DatabasePort); MySql = new MySqlDb(Config.DatabaseHost, Config.DatabaseUser, Config.DatabasePassword, Config.DatabaseName!, Config.DatabasePort);
RegisterListener<Listeners.OnEntitySpawned>(OnEntitySpawned); RegisterListener<Listeners.OnEntitySpawned>(OnEntitySpawned);
RegisterListener<Listeners.OnClientAuthorized>(OnClientAuthorized); RegisterListener<Listeners.OnClientPutInServer>(OnClientPutInServer);
RegisterListener<Listeners.OnClientDisconnect>(OnClientDisconnect); RegisterListener<Listeners.OnClientDisconnect>(OnClientDisconnect);
RegisterListener<Listeners.OnMapStart>(OnMapStart); RegisterListener<Listeners.OnMapStart>(OnMapStart);
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn); RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
@@ -76,6 +78,11 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
} }
public void OnConfigParsed(WeaponPaintsConfig config) public void OnConfigParsed(WeaponPaintsConfig config)
{ {
if (config.DatabaseHost.Length < 1 || config.DatabaseName.Length < 1 || config.DatabaseUser.Length < 1)
{
throw new Exception("You need to setup Database credentials in config!");
}
Config = config; Config = config;
} }
// TODO: fix for map which change mp_t_default_melee // TODO: fix for map which change mp_t_default_melee
@@ -113,7 +120,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
}); });
} }
private void OnClientAuthorized(int playerSlot, SteamID steamId) private void OnClientPutInServer(int playerSlot)
{ {
int playerIndex = playerSlot + 1; int playerIndex = playerSlot + 1;
Task.Run(async () => Task.Run(async () =>
@@ -125,16 +132,23 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
private void OnClientDisconnect(int playerSlot) private void OnClientDisconnect(int playerSlot)
{ {
// TODO: Clean up after player // TODO: Clean up after player
g_playersKnife.Remove(playerSlot+1);
} }
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info) private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
{ {
var player = @event.Userid; var player = @event.Userid;
if (!player.IsValid || !player.PlayerPawn.IsValid || player.IsBot) if (!player.IsValid || !player.PlayerPawn.IsValid)
{ {
return HookResult.Continue; return HookResult.Continue;
} }
if (!PlayerHasKnife(player)) player.GiveNamedItem(g_playersKife[(int)player.EntityIndex!.Value.Value]);
GiveKnifeToPlayer(player);
// Check the best slot and set it. Weird solution but works xD
AddTimer(0.1f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot3"));
AddTimer(0.25f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot2"));
AddTimer(0.35f, () => NativeAPI.IssueClientCommand((int)player.EntityIndex!.Value.Value - 1, "slot1"));
return HookResult.Continue; return HookResult.Continue;
} }
@@ -161,7 +175,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
var player = Utilities.GetPlayerFromIndex(playerIndex); var player = Utilities.GetPlayerFromIndex(playerIndex);
if (player == null || !player.IsValid || player.IsBot) return; if (player == null || !player.IsValid || player.IsBot) return;
// TODO: Remove knife crashes here, needs another solution // TODO: Remove knife crashes here, needs another solution
/*if (isKnife && g_playersKife[(int)player.EntityIndex!.Value.Value] != "weapon_knife" && (weapon.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.AttributeManager.Item.ItemDefinitionIndex == 59)) /*if (isKnife && g_playersKnife[(int)player.EntityIndex!.Value.Value] != "weapon_knife" && (weapon.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.AttributeManager.Item.ItemDefinitionIndex == 59))
{ {
RemoveKnifeFromPlayer(player); RemoveKnifeFromPlayer(player);
return; return;
@@ -183,9 +197,29 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
} }
}); });
} }
public void GiveKnifeToPlayer(CCSPlayerController player)
{
if (player.IsBot)
{
player.GiveNamedItem((CsTeam)player.TeamNum == CsTeam.Terrorist ? "weapon_knife_t" : "weapon_knife");
return;
}
if (!PlayerHasKnife(player))
{
if (g_playersKnife.TryGetValue((int)player.EntityIndex!.Value.Value, out var knife))
{
player.GiveNamedItem(knife);
}
else
{
player.GiveNamedItem((CsTeam)player.TeamNum == CsTeam.Terrorist ? "weapon_knife_t" : "weapon_knife");
}
}
}
public void RemoveKnifeFromPlayer(CCSPlayerController player) public void RemoveKnifeFromPlayer(CCSPlayerController player)
{ {
if (!player.PawnIsAlive) return; if (!g_playersKnife.ContainsKey((int)player.EntityIndex!.Value.Value)) return;
var weapons = player.PlayerPawn.Value.WeaponServices!.MyWeapons; var weapons = player.PlayerPawn.Value.WeaponServices!.MyWeapons;
foreach (var weapon in weapons) foreach (var weapon in weapons)
{ {
@@ -195,7 +229,6 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
if (weapon.Value.DesignerName.Contains("knife")) if (weapon.Value.DesignerName.Contains("knife"))
{ {
weapon.Value.Remove(); weapon.Value.Remove();
player.GiveNamedItem(g_playersKife[(int)player.EntityIndex!.Value.Value]);
break; break;
} }
} }
@@ -203,7 +236,6 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
} }
public static bool PlayerHasKnife(CCSPlayerController player) public static bool PlayerHasKnife(CCSPlayerController player)
{ {
if (!player.PawnIsAlive) return false;
var weapons = player.PlayerPawn.Value.WeaponServices!.MyWeapons; var weapons = player.PlayerPawn.Value.WeaponServices!.MyWeapons;
foreach (var weapon in weapons) foreach (var weapon in weapons)
{ {
@@ -219,15 +251,19 @@ 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_playersKife[(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);
GiveKnifeToPlayer(player);
} }
}; };
foreach (var knife in knifeTypes) foreach (var knife in knifeTypes)
@@ -240,23 +276,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)
{ {
@@ -275,7 +330,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
.Add("steamid", "=", steamId.SteamId64.ToString()); .Add("steamid", "=", steamId.SteamId64.ToString());
MySqlQueryResult result = await MySql!.Table("wp_player_skins").Where(conditions).SelectAsync(); MySqlQueryResult result = await MySql!.Table("wp_player_skins").Where(conditions).SelectAsync();
if (result.Rows < 1) return;
result.ToList().ForEach(pair => result.ToList().ForEach(pair =>
{ {
int WeaponDefIndex = result.Get<int>(pair.Key, "weapon_defindex"); int WeaponDefIndex = result.Get<int>(pair.Key, "weapon_defindex");
@@ -301,8 +356,9 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
gPlayerWeaponSeed[steamId.SteamId64][WeaponDefIndex] = Seed; gPlayerWeaponSeed[steamId.SteamId64][WeaponDefIndex] = Seed;
}); });
} }
catch (Exception) catch (Exception e)
{ {
Log(e.Message);
return; return;
} }
} }
@@ -318,20 +374,22 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
MySqlQueryResult result = await MySql!.Table("wp_player_knife").Where(conditions).SelectAsync(); MySqlQueryResult result = await MySql!.Table("wp_player_knife").Where(conditions).SelectAsync();
if (result.Rows < 1)
{
//g_playersKnife[playerIndex] = "weapon_knife";
return;
}
string knife = result.Get<string>(0, "knife"); string knife = result.Get<string>(0, "knife");
if (knife != null) if (knife != null)
{ {
g_playersKife[playerIndex] = knife; g_playersKnife[playerIndex] = knife;
} }
else //Log($"{player.PlayerName} has this knife -> {g_playersKnife[playerIndex]}");
{
g_playersKife[playerIndex] = "weapon_knife";
}
//Log($"{player.PlayerName} has this knife -> {g_playersKife[playerIndex]}");
} }
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine(e.Message); Log(e.Message);
return; return;
} }
} }
@@ -344,13 +402,33 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
var steamId = new SteamID(player.SteamID); var steamId = new SteamID(player.SteamID);
await MySql!.ExecuteNonQueryAsync($"INSERT INTO `wp_player_knife` (`steamid`, `knife`) VALUES('{steamId.SteamId64}', '{knife}') ON DUPLICATE KEY UPDATE `knife` = '{knife}';"); await MySql!.ExecuteNonQueryAsync($"INSERT INTO `wp_player_knife` (`steamid`, `knife`) VALUES('{steamId.SteamId64}', '{knife}') ON DUPLICATE KEY UPDATE `knife` = '{knife}';");
} }
catch (Exception ex) catch (Exception e)
{ {
Log(ex.Message); Log(e.Message);
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;
@@ -358,4 +436,4 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
Console.WriteLine(message); Console.WriteLine(message);
Console.ResetColor(); Console.ResetColor();
} }
} }

48
website/class/utils.php Normal file
View File

@@ -0,0 +1,48 @@
<?php
class UtilsClass
{
public static function skinsFromJson(): array
{
$skins = [];
$json = json_decode(file_get_contents(__DIR__ . "/../data/skins.json"), true);
foreach ($json as $skin) {
$skins[(int)$skin['weapon_defindex']][(int)$skin['paint']] = [
'paint_name' => $skin['paint_name'],
'image_url' => $skin['image'],
];
}
return $skins;
}
public static function getWeaponsFromArray()
{
$weapons = [];
$temp = self::skinsFromJson();
foreach ($temp as $key => $value)
{
if (key_exists($key, $weapons)) continue;
$weapons[$key] = [
'paint_name' => $value[0]['paint_name'],
'image_url' => $value[0]['image_url'],
];
}
return $weapons;
}
public static function getSelectedSkins(array $temp)
{
$selected = [];
foreach ($temp as $weapon)
{
$selected[$weapon['weapon_defindex']] = $weapon['weapon_paint_id'];
}
return $selected;
}
}

1
website/data/skins.json Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Some files were not shown because too many files have changed in this diff Show More