mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-18 10:43:22 +00:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48b9679236 | ||
|
|
7493ee4c7f | ||
|
|
027a547052 | ||
|
|
686c225f4f | ||
|
|
a5397e3831 | ||
|
|
1b95ddb089 | ||
|
|
7d4078dc40 | ||
|
|
e3011c51ae | ||
|
|
b99f30deb2 | ||
|
|
44c59e6bac | ||
|
|
845a40c189 | ||
|
|
f93bed46f1 | ||
|
|
ccee3e52c9 | ||
|
|
7d33693930 | ||
|
|
7b868611e5 | ||
|
|
b7289dd1e8 |
35
Commands.cs
35
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 @@ 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,30 @@ 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;
|
||||
|
||||
teamWeapon.StatTrak = !teamWeapon.StatTrak;
|
||||
RefreshWeapons(player);
|
||||
|
||||
if (!string.IsNullOrEmpty(Localizer["wp_stattrak_action"]))
|
||||
{
|
||||
player.Print(Localizer["wp_stattrak_action"]);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupKnifeMenu()
|
||||
{
|
||||
if (!Config.Additional.KnifeEnabled || !_gBCommandsAllowed) return;
|
||||
|
||||
@@ -43,6 +43,9 @@ namespace WeaponPaints
|
||||
|
||||
[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"];
|
||||
@@ -68,7 +71,7 @@ namespace WeaponPaints
|
||||
|
||||
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 @@ namespace WeaponPaints
|
||||
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";
|
||||
|
||||
45
Events.cs
45
Events.cs
@@ -9,6 +9,8 @@ namespace WeaponPaints
|
||||
{
|
||||
public partial class WeaponPaints
|
||||
{
|
||||
private bool _mvpPlayed;
|
||||
|
||||
[GameEventHandler]
|
||||
public HookResult OnClientFullConnect(EventPlayerConnectFull @event, GameEventInfo info)
|
||||
{
|
||||
@@ -78,7 +80,9 @@ namespace WeaponPaints
|
||||
};
|
||||
|
||||
if (WeaponSync != null)
|
||||
{
|
||||
_ = Task.Run(async () => await WeaponSync.SyncStatTrakToDatabase(playerInfo));
|
||||
}
|
||||
|
||||
if (Config.Additional.SkinEnabled)
|
||||
{
|
||||
@@ -104,7 +108,7 @@ namespace WeaponPaints
|
||||
{
|
||||
GPlayersPin.TryRemove(player.Slot, out _);
|
||||
}
|
||||
|
||||
|
||||
_temporaryPlayerWeaponWear.TryRemove(player.Slot, out _);
|
||||
CommandsCooldown.Remove(player.Slot);
|
||||
|
||||
@@ -114,9 +118,12 @@ namespace WeaponPaints
|
||||
private void OnMapStart(string mapName)
|
||||
{
|
||||
if (Config.Additional is { KnifeEnabled: false, SkinEnabled: false, GloveEnabled: false }) return;
|
||||
|
||||
|
||||
if (Database != null)
|
||||
WeaponSync = new WeaponSynchronization(Database, Config);
|
||||
|
||||
_fadeSeed = 0;
|
||||
_nextItemId = MinimumCustomItemId;
|
||||
}
|
||||
|
||||
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
|
||||
@@ -148,6 +155,39 @@ namespace WeaponPaints
|
||||
private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)
|
||||
{
|
||||
_gBCommandsAllowed = true;
|
||||
_mvpPlayed = false;
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
private HookResult OnRoundMvp(EventRoundMvp @event, GameEventInfo info)
|
||||
{
|
||||
if (_mvpPlayed)
|
||||
return HookResult.Continue;
|
||||
|
||||
var player = @event.Userid;
|
||||
|
||||
if (player == null || !player.IsValid || player.IsBot)
|
||||
return HookResult.Continue;
|
||||
|
||||
if (!(GPlayersMusic.TryGetValue(player.Slot, out var musicInfo)
|
||||
&& musicInfo.TryGetValue(player.Team, out var musicId)
|
||||
&& musicId != 0))
|
||||
return HookResult.Continue;
|
||||
|
||||
@event.Musickitid = musicId;
|
||||
@event.Nomusic = 0;
|
||||
info.DontBroadcast = true;
|
||||
|
||||
var newEvent = new EventRoundMvp(true)
|
||||
{
|
||||
Userid = player,
|
||||
Musickitid = musicId,
|
||||
Nomusic = 0,
|
||||
};
|
||||
|
||||
_mvpPlayed = true;
|
||||
|
||||
newEvent.FireEvent(false);
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
@@ -289,6 +329,7 @@ namespace WeaponPaints
|
||||
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
|
||||
RegisterEventHandler<EventRoundStart>(OnRoundStart);
|
||||
RegisterEventHandler<EventRoundEnd>(OnRoundEnd);
|
||||
RegisterEventHandler<EventRoundMvp>(OnRoundMvp);
|
||||
RegisterListener<Listeners.OnEntityCreated>(OnEntityCreated);
|
||||
RegisterEventHandler<EventPlayerDeath>(OnPlayerDeath);
|
||||
|
||||
|
||||
@@ -165,4 +165,6 @@ public partial class WeaponPaints
|
||||
|
||||
internal static IMenuApi? MenuApi;
|
||||
private static readonly PluginCapability<IMenuApi> MenuCapability = new("menu:nfcore");
|
||||
|
||||
private int _fadeSeed;
|
||||
}
|
||||
@@ -36,11 +36,15 @@ namespace WeaponPaints
|
||||
weapon.AttributeManager.Item.ItemDefinitionIndex = (ushort)newDefIndex.Key;
|
||||
weapon.AttributeManager.Item.EntityQuality = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
weapon.AttributeManager.Item.EntityQuality = 0;
|
||||
}
|
||||
|
||||
UpdatePlayerEconItemId(weapon.AttributeManager.Item);
|
||||
|
||||
int weaponDefIndex = weapon.AttributeManager.Item.ItemDefinitionIndex;
|
||||
int fallbackPaintKit = 0;
|
||||
int fallbackPaintKit;
|
||||
|
||||
weapon.AttributeManager.Item.AccountID = (uint)player.SteamID;
|
||||
|
||||
@@ -94,12 +98,23 @@ namespace WeaponPaints
|
||||
weapon.AttributeManager.Item.ItemIDHigh = weapon.AttributeManager.Item.ItemIDLow >> 32;
|
||||
weapon.AttributeManager.Item.CustomName = weaponInfo.Nametag;
|
||||
weapon.FallbackPaintKit = weaponInfo.Paint;
|
||||
weapon.FallbackSeed = weaponInfo.Seed;
|
||||
|
||||
if (weaponInfo is { Paint: 38, Seed: 0 })
|
||||
{
|
||||
weapon.FallbackSeed = _fadeSeed++;
|
||||
}
|
||||
else
|
||||
{
|
||||
weapon.FallbackSeed = weaponInfo.Seed;
|
||||
}
|
||||
|
||||
weapon.FallbackWear = weaponInfo.Wear;
|
||||
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);
|
||||
|
||||
@@ -172,10 +187,10 @@ namespace WeaponPaints
|
||||
// $"sticker slot {stickerSlot} schema", stickerSlot);
|
||||
// if (stickerSlot == 5)
|
||||
// {
|
||||
// // CAttributeListSetOrAddAttributeValueByName.Invoke(weapon.AttributeManager.Item.NetworkedDynamicAttributes.Handle,
|
||||
// // $"sticker slot {stickerSlot} offset x", 0.05f);
|
||||
// // CAttributeListSetOrAddAttributeValueByName.Invoke(weapon.AttributeManager.Item.NetworkedDynamicAttributes.Handle,
|
||||
// // $"sticker slot {stickerSlot} offset y", 0.02f);
|
||||
CAttributeListSetOrAddAttributeValueByName.Invoke(weapon.AttributeManager.Item.NetworkedDynamicAttributes.Handle,
|
||||
$"sticker slot {stickerSlot} offset x", sticker.OffsetX);
|
||||
CAttributeListSetOrAddAttributeValueByName.Invoke(weapon.AttributeManager.Item.NetworkedDynamicAttributes.Handle,
|
||||
$"sticker slot {stickerSlot} offset y", sticker.OffsetY);
|
||||
// }
|
||||
CAttributeListSetOrAddAttributeValueByName.Invoke(weapon.AttributeManager.Item.NetworkedDynamicAttributes.Handle,
|
||||
$"sticker slot {stickerSlot} wear", sticker.Wear);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
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();
|
||||
|
||||
@@ -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.0b";
|
||||
|
||||
public override void Load(bool hotReload)
|
||||
{
|
||||
|
||||
@@ -566,7 +566,6 @@ internal class WeaponSynchronization
|
||||
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 class WeaponSynchronization
|
||||
// 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 class WeaponSynchronization
|
||||
|
||||
// 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
|
||||
};
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
@@ -24,5 +24,7 @@
|
||||
"wp_skin_menu_skin_title": "Выберите скин для {lime}{0}{default}",
|
||||
"wp_skin_menu_select": "Вы выбрали {lime}{0}{default} в качестве вашего скина",
|
||||
|
||||
"wp_stattrak_action": "Вы успешно изменили настройки статтрак",
|
||||
|
||||
"None": "Нет"
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
@@ -24,5 +24,7 @@
|
||||
"wp_skin_menu_skin_title": "Виберіть шкіру для {lime}{0}{default}",
|
||||
"wp_skin_menu_select": "Ви обрали {lime}{0}{default} як свою шкіру",
|
||||
|
||||
"wp_stattrak_action": "Ви успішно змінили налаштування статтрака",
|
||||
|
||||
"None": "Немає"
|
||||
}
|
||||
@@ -24,5 +24,7 @@
|
||||
"wp_skin_menu_skin_title": "选择 {lime}{0}{default} 的皮肤",
|
||||
"wp_skin_menu_select": "您选择了 {lime}{0}{default} 作为您的皮肤",
|
||||
|
||||
"wp_stattrak_action": "您已成功更改 StatTrak 设置",
|
||||
|
||||
"None": "无"
|
||||
}
|
||||
Reference in New Issue
Block a user