mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-17 18:39:07 +00:00
3.0a
- Stattrak fix & command
This commit is contained in:
43
Commands.cs
43
Commands.cs
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using CounterStrikeSharp.API;
|
||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API.Modules.Commands;
|
using CounterStrikeSharp.API.Modules.Commands;
|
||||||
using CounterStrikeSharp.API.Modules.Menu;
|
using CounterStrikeSharp.API.Modules.Menu;
|
||||||
@@ -106,6 +107,16 @@ public partial class WeaponPaints
|
|||||||
|
|
||||||
private void RegisterCommands()
|
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 =>
|
_config.Additional.CommandSkin.ForEach(c =>
|
||||||
{
|
{
|
||||||
AddCommand($"css_{c}", "Skins info", (player, info) =>
|
AddCommand($"css_{c}", "Skins info", (player, info) =>
|
||||||
@@ -138,6 +149,38 @@ public partial class WeaponPaints
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()
|
private void SetupKnifeMenu()
|
||||||
{
|
{
|
||||||
if (!Config.Additional.KnifeEnabled || !_gBCommandsAllowed) return;
|
if (!Config.Additional.KnifeEnabled || !_gBCommandsAllowed) return;
|
||||||
|
|||||||
@@ -44,6 +44,9 @@ namespace WeaponPaints
|
|||||||
[JsonPropertyName("CommandAgent")]
|
[JsonPropertyName("CommandAgent")]
|
||||||
public List<string> CommandAgent { get; set; } = ["agents"];
|
public List<string> CommandAgent { get; set; } = ["agents"];
|
||||||
|
|
||||||
|
[JsonPropertyName("CommandStattrak")]
|
||||||
|
public List<string> CommandStattrak { get; set; } = ["stattrak", "st"];
|
||||||
|
|
||||||
[JsonPropertyName("CommandSkin")]
|
[JsonPropertyName("CommandSkin")]
|
||||||
public List<string> CommandSkin { get; set; } = ["ws"];
|
public List<string> CommandSkin { get; set; } = ["ws"];
|
||||||
|
|
||||||
@@ -68,7 +71,7 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
public class WeaponPaintsConfig : BasePluginConfig
|
public class WeaponPaintsConfig : BasePluginConfig
|
||||||
{
|
{
|
||||||
[JsonPropertyName("ConfigVersion")] public override int Version { get; set; } = 9;
|
[JsonPropertyName("ConfigVersion")] public override int Version { get; set; } = 10;
|
||||||
|
|
||||||
[JsonPropertyName("SkinsLanguage")]
|
[JsonPropertyName("SkinsLanguage")]
|
||||||
public string SkinsLanguage { get; set; } = "en";
|
public string SkinsLanguage { get; set; } = "en";
|
||||||
@@ -89,7 +92,7 @@ namespace WeaponPaints
|
|||||||
public string DatabaseName { get; set; } = "";
|
public string DatabaseName { get; set; } = "";
|
||||||
|
|
||||||
[JsonPropertyName("CmdRefreshCooldownSeconds")]
|
[JsonPropertyName("CmdRefreshCooldownSeconds")]
|
||||||
public int CmdRefreshCooldownSeconds { get; set; } = 10;
|
public int CmdRefreshCooldownSeconds { get; set; } = 3;
|
||||||
|
|
||||||
[JsonPropertyName("Website")]
|
[JsonPropertyName("Website")]
|
||||||
public string Website { get; set; } = "example.com/skins";
|
public string Website { get; set; } = "example.com/skins";
|
||||||
|
|||||||
@@ -80,7 +80,9 @@ namespace WeaponPaints
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (WeaponSync != null)
|
if (WeaponSync != null)
|
||||||
|
{
|
||||||
_ = Task.Run(async () => await WeaponSync.SyncStatTrakToDatabase(playerInfo));
|
_ = Task.Run(async () => await WeaponSync.SyncStatTrakToDatabase(playerInfo));
|
||||||
|
}
|
||||||
|
|
||||||
if (Config.Additional.SkinEnabled)
|
if (Config.Additional.SkinEnabled)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -36,6 +36,10 @@ namespace WeaponPaints
|
|||||||
weapon.AttributeManager.Item.ItemDefinitionIndex = (ushort)newDefIndex.Key;
|
weapon.AttributeManager.Item.ItemDefinitionIndex = (ushort)newDefIndex.Key;
|
||||||
weapon.AttributeManager.Item.EntityQuality = 3;
|
weapon.AttributeManager.Item.EntityQuality = 3;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
weapon.AttributeManager.Item.EntityQuality = 0;
|
||||||
|
}
|
||||||
|
|
||||||
UpdatePlayerEconItemId(weapon.AttributeManager.Item);
|
UpdatePlayerEconItemId(weapon.AttributeManager.Item);
|
||||||
|
|
||||||
@@ -100,6 +104,8 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
if (weaponInfo.StatTrak)
|
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", ViewAsFloat((uint)weaponInfo.StatTrakCount));
|
||||||
CAttributeListSetOrAddAttributeValueByName.Invoke(weapon.AttributeManager.Item.NetworkedDynamicAttributes.Handle, "kill eater score type", 0);
|
CAttributeListSetOrAddAttributeValueByName.Invoke(weapon.AttributeManager.Item.NetworkedDynamicAttributes.Handle, "kill eater score type", 0);
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
public int Seed { get; set; }
|
public int Seed { get; set; }
|
||||||
public float Wear { get; set; }
|
public float Wear { get; set; }
|
||||||
public string Nametag { get; set; } = "";
|
public string Nametag { get; set; } = "";
|
||||||
public bool StatTrak { get; set; } = false;
|
public bool StatTrak { get; set; }
|
||||||
public int StatTrakCount { get; set; }
|
public int StatTrakCount { get; set; }
|
||||||
public KeyChainInfo? KeyChain { get; set; }
|
public KeyChainInfo? KeyChain { get; set; }
|
||||||
public List<StickerInfo> Stickers { get; set; } = new();
|
public List<StickerInfo> Stickers { get; set; } = new();
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
public override string ModuleAuthor => "Nereziel & daffyy";
|
public override string ModuleAuthor => "Nereziel & daffyy";
|
||||||
public override string ModuleDescription => "Skin, gloves, agents and knife selector, standalone and web-based";
|
public override string ModuleDescription => "Skin, gloves, agents and knife selector, standalone and web-based";
|
||||||
public override string ModuleName => "WeaponPaints";
|
public override string ModuleName => "WeaponPaints";
|
||||||
public override string ModuleVersion => "2.9c";
|
public override string ModuleVersion => "3.0a";
|
||||||
|
|
||||||
public override void Load(bool hotReload)
|
public override void Load(bool hotReload)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -566,7 +566,6 @@ internal class WeaponSynchronization
|
|||||||
internal async Task SyncStatTrakToDatabase(PlayerInfo player)
|
internal async Task SyncStatTrakToDatabase(PlayerInfo player)
|
||||||
{
|
{
|
||||||
if (WeaponPaints.WeaponSync == null || WeaponPaints.GPlayerWeaponsInfo.IsEmpty) return;
|
if (WeaponPaints.WeaponSync == null || WeaponPaints.GPlayerWeaponsInfo.IsEmpty) return;
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(player.SteamId))
|
if (string.IsNullOrEmpty(player.SteamId))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -587,8 +586,10 @@ internal class WeaponSynchronization
|
|||||||
|
|
||||||
// Get StatTrak weapons for the current team
|
// Get StatTrak weapons for the current team
|
||||||
var statTrakWeapons = weaponInfos
|
var statTrakWeapons = weaponInfos
|
||||||
.Where(w => w.Value is { StatTrak: true, StatTrakCount: > 0 })
|
.ToDictionary(
|
||||||
.ToDictionary(w => w.Key, w => w.Value.StatTrakCount);
|
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
|
// Check if there are StatTrak weapons to sync
|
||||||
if (statTrakWeapons.Count == 0) continue;
|
if (statTrakWeapons.Count == 0) continue;
|
||||||
@@ -597,17 +598,21 @@ internal class WeaponSynchronization
|
|||||||
int weaponTeam = (int)teamInfo.Key;
|
int weaponTeam = (int)teamInfo.Key;
|
||||||
|
|
||||||
// Sync StatTrak values for the current team
|
// Sync StatTrak values for the current team
|
||||||
foreach (var (defindex, statTrakCount) in statTrakWeapons)
|
foreach (var (defindex, (statTrak, statTrakCount)) in statTrakWeapons)
|
||||||
{
|
{
|
||||||
const string query = @"
|
const string query = @"
|
||||||
INSERT INTO `wp_player_skins` (`steamid`, `weapon_defindex`, `weapon_stattrak_count`, `weapon_team`)
|
UPDATE `wp_player_skins`
|
||||||
VALUES (@steamid, @weaponDefIndex, @StatTrakCount, @weaponTeam)
|
SET `weapon_stattrak` = @StatTrak,
|
||||||
ON DUPLICATE KEY UPDATE `weapon_stattrak_count` = @StatTrakCount";
|
`weapon_stattrak_count` = @StatTrakCount
|
||||||
|
WHERE `steamid` = @steamid
|
||||||
|
AND `weapon_defindex` = @weaponDefIndex
|
||||||
|
AND `weapon_team` = @weaponTeam";
|
||||||
|
|
||||||
var parameters = new
|
var parameters = new
|
||||||
{
|
{
|
||||||
steamid = player.SteamId,
|
steamid = player.SteamId,
|
||||||
weaponDefIndex = defindex,
|
weaponDefIndex = defindex,
|
||||||
|
StatTrak = statTrak,
|
||||||
StatTrakCount = statTrakCount,
|
StatTrakCount = statTrakCount,
|
||||||
weaponTeam
|
weaponTeam
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -24,5 +24,7 @@
|
|||||||
"wp_skin_menu_skin_title": "Select skin for {lime}{0}{default}",
|
"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_skin_menu_select": "You have chosen {lime}{0}{default} as your skin",
|
||||||
|
|
||||||
|
"wp_stattrak_action": "You have successfully changed the stattrak setting",
|
||||||
|
|
||||||
"None": "None"
|
"None": "None"
|
||||||
}
|
}
|
||||||
@@ -24,5 +24,7 @@
|
|||||||
"wp_skin_menu_skin_title": "Izvēlieties ādu priekš {lime}{0}{default}",
|
"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_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"
|
"None": "Nav"
|
||||||
}
|
}
|
||||||
@@ -24,5 +24,7 @@
|
|||||||
"wp_skin_menu_skin_title": "Wybierz skórkę dla {lime}{0}{default}",
|
"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_skin_menu_select": "Wybrałeś {lime}{0}{default} jako swoją skórkę",
|
||||||
|
|
||||||
|
"wp_stattrak_action": "Pomyślnie zmieniłeś ustawienie stattraka",
|
||||||
|
|
||||||
"None": "Brak"
|
"None": "Brak"
|
||||||
}
|
}
|
||||||
@@ -24,5 +24,7 @@
|
|||||||
"wp_skin_menu_skin_title": "Selecione a skin para {lime}{0}{default}",
|
"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_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"
|
"None": "Nenhum"
|
||||||
}
|
}
|
||||||
@@ -24,5 +24,7 @@
|
|||||||
"wp_skin_menu_skin_title": "Selecione a skin para {lime}{0}{default}",
|
"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_skin_menu_select": "Escolheu {lime}{0}{default} como a sua skin",
|
||||||
|
|
||||||
|
"wp_stattrak_action": "Alterou com sucesso a configuração do stattrak",
|
||||||
|
|
||||||
"None": "Nenhum"
|
"None": "Nenhum"
|
||||||
}
|
}
|
||||||
@@ -24,5 +24,7 @@
|
|||||||
"wp_skin_menu_skin_title": "Выберите скин для {lime}{0}{default}",
|
"wp_skin_menu_skin_title": "Выберите скин для {lime}{0}{default}",
|
||||||
"wp_skin_menu_select": "Вы выбрали {lime}{0}{default} в качестве вашего скина",
|
"wp_skin_menu_select": "Вы выбрали {lime}{0}{default} в качестве вашего скина",
|
||||||
|
|
||||||
|
"wp_stattrak_action": "Вы успешно изменили настройки статтрак",
|
||||||
|
|
||||||
"None": "Нет"
|
"None": "Нет"
|
||||||
}
|
}
|
||||||
@@ -24,5 +24,7 @@
|
|||||||
"wp_skin_menu_skin_title": "{lime}{0}{default} için cilt seçin",
|
"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_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"
|
"None": "Hiçbiri"
|
||||||
}
|
}
|
||||||
@@ -24,5 +24,7 @@
|
|||||||
"wp_skin_menu_skin_title": "Виберіть шкіру для {lime}{0}{default}",
|
"wp_skin_menu_skin_title": "Виберіть шкіру для {lime}{0}{default}",
|
||||||
"wp_skin_menu_select": "Ви обрали {lime}{0}{default} як свою шкіру",
|
"wp_skin_menu_select": "Ви обрали {lime}{0}{default} як свою шкіру",
|
||||||
|
|
||||||
|
"wp_stattrak_action": "Ви успішно змінили налаштування статтрака",
|
||||||
|
|
||||||
"None": "Немає"
|
"None": "Немає"
|
||||||
}
|
}
|
||||||
@@ -24,5 +24,7 @@
|
|||||||
"wp_skin_menu_skin_title": "选择 {lime}{0}{default} 的皮肤",
|
"wp_skin_menu_skin_title": "选择 {lime}{0}{default} 的皮肤",
|
||||||
"wp_skin_menu_select": "您选择了 {lime}{0}{default} 作为您的皮肤",
|
"wp_skin_menu_select": "您选择了 {lime}{0}{default} 作为您的皮肤",
|
||||||
|
|
||||||
|
"wp_stattrak_action": "您已成功更改 StatTrak 设置",
|
||||||
|
|
||||||
"None": "无"
|
"None": "无"
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user