mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-03-09 16:18:48 +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;
|
||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API.Modules.Commands;
|
using CounterStrikeSharp.API.Modules.Commands;
|
||||||
@@ -40,6 +40,7 @@ namespace WeaponPaints
|
|||||||
GivePlayerGloves(player);
|
GivePlayerGloves(player);
|
||||||
GivePlayerAgent(player);
|
GivePlayerAgent(player);
|
||||||
GivePlayerMusicKit(player);
|
GivePlayerMusicKit(player);
|
||||||
|
GivePlayerPin(player);
|
||||||
RefreshWeapons(player);
|
RefreshWeapons(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,9 @@ namespace WeaponPaints
|
|||||||
[JsonPropertyName("NameTagEnabled")]
|
[JsonPropertyName("NameTagEnabled")]
|
||||||
public bool NameTagEnabled { get; set; } = true;
|
public bool NameTagEnabled { get; set; } = true;
|
||||||
|
|
||||||
|
[JsonPropertyName("PinEnabled")]
|
||||||
|
public bool PinEnabled { get; set; } = true;
|
||||||
|
|
||||||
[JsonPropertyName("CommandsKnife")]
|
[JsonPropertyName("CommandsKnife")]
|
||||||
public List<string> CommandsKnife { get; set; } = ["knife", "knives"];
|
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;
|
||||||
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
||||||
using CounterStrikeSharp.API.Modules.Entities;
|
using CounterStrikeSharp.API.Modules.Entities;
|
||||||
@@ -91,6 +91,10 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
g_playersMusic.TryRemove(player.Slot, out _);
|
g_playersMusic.TryRemove(player.Slot, out _);
|
||||||
}
|
}
|
||||||
|
if (Config.Additional.PinEnabled)
|
||||||
|
{
|
||||||
|
g_playersPin.TryRemove(player.Slot, out _);
|
||||||
|
}
|
||||||
|
|
||||||
commandsCooldown.Remove(player.Slot);
|
commandsCooldown.Remove(player.Slot);
|
||||||
|
|
||||||
@@ -125,6 +129,7 @@ namespace WeaponPaints
|
|||||||
GivePlayerMusicKit(player);
|
GivePlayerMusicKit(player);
|
||||||
GivePlayerAgent(player);
|
GivePlayerAgent(player);
|
||||||
GivePlayerGloves(player);
|
GivePlayerGloves(player);
|
||||||
|
GivePlayerPin(player);
|
||||||
|
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API.Core.Translations;
|
using CounterStrikeSharp.API.Core.Translations;
|
||||||
using Dapper;
|
using Dapper;
|
||||||
using Microsoft.Extensions.Logging;
|
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_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_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_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)
|
foreach (var query in createTableQueries)
|
||||||
|
|||||||
@@ -401,6 +401,18 @@ public partial class WeaponPaints
|
|||||||
Utilities.SetStateChanged(player, "CCSPlayerController", "m_iMusicKitID");
|
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)
|
private void GiveOnItemPickup(CCSPlayerController player)
|
||||||
{
|
{
|
||||||
var pawn = player.PlayerPawn.Value;
|
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_playersKnife = new();
|
||||||
internal static ConcurrentDictionary<int, ushort> g_playersGlove = new();
|
internal static ConcurrentDictionary<int, ushort> g_playersGlove = new();
|
||||||
internal static ConcurrentDictionary<int, ushort> g_playersMusic = 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, (string? CT, string? T)> g_playersAgent = new();
|
||||||
internal static ConcurrentDictionary<int, ConcurrentDictionary<ushort, WeaponInfo>> gPlayerWeaponsInfo = new();
|
internal static ConcurrentDictionary<int, ConcurrentDictionary<ushort, WeaponInfo>> gPlayerWeaponsInfo = new();
|
||||||
internal static ConcurrentDictionary<int, int> g_playersDatabaseIndex = new();
|
internal static ConcurrentDictionary<int, int> g_playersDatabaseIndex = new();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using Dapper;
|
using Dapper;
|
||||||
using MySqlConnector;
|
using MySqlConnector;
|
||||||
|
|
||||||
@@ -71,6 +71,8 @@ internal class WeaponSynchronization
|
|||||||
GetMusicFromDatabase(player, connection);
|
GetMusicFromDatabase(player, connection);
|
||||||
if (_config.Additional.SkinEnabled)
|
if (_config.Additional.SkinEnabled)
|
||||||
GetWeaponPaintsFromDatabase(player, connection);
|
GetWeaponPaintsFromDatabase(player, connection);
|
||||||
|
if (_config.Additional.PinEnabled)
|
||||||
|
GetPinFromDatabase(player, connection);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
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()
|
internal async Task PurgeExpiredUsers()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -234,6 +254,9 @@ internal class WeaponSynchronization
|
|||||||
query = $"DELETE FROM wp_users_musics WHERE user_id IN ({ids})";
|
query = $"DELETE FROM wp_users_musics WHERE user_id IN ({ids})";
|
||||||
await connection.ExecuteAsync(query, transaction: transaction);
|
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
|
// Step 3: Delete users from wp_users
|
||||||
query = $"DELETE FROM wp_users WHERE id IN ({ids})";
|
query = $"DELETE FROM wp_users WHERE id IN ({ids})";
|
||||||
await connection.ExecuteAsync(query, transaction: transaction);
|
await connection.ExecuteAsync(query, transaction: transaction);
|
||||||
|
|||||||
Reference in New Issue
Block a user