Skip to content

Commit

Permalink
3.0a
Browse files Browse the repository at this point in the history
- Stattrak fix & command
  • Loading branch information
daffyyyy committed Oct 20, 2024
1 parent 845a40c commit e3011c5
Show file tree
Hide file tree
Showing 17 changed files with 96 additions and 19 deletions.
43 changes: 43 additions & 0 deletions Commands.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) =>
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public class Additional

[JsonPropertyName("CommandAgent")]
public List<string> CommandAgent { get; set; } = ["agents"];

[JsonPropertyName("CommandStattrak")]
public List<string> CommandStattrak { get; set; } = ["stattrak", "st"];

[JsonPropertyName("CommandSkin")]
public List<string> CommandSkin { get; set; } = ["ws"];
Expand All @@ -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";
Expand All @@ -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";
Expand Down
6 changes: 4 additions & 2 deletions Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo
};

if (WeaponSync != null)
{
_ = Task.Run(async () => await WeaponSync.SyncStatTrakToDatabase(playerInfo));
}

if (Config.Additional.SkinEnabled)
{
Expand All @@ -106,7 +108,7 @@ public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo
{
GPlayersPin.TryRemove(player.Slot, out _);
}

_temporaryPlayerWeaponWear.TryRemove(player.Slot, out _);
CommandsCooldown.Remove(player.Slot);

Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.9c
3.0a
8 changes: 7 additions & 1 deletion WeaponAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion WeaponInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<StickerInfo> Stickers { get; set; } = new();
Expand Down
2 changes: 1 addition & 1 deletion WeaponPaints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
public override string ModuleAuthor => "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)
{
Expand Down
25 changes: 15 additions & 10 deletions WeaponSynchronization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
{
Expand All @@ -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
};
Expand Down
2 changes: 2 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
4 changes: 3 additions & 1 deletion lang/lv.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 2 additions & 0 deletions lang/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 2 additions & 0 deletions lang/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 2 additions & 0 deletions lang/pt-PT.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 2 additions & 0 deletions lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@
"wp_skin_menu_skin_title": "Выберите скин для {lime}{0}{default}",
"wp_skin_menu_select": "Вы выбрали {lime}{0}{default} в качестве вашего скина",

"wp_stattrak_action": "Вы успешно изменили настройки статтрак",

"None": "Нет"
}
2 changes: 2 additions & 0 deletions lang/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 2 additions & 0 deletions lang/ua.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@
"wp_skin_menu_skin_title": "Виберіть шкіру для {lime}{0}{default}",
"wp_skin_menu_select": "Ви обрали {lime}{0}{default} як свою шкіру",

"wp_stattrak_action": "Ви успішно змінили налаштування статтрака",

"None": "Немає"
}
2 changes: 2 additions & 0 deletions lang/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@
"wp_skin_menu_skin_title": "选择 {lime}{0}{default} 的皮肤",
"wp_skin_menu_select": "您选择了 {lime}{0}{default} 作为您的皮肤",

"wp_stattrak_action": "您已成功更改 StatTrak 设置",

"None": ""
}

0 comments on commit e3011c5

Please sign in to comment.