- Stattrak fix & command
This commit is contained in:
Dawid Bepierszcz
2024-10-20 15:00:13 +02:00
parent 845a40c189
commit e3011c51ae
17 changed files with 96 additions and 19 deletions

View File

@@ -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 @@ public partial class WeaponPaints
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 @@ 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()
{
if (!Config.Additional.KnifeEnabled || !_gBCommandsAllowed) return;