diff --git a/Events.cs b/Events.cs index 237eb30a..59cf66df 100644 --- a/Events.cs +++ b/Events.cs @@ -102,9 +102,7 @@ public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo private void GivePlayerWeaponSkin(CCSPlayerController player, CBasePlayerWeapon weapon) { if (!Config.Additional.SkinEnabled) return; - if (player is null || weapon is null || !weapon.IsValid || !Utility.IsPlayerValid(player)) return; - if (!gPlayerWeaponsInfo.ContainsKey(player.Slot)) return; bool isKnife = weapon.DesignerName.Contains("knife") || weapon.DesignerName.Contains("bayonet"); @@ -257,7 +255,7 @@ public HookResult OnGiveNamedItemPost(DynamicHook hook) } */ - public void OnEntitySpawned(CEntityInstance entity) + public void OnEntityCreated(CEntityInstance entity) { var designerName = entity.DesignerName; @@ -268,8 +266,8 @@ public void OnEntitySpawned(CEntityInstance entity) var weapon = new CBasePlayerWeapon(entity.Handle); if (weapon == null || !weapon.IsValid || weapon.OwnerEntity.Value == null) return; - CCSPlayerController? player = Utilities.GetPlayerFromIndex((int)weapon.OwnerEntity.Value.Index); - if (player == null || !player.IsValid || !Utility.IsPlayerValid(player)) return; + CCSPlayerController? player = Utilities.GetPlayerFromSteamId(weapon.OriginalOwnerXuidLow); + if (player is null || !player.IsValid || !Utility.IsPlayerValid(player)) return; GivePlayerWeaponSkin(player, weapon); }); @@ -299,7 +297,7 @@ private void RegisterListeners() RegisterEventHandler(OnPlayerSpawn); RegisterEventHandler(OnRoundStart, HookMode.Pre); RegisterEventHandler(OnRoundEnd); - RegisterListener(OnEntitySpawned); + RegisterListener(OnEntityCreated); RegisterListener(OnTick); //VirtualFunctions.GiveNamedItemFunc.Hook(OnGiveNamedItemPost, HookMode.Post); } diff --git a/Utility.cs b/Utility.cs index e3564a41..f700c2a9 100644 --- a/Utility.cs +++ b/Utility.cs @@ -89,10 +89,9 @@ internal static async Task CheckDatabaseTables() internal static bool IsPlayerValid(CCSPlayerController? player) { - if (player is null) return false; + if (player is null || WeaponPaints.weaponSync is null) return false; - return (player is not null && player.IsValid && !player.IsBot && !player.IsHLTV && player.UserId.HasValue - && WeaponPaints.weaponSync != null && player.Connected == PlayerConnectedState.PlayerConnected && player.SteamID.ToString().Length == 17); + return (player.IsValid && !player.IsBot && !player.IsHLTV && player.UserId.HasValue); } internal static void LoadSkinsFromFile(string filePath) diff --git a/VERSION b/VERSION index 535769df..572c7afb 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.2c \ No newline at end of file +2.2d \ No newline at end of file diff --git a/WeaponPaints.cs b/WeaponPaints.cs index 8020df1f..62d62187 100644 --- a/WeaponPaints.cs +++ b/WeaponPaints.cs @@ -158,7 +158,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.2c"; + public override string ModuleVersion => "2.2d"; public static WeaponPaintsConfig GetWeaponPaintsConfig() { @@ -175,13 +175,15 @@ public override void Load(bool hotReload) foreach (var player in Utilities.GetPlayers()) { - if (weaponSync == null || player is null || !player.IsValid || player.SteamID.ToString().Length != 17 || !player.PawnIsAlive || player.IsBot || + if (weaponSync == null || player is null || !player.IsValid || player.SteamID.ToString().Length != 17 || player.IsBot || player.IsHLTV || player.Connected != PlayerConnectedState.PlayerConnected) continue; g_knifePickupCount[player.Slot] = 0; gPlayerWeaponsInfo.TryRemove(player.Slot, out _); g_playersKnife.TryRemove(player.Slot, out _); + g_playersGlove.TryRemove(player.Slot, out _); + g_playersAgent.TryRemove(player.Slot, out _); PlayerInfo playerInfo = new PlayerInfo { diff --git a/WeaponSynchronization.cs b/WeaponSynchronization.cs index 057dd2a2..f7a2b718 100644 --- a/WeaponSynchronization.cs +++ b/WeaponSynchronization.cs @@ -96,14 +96,17 @@ public async Task GetWeaponPaintsFromDatabase(PlayerInfo player) if (!_config.Additional.SkinEnabled || player == null || string.IsNullOrEmpty(player.SteamId)) return; + var weaponInfos = new ConcurrentDictionary(); + await using var connection = await _database.GetConnectionAsync(); string query = "SELECT * FROM `wp_player_skins` WHERE `steamid` = @steamid"; var playerSkins = await connection.QueryAsync(query, new { steamid = player.SteamId }); if (playerSkins == null) + { + WeaponPaints.gPlayerWeaponsInfo[player.Slot] = weaponInfos; return; - - var weaponInfos = new ConcurrentDictionary(); + } foreach (var row in playerSkins) {