diff --git a/Commands.cs b/Commands.cs index 3b082852..3a3db02a 100644 --- a/Commands.cs +++ b/Commands.cs @@ -1,4 +1,5 @@ using System.Collections.Concurrent; +using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Modules.Commands; using CounterStrikeSharp.API.Modules.Menu; @@ -106,6 +107,16 @@ private void OnCommandWS(CCSPlayerController? player, CommandInfo command) private void RegisterCommands() { + _config.Additional.CommandStattrak.ForEach(c => + { + AddCommand($"css_{c}", "Stattrak toggle", (player, info) => + { + if (!Utility.IsPlayerValid(player)) return; + + OnCommandStattrak(player, info); + }); + }); + _config.Additional.CommandSkin.ForEach(c => { AddCommand($"css_{c}", "Skins info", (player, info) => @@ -138,6 +149,38 @@ private void RegisterCommands() } } + private void OnCommandStattrak(CCSPlayerController? player, CommandInfo commandInfo) + { + if (player == null || !player.IsValid) return; + + if (!GPlayerWeaponsInfo.TryGetValue(player.Slot, out var teamInfo) || + !teamInfo.TryGetValue(player.Team, out var teamWeapons) ) + return; + + var weapon = player.PlayerPawn.Value?.WeaponServices?.ActiveWeapon.Value; + + if (weapon == null || !weapon.IsValid) + return; + if (!teamWeapons.TryGetValue(weapon.AttributeManager.Item.ItemDefinitionIndex, out var teamWeapon)) + return; + + if (teamWeapon.StatTrak) + { + teamWeapon.StatTrak = false; + RefreshWeapons(player); + } + else + { + teamWeapon.StatTrak = true; + RefreshWeapons(player); + } + + if (!string.IsNullOrEmpty(Localizer["wp_stattrak_action"])) + { + player.Print(Localizer["wp_stattrak_action"]); + } + } + private void SetupKnifeMenu() { if (!Config.Additional.KnifeEnabled || !_gBCommandsAllowed) return; diff --git a/Config.cs b/Config.cs index 0c8b29b4..9b0041e1 100644 --- a/Config.cs +++ b/Config.cs @@ -43,6 +43,9 @@ public class Additional [JsonPropertyName("CommandAgent")] public List CommandAgent { get; set; } = ["agents"]; + + [JsonPropertyName("CommandStattrak")] + public List CommandStattrak { get; set; } = ["stattrak", "st"]; [JsonPropertyName("CommandSkin")] public List CommandSkin { get; set; } = ["ws"]; @@ -68,7 +71,7 @@ public class Additional public class WeaponPaintsConfig : BasePluginConfig { - [JsonPropertyName("ConfigVersion")] public override int Version { get; set; } = 9; + [JsonPropertyName("ConfigVersion")] public override int Version { get; set; } = 10; [JsonPropertyName("SkinsLanguage")] public string SkinsLanguage { get; set; } = "en"; @@ -89,7 +92,7 @@ public class WeaponPaintsConfig : BasePluginConfig public string DatabaseName { get; set; } = ""; [JsonPropertyName("CmdRefreshCooldownSeconds")] - public int CmdRefreshCooldownSeconds { get; set; } = 10; + public int CmdRefreshCooldownSeconds { get; set; } = 3; [JsonPropertyName("Website")] public string Website { get; set; } = "example.com/skins"; diff --git a/Events.cs b/Events.cs index 22bdfefd..424ff64d 100644 --- a/Events.cs +++ b/Events.cs @@ -80,7 +80,9 @@ public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo }; if (WeaponSync != null) + { _ = Task.Run(async () => await WeaponSync.SyncStatTrakToDatabase(playerInfo)); + } if (Config.Additional.SkinEnabled) { @@ -106,7 +108,7 @@ public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo { GPlayersPin.TryRemove(player.Slot, out _); } - + _temporaryPlayerWeaponWear.TryRemove(player.Slot, out _); CommandsCooldown.Remove(player.Slot); @@ -116,7 +118,7 @@ public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo private void OnMapStart(string mapName) { if (Config.Additional is { KnifeEnabled: false, SkinEnabled: false, GloveEnabled: false }) return; - + if (Database != null) WeaponSync = new WeaponSynchronization(Database, Config); } diff --git a/VERSION b/VERSION index 9e77c679..4264043f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.9c \ No newline at end of file +3.0a \ No newline at end of file diff --git a/WeaponAction.cs b/WeaponAction.cs index ea93c1b5..6a969c57 100644 --- a/WeaponAction.cs +++ b/WeaponAction.cs @@ -36,6 +36,10 @@ private void GivePlayerWeaponSkin(CCSPlayerController player, CBasePlayerWeapon weapon.AttributeManager.Item.ItemDefinitionIndex = (ushort)newDefIndex.Key; weapon.AttributeManager.Item.EntityQuality = 3; } + else + { + weapon.AttributeManager.Item.EntityQuality = 0; + } UpdatePlayerEconItemId(weapon.AttributeManager.Item); @@ -99,7 +103,9 @@ private void GivePlayerWeaponSkin(CCSPlayerController player, CBasePlayerWeapon CAttributeListSetOrAddAttributeValueByName.Invoke(weapon.AttributeManager.Item.NetworkedDynamicAttributes.Handle, "set item texture prefab", weapon.FallbackPaintKit); if (weaponInfo.StatTrak) - { + { + weapon.AttributeManager.Item.EntityQuality = 7; + CAttributeListSetOrAddAttributeValueByName.Invoke(weapon.AttributeManager.Item.NetworkedDynamicAttributes.Handle, "kill eater", ViewAsFloat((uint)weaponInfo.StatTrakCount)); CAttributeListSetOrAddAttributeValueByName.Invoke(weapon.AttributeManager.Item.NetworkedDynamicAttributes.Handle, "kill eater score type", 0); diff --git a/WeaponInfo.cs b/WeaponInfo.cs index 1bd66f6a..4c9dda1a 100644 --- a/WeaponInfo.cs +++ b/WeaponInfo.cs @@ -6,7 +6,7 @@ public class WeaponInfo public int Seed { get; set; } public float Wear { get; set; } public string Nametag { get; set; } = ""; - public bool StatTrak { get; set; } = false; + public bool StatTrak { get; set; } public int StatTrakCount { get; set; } public KeyChainInfo? KeyChain { get; set; } public List Stickers { get; set; } = new(); diff --git a/WeaponPaints.cs b/WeaponPaints.cs index dec0aa3d..adac6a71 100644 --- a/WeaponPaints.cs +++ b/WeaponPaints.cs @@ -16,7 +16,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig "Nereziel & daffyy"; public override string ModuleDescription => "Skin, gloves, agents and knife selector, standalone and web-based"; public override string ModuleName => "WeaponPaints"; - public override string ModuleVersion => "2.9c"; + public override string ModuleVersion => "3.0a"; public override void Load(bool hotReload) { diff --git a/WeaponSynchronization.cs b/WeaponSynchronization.cs index e852b15d..9960294e 100644 --- a/WeaponSynchronization.cs +++ b/WeaponSynchronization.cs @@ -566,7 +566,6 @@ internal async Task SyncPinToDatabase(PlayerInfo player, ushort pin, CsTeam[] te internal async Task SyncStatTrakToDatabase(PlayerInfo player) { if (WeaponPaints.WeaponSync == null || WeaponPaints.GPlayerWeaponsInfo.IsEmpty) return; - if (string.IsNullOrEmpty(player.SteamId)) return; @@ -578,7 +577,7 @@ internal async Task SyncStatTrakToDatabase(PlayerInfo player) // Check if player's slot exists in GPlayerWeaponsInfo if (!WeaponPaints.GPlayerWeaponsInfo.TryGetValue(player.Slot, out var teamWeaponsInfo)) return; - + // Iterate through each team in the player's weapon info foreach (var teamInfo in teamWeaponsInfo) { @@ -587,27 +586,33 @@ internal async Task SyncStatTrakToDatabase(PlayerInfo player) // Get StatTrak weapons for the current team var statTrakWeapons = weaponInfos - .Where(w => w.Value is { StatTrak: true, StatTrakCount: > 0 }) - .ToDictionary(w => w.Key, w => w.Value.StatTrakCount); + .ToDictionary( + w => w.Key, + w => (w.Value.StatTrak, w.Value.StatTrakCount) // Store both StatTrak and StatTrakCount in a tuple + ); // Check if there are StatTrak weapons to sync if (statTrakWeapons.Count == 0) continue; - + // Get the current team ID int weaponTeam = (int)teamInfo.Key; // Sync StatTrak values for the current team - foreach (var (defindex, statTrakCount) in statTrakWeapons) + foreach (var (defindex, (statTrak, statTrakCount)) in statTrakWeapons) { - const string query = @" - INSERT INTO `wp_player_skins` (`steamid`, `weapon_defindex`, `weapon_stattrak_count`, `weapon_team`) - VALUES (@steamid, @weaponDefIndex, @StatTrakCount, @weaponTeam) - ON DUPLICATE KEY UPDATE `weapon_stattrak_count` = @StatTrakCount"; + const string query = @" + UPDATE `wp_player_skins` + SET `weapon_stattrak` = @StatTrak, + `weapon_stattrak_count` = @StatTrakCount + WHERE `steamid` = @steamid + AND `weapon_defindex` = @weaponDefIndex + AND `weapon_team` = @weaponTeam"; var parameters = new { steamid = player.SteamId, weaponDefIndex = defindex, + StatTrak = statTrak, StatTrakCount = statTrakCount, weaponTeam }; diff --git a/lang/en.json b/lang/en.json index 7aa58373..162e9347 100644 --- a/lang/en.json +++ b/lang/en.json @@ -24,5 +24,7 @@ "wp_skin_menu_skin_title": "Select skin for {lime}{0}{default}", "wp_skin_menu_select": "You have chosen {lime}{0}{default} as your skin", + "wp_stattrak_action": "You have successfully changed the stattrak setting", + "None": "None" } \ No newline at end of file diff --git a/lang/lv.json b/lang/lv.json index c81b071e..f95e1678 100644 --- a/lang/lv.json +++ b/lang/lv.json @@ -23,6 +23,8 @@ "wp_skin_menu_weapon_title": "Ieroču Izvēlne", "wp_skin_menu_skin_title": "Izvēlieties ādu priekš {lime}{0}{default}", "wp_skin_menu_select": "Jūs esat izvēlējies {lime}{0}{default} kā savu ādu", - + + "wp_stattrak_action": "Jūs veiksmīgi mainījāt stattrak iestatījumu", + "None": "Nav" } \ No newline at end of file diff --git a/lang/pl.json b/lang/pl.json index c1a4cd49..582e8693 100644 --- a/lang/pl.json +++ b/lang/pl.json @@ -24,5 +24,7 @@ "wp_skin_menu_skin_title": "Wybierz skórkę dla {lime}{0}{default}", "wp_skin_menu_select": "Wybrałeś {lime}{0}{default} jako swoją skórkę", + "wp_stattrak_action": "Pomyślnie zmieniłeś ustawienie stattraka", + "None": "Brak" } \ No newline at end of file diff --git a/lang/pt-BR.json b/lang/pt-BR.json index c7c43608..45a6d027 100644 --- a/lang/pt-BR.json +++ b/lang/pt-BR.json @@ -24,5 +24,7 @@ "wp_skin_menu_skin_title": "Selecione a skin para {lime}{0}{default}", "wp_skin_menu_select": "Você escolheu {lime}{0}{default} como sua skin", + "wp_stattrak_action": "Você alterou a configuração de stattrak com sucesso", + "None": "Nenhum" } \ No newline at end of file diff --git a/lang/pt-PT.json b/lang/pt-PT.json index 28c9674b..1a15186c 100644 --- a/lang/pt-PT.json +++ b/lang/pt-PT.json @@ -24,5 +24,7 @@ "wp_skin_menu_skin_title": "Selecione a skin para {lime}{0}{default}", "wp_skin_menu_select": "Escolheu {lime}{0}{default} como a sua skin", + "wp_stattrak_action": "Alterou com sucesso a configuração do stattrak", + "None": "Nenhum" } \ No newline at end of file diff --git a/lang/ru.json b/lang/ru.json index 81d770bc..88ee79e3 100644 --- a/lang/ru.json +++ b/lang/ru.json @@ -24,5 +24,7 @@ "wp_skin_menu_skin_title": "Выберите скин для {lime}{0}{default}", "wp_skin_menu_select": "Вы выбрали {lime}{0}{default} в качестве вашего скина", + "wp_stattrak_action": "Вы успешно изменили настройки статтрак", + "None": "Нет" } \ No newline at end of file diff --git a/lang/tr.json b/lang/tr.json index 43d36ba3..0efd2a85 100644 --- a/lang/tr.json +++ b/lang/tr.json @@ -24,5 +24,7 @@ "wp_skin_menu_skin_title": "{lime}{0}{default} için cilt seçin", "wp_skin_menu_select": "{lime}{0}{default} olarak cildinizi seçtiniz", + "wp_stattrak_action": "StatTrak ayarını başarıyla değiştirdiniz", + "None": "Hiçbiri" } \ No newline at end of file diff --git a/lang/ua.json b/lang/ua.json index 34aa3309..8457962e 100644 --- a/lang/ua.json +++ b/lang/ua.json @@ -24,5 +24,7 @@ "wp_skin_menu_skin_title": "Виберіть шкіру для {lime}{0}{default}", "wp_skin_menu_select": "Ви обрали {lime}{0}{default} як свою шкіру", + "wp_stattrak_action": "Ви успішно змінили налаштування статтрака", + "None": "Немає" } \ No newline at end of file diff --git a/lang/zh-cn.json b/lang/zh-cn.json index 4e82faaf..308f0385 100644 --- a/lang/zh-cn.json +++ b/lang/zh-cn.json @@ -24,5 +24,7 @@ "wp_skin_menu_skin_title": "选择 {lime}{0}{default} 的皮肤", "wp_skin_menu_select": "您选择了 {lime}{0}{default} 作为您的皮肤", + "wp_stattrak_action": "您已成功更改 StatTrak 设置", + "None": "无" } \ No newline at end of file