mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-18 18:49:21 +00:00
Basic pin feature
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Concurrent;
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Commands;
|
||||
@@ -40,6 +40,7 @@ namespace WeaponPaints
|
||||
GivePlayerGloves(player);
|
||||
GivePlayerAgent(player);
|
||||
GivePlayerMusicKit(player);
|
||||
GivePlayerPin(player);
|
||||
RefreshWeapons(player);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,9 @@ namespace WeaponPaints
|
||||
[JsonPropertyName("NameTagEnabled")]
|
||||
public bool NameTagEnabled { get; set; } = true;
|
||||
|
||||
[JsonPropertyName("PinEnabled")]
|
||||
public bool PinEnabled { get; set; } = true;
|
||||
|
||||
[JsonPropertyName("CommandsKnife")]
|
||||
public List<string> CommandsKnife { get; set; } = ["knife", "knives"];
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
||||
using CounterStrikeSharp.API.Modules.Entities;
|
||||
@@ -91,6 +91,10 @@ namespace WeaponPaints
|
||||
{
|
||||
g_playersMusic.TryRemove(player.Slot, out _);
|
||||
}
|
||||
if (Config.Additional.PinEnabled)
|
||||
{
|
||||
g_playersPin.TryRemove(player.Slot, out _);
|
||||
}
|
||||
|
||||
commandsCooldown.Remove(player.Slot);
|
||||
|
||||
@@ -125,6 +129,7 @@ namespace WeaponPaints
|
||||
GivePlayerMusicKit(player);
|
||||
GivePlayerAgent(player);
|
||||
GivePlayerGloves(player);
|
||||
GivePlayerPin(player);
|
||||
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core.Translations;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -30,7 +30,8 @@ namespace WeaponPaints
|
||||
"CREATE TABLE IF NOT EXISTS `wp_users_knives` (`user_id` INT UNSIGNED NOT NULL, `knife` SMALLINT UNSIGNED NOT NULL, PRIMARY KEY (`user_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
|
||||
"CREATE TABLE IF NOT EXISTS `wp_users_gloves` (`user_id` INT UNSIGNED NOT NULL, `weapon_defindex` SMALLINT UNSIGNED DEFAULT NULL, PRIMARY KEY (`user_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
|
||||
"CREATE TABLE IF NOT EXISTS `wp_users_musics` (`user_id` INT UNSIGNED NOT NULL, `music` SMALLINT UNSIGNED DEFAULT NULL, PRIMARY KEY (`user_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
|
||||
"CREATE TABLE IF NOT EXISTS `wp_users_agents` (`user_id` INT UNSIGNED NOT NULL,`agent_ct` varchar(64) DEFAULT NULL,`agent_t` varchar(64) DEFAULT NULL, PRIMARY KEY (`user_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;"
|
||||
"CREATE TABLE IF NOT EXISTS `wp_users_agents` (`user_id` INT UNSIGNED NOT NULL,`agent_ct` varchar(64) DEFAULT NULL,`agent_t` varchar(64) DEFAULT NULL, PRIMARY KEY (`user_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
|
||||
"CREATE TABLE IF NOT EXISTS `wp_users_pins` (`user_id` INT UNSIGNED NOT NULL, `pin` SMALLINT UNSIGNED DEFAULT NULL, PRIMARY KEY (`user_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
|
||||
};
|
||||
|
||||
foreach (var query in createTableQueries)
|
||||
|
||||
@@ -401,6 +401,18 @@ public partial class WeaponPaints
|
||||
Utilities.SetStateChanged(player, "CCSPlayerController", "m_iMusicKitID");
|
||||
}
|
||||
|
||||
private static void GivePlayerPin(CCSPlayerController player)
|
||||
{
|
||||
if (!g_playersPin.TryGetValue(player.Slot, out var value)) return;
|
||||
if (player.InventoryServices == null) return;
|
||||
|
||||
for (var index = 0; index < player.InventoryServices.Rank.Length; index++)
|
||||
{
|
||||
player.InventoryServices.Rank[index] = index == 5 ? (MedalRank_t)value : MedalRank_t.MEDAL_RANK_NONE;
|
||||
Utilities.SetStateChanged(player, "CCSPlayerController", "m_pInventoryServices");
|
||||
}
|
||||
}
|
||||
|
||||
private void GiveOnItemPickup(CCSPlayerController player)
|
||||
{
|
||||
var pawn = player.PlayerPawn.Value;
|
||||
|
||||
@@ -83,6 +83,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
||||
internal static ConcurrentDictionary<int, ushort> g_playersKnife = new();
|
||||
internal static ConcurrentDictionary<int, ushort> g_playersGlove = new();
|
||||
internal static ConcurrentDictionary<int, ushort> g_playersMusic = new();
|
||||
internal static ConcurrentDictionary<int, ushort> g_playersPin = new();
|
||||
internal static ConcurrentDictionary<int, (string? CT, string? T)> g_playersAgent = new();
|
||||
internal static ConcurrentDictionary<int, ConcurrentDictionary<ushort, WeaponInfo>> gPlayerWeaponsInfo = new();
|
||||
internal static ConcurrentDictionary<int, int> g_playersDatabaseIndex = new();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Concurrent;
|
||||
using Dapper;
|
||||
using MySqlConnector;
|
||||
|
||||
@@ -71,6 +71,8 @@ internal class WeaponSynchronization
|
||||
GetMusicFromDatabase(player, connection);
|
||||
if (_config.Additional.SkinEnabled)
|
||||
GetWeaponPaintsFromDatabase(player, connection);
|
||||
if (_config.Additional.PinEnabled)
|
||||
GetPinFromDatabase(player, connection);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -200,6 +202,24 @@ internal class WeaponSynchronization
|
||||
}
|
||||
}
|
||||
|
||||
private void GetPinFromDatabase(PlayerInfo? player, MySqlConnection connection)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!_config.Additional.PinEnabled || string.IsNullOrEmpty(player?.SteamId.ToString()))
|
||||
return;
|
||||
|
||||
const string query = "SELECT `pin` FROM `wp_users_pins` WHERE `user_id` = @userId";
|
||||
var pinData = connection.QueryFirstOrDefault<ushort?>(query, new { userId = WeaponPaints.g_playersDatabaseIndex[player.Slot] });
|
||||
|
||||
if (pinData != null) WeaponPaints.g_playersPin[player.Slot] = pinData.Value;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utility.Log($"An error occurred in GetPinFromDatabase: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task PurgeExpiredUsers()
|
||||
{
|
||||
try
|
||||
@@ -234,6 +254,9 @@ internal class WeaponSynchronization
|
||||
query = $"DELETE FROM wp_users_musics WHERE user_id IN ({ids})";
|
||||
await connection.ExecuteAsync(query, transaction: transaction);
|
||||
|
||||
query = $"DELETE FROM wp_users_pins WHERE user_id IN ({ids})";
|
||||
await connection.ExecuteAsync(query, transaction: transaction);
|
||||
|
||||
// Step 3: Delete users from wp_users
|
||||
query = $"DELETE FROM wp_users WHERE id IN ({ids})";
|
||||
await connection.ExecuteAsync(query, transaction: transaction);
|
||||
|
||||
Reference in New Issue
Block a user