mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-17 18:39:07 +00:00
1.9c
- Some changes
This commit is contained in:
@@ -164,7 +164,6 @@ namespace WeaponPaints
|
||||
|
||||
g_playersKnife[player.Slot] = knifeKey;
|
||||
|
||||
|
||||
if (g_bCommandsAllowed && (LifeState_t)player.LifeState == LifeState_t.LIFE_ALIVE)
|
||||
RefreshWeapons(player);
|
||||
|
||||
@@ -225,7 +224,6 @@ namespace WeaponPaints
|
||||
{
|
||||
if (!Utility.IsPlayerValid(p)) return;
|
||||
|
||||
|
||||
string steamId = p.SteamID.ToString();
|
||||
var firstSkin = skinsList?.FirstOrDefault(skin =>
|
||||
{
|
||||
@@ -393,7 +391,6 @@ namespace WeaponPaints
|
||||
player!.Print(Localizer["wp_glove_menu_select", selectedPaintName]);
|
||||
}
|
||||
|
||||
|
||||
if (weaponSync != null)
|
||||
{
|
||||
Task.Run(async () =>
|
||||
@@ -408,7 +405,6 @@ namespace WeaponPaints
|
||||
gPlayerWeaponsInfo[playerInfo.Slot][weaponDefindex].Paint = paint;
|
||||
gPlayerWeaponsInfo[playerInfo.Slot][weaponDefindex].Wear = 0.00f;
|
||||
gPlayerWeaponsInfo[playerInfo.Slot][weaponDefindex].Seed = 0;
|
||||
|
||||
});
|
||||
}
|
||||
RefreshGloves(player);
|
||||
|
||||
69
Events.cs
69
Events.cs
@@ -26,22 +26,30 @@ namespace WeaponPaints
|
||||
|
||||
try
|
||||
{
|
||||
List<Task> tasks = new List<Task>();
|
||||
|
||||
if (Config.Additional.SkinEnabled)
|
||||
{
|
||||
Task.Run(() => weaponSync.GetWeaponPaintsFromDatabase(playerInfo));
|
||||
tasks.Add(Task.Run(() => weaponSync.GetWeaponPaintsFromDatabase(playerInfo)));
|
||||
}
|
||||
if (Config.Additional.KnifeEnabled)
|
||||
{
|
||||
Task.Run(() => weaponSync.GetKnifeFromDatabase(playerInfo));
|
||||
tasks.Add(Task.Run(() => weaponSync.GetKnifeFromDatabase(playerInfo)));
|
||||
}
|
||||
if (Config.Additional.GloveEnabled)
|
||||
{
|
||||
Task.Run(() => weaponSync.GetGloveFromDatabase(playerInfo));
|
||||
tasks.Add(Task.Run(() => weaponSync.GetGloveFromDatabase(playerInfo)));
|
||||
}
|
||||
|
||||
Task.WaitAll(tasks.ToArray());
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (AggregateException ex)
|
||||
{
|
||||
Console.WriteLine($"An error occurred: {ex.Message}");
|
||||
// Handle the exception
|
||||
foreach (var innerException in ex.InnerExceptions)
|
||||
{
|
||||
Console.WriteLine($"An error occurred for player {player}: {innerException.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
return HookResult.Continue;
|
||||
@@ -67,25 +75,30 @@ namespace WeaponPaints
|
||||
|
||||
if (weaponSync != null)
|
||||
{
|
||||
// Run weapon sync tasks asynchronously
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await weaponSync.SyncWeaponPaintsToDatabase(playerInfo);
|
||||
});
|
||||
try
|
||||
{
|
||||
await weaponSync.SyncWeaponPaintsToDatabase(playerInfo);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utility.Log($"Error syncing weapon paints: {ex.Message}");
|
||||
}
|
||||
|
||||
// Remove player data
|
||||
if (Config.Additional.SkinEnabled)
|
||||
{
|
||||
gPlayerWeaponsInfo.TryRemove(player.Slot, out _);
|
||||
}
|
||||
if (Config.Additional.KnifeEnabled)
|
||||
{
|
||||
g_playersKnife.TryRemove(player.Slot, out _);
|
||||
}
|
||||
if (Config.Additional.GloveEnabled)
|
||||
{
|
||||
g_playersGlove.TryRemove(player.Slot, out _);
|
||||
}
|
||||
if (Config.Additional.SkinEnabled)
|
||||
{
|
||||
gPlayerWeaponsInfo.TryRemove(player.Slot, out _);
|
||||
}
|
||||
if (Config.Additional.KnifeEnabled)
|
||||
{
|
||||
g_playersKnife.TryRemove(player.Slot, out _);
|
||||
}
|
||||
if (Config.Additional.GloveEnabled)
|
||||
{
|
||||
g_playersGlove.TryRemove(player.Slot, out _);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Remove player's command cooldown
|
||||
@@ -136,7 +149,7 @@ namespace WeaponPaints
|
||||
|
||||
CCSPlayerController? player = Utilities.GetEntityFromIndex<CCSPlayerPawn>((int)activator.Index).OriginalController.Value;
|
||||
|
||||
if (player == null || player.IsBot || player.IsHLTV ||
|
||||
if (player == null || player.IsBot || player.PlayerPawn == null || !player.PlayerPawn.IsValid || !player.PawnIsAlive ||
|
||||
player.SteamID.ToString().Length != 17 || !g_knifePickupCount.TryGetValue(player.Slot, out var pickupCount) ||
|
||||
!g_playersKnife.ContainsKey(player.Slot))
|
||||
{
|
||||
@@ -190,6 +203,11 @@ namespace WeaponPaints
|
||||
if (player is null || !player.IsValid || !Config.Additional.KnifeEnabled && !Config.Additional.GloveEnabled)
|
||||
return HookResult.Continue;
|
||||
|
||||
CCSPlayerPawn? pawn = player.PlayerPawn.Value;
|
||||
|
||||
if (pawn == null || !pawn.IsValid)
|
||||
return HookResult.Continue;
|
||||
|
||||
g_knifePickupCount[player.Slot] = 0;
|
||||
|
||||
if (!PlayerHasKnife(player))
|
||||
@@ -220,12 +238,13 @@ namespace WeaponPaints
|
||||
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
private void OnTick()
|
||||
{
|
||||
foreach (var player in Utilities.GetPlayers().Where(p =>
|
||||
p is not null && p.IsValid &&
|
||||
p is not null && p.IsValid && p.PlayerPawn != null && p.PlayerPawn.IsValid &&
|
||||
(LifeState_t)p.LifeState == LifeState_t.LIFE_ALIVE && p.SteamID.ToString().Length == 17
|
||||
&& !p.IsBot && !p.IsHLTV && p.Connected == PlayerConnectedState.PlayerConnected && p.Team != CounterStrikeSharp.API.Modules.Utils.CsTeam.None
|
||||
&& !p.IsBot && !p.IsHLTV && p.Connected == PlayerConnectedState.PlayerConnected
|
||||
)
|
||||
)
|
||||
{
|
||||
@@ -297,7 +316,7 @@ namespace WeaponPaints
|
||||
//RegisterListener<Listeners.OnClientPutInServer>(OnClientPutInServer);
|
||||
//RegisterListener<Listeners.OnClientDisconnect>(OnClientDisconnect);
|
||||
RegisterListener<Listeners.OnMapStart>(OnMapStart);
|
||||
RegisterListener<Listeners.OnTick>(OnTick);
|
||||
//RegisterListener<Listeners.OnTick>(OnTick);
|
||||
|
||||
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
|
||||
RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre);
|
||||
|
||||
@@ -142,8 +142,10 @@ namespace WeaponPaints
|
||||
{
|
||||
if (!_config.Additional.KnifeEnabled || player == null || !player.IsValid) return;
|
||||
|
||||
WeaponPaints.Instance.AddTimer(1.0f, () =>
|
||||
Instance.AddTimer(1.0f, () =>
|
||||
{
|
||||
if (PlayerHasKnife(player)) return;
|
||||
|
||||
string knifeToGive;
|
||||
if (g_playersKnife.TryGetValue(player.Slot, out var knife))
|
||||
{
|
||||
@@ -181,7 +183,7 @@ namespace WeaponPaints
|
||||
return false;
|
||||
}
|
||||
|
||||
if (player.PlayerPawn?.Value == null || player.PlayerPawn?.Value.WeaponServices == null || player.PlayerPawn?.Value.ItemServices == null)
|
||||
if (player.PlayerPawn.Value == null || player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null)
|
||||
return false;
|
||||
|
||||
var weapons = player.PlayerPawn.Value.WeaponServices?.MyWeapons;
|
||||
@@ -256,8 +258,6 @@ namespace WeaponPaints
|
||||
|
||||
weaponsWithAmmo[weaponByDefindex].Add((clip1, reservedAmmo));
|
||||
}
|
||||
|
||||
//player.RemoveItemByDesignerName(weapon.Value.DesignerName, false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -271,18 +271,21 @@ namespace WeaponPaints
|
||||
player.ExecuteClientCommand($"slot {i}");
|
||||
player.ExecuteClientCommand($"slot {i}");
|
||||
|
||||
AddTimer(0.1f, () =>
|
||||
AddTimer(0.2f, () =>
|
||||
{
|
||||
var weapon = player.PlayerPawn.Value.WeaponServices.ActiveWeapon.Value;
|
||||
CCSWeaponBaseGun? gun = weapon?.As<CCSWeaponBaseGun>();
|
||||
|
||||
if (weapon is null || !weapon.IsValid) return;
|
||||
|
||||
CCSWeaponBaseGun gun = weapon.As<CCSWeaponBaseGun>();
|
||||
|
||||
if (gun == null || gun.VData == null) return;
|
||||
|
||||
if (gun?.VData?.GearSlot == gear_slot_t.GEAR_SLOT_C4 || gun?.VData?.GearSlot == gear_slot_t.GEAR_SLOT_GRENADES) return;
|
||||
if (gun.VData.GearSlot == gear_slot_t.GEAR_SLOT_C4 || gun.VData.GearSlot == gear_slot_t.GEAR_SLOT_GRENADES) return;
|
||||
|
||||
player.DropActiveWeapon();
|
||||
|
||||
AddTimer(0.22f, () =>
|
||||
AddTimer(0.25f, () =>
|
||||
{
|
||||
if (gun != null && gun.IsValid && gun.State == CSWeaponState_t.WEAPON_NOT_CARRIED)
|
||||
{
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace WeaponPaints;
|
||||
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
{
|
||||
internal static WeaponPaints Instance { get; private set; } = new();
|
||||
|
||||
internal static readonly Dictionary<string, string> weaponList = new()
|
||||
{
|
||||
{"weapon_deagle", "Desert Eagle"},
|
||||
@@ -155,7 +156,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
||||
public override string ModuleAuthor => "Nereziel & daffyy";
|
||||
public override string ModuleDescription => "Skin, gloves and knife selector, standalone and web-based";
|
||||
public override string ModuleName => "WeaponPaints";
|
||||
public override string ModuleVersion => "1.9b";
|
||||
public override string ModuleVersion => "1.9c";
|
||||
|
||||
public static WeaponPaintsConfig GetWeaponPaintsConfig()
|
||||
{
|
||||
|
||||
@@ -14,11 +14,13 @@ namespace WeaponPaints
|
||||
_config = config;
|
||||
}
|
||||
|
||||
internal async Task GetKnifeFromDatabase(PlayerInfo player)
|
||||
public async Task GetKnifeFromDatabase(PlayerInfo player)
|
||||
{
|
||||
if (!_config.Additional.KnifeEnabled) return;
|
||||
try
|
||||
{
|
||||
if (!_config.Additional.KnifeEnabled || string.IsNullOrEmpty(player?.SteamId))
|
||||
return;
|
||||
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
string query = "SELECT `knife` FROM `wp_player_knife` WHERE `steamid` = @steamid";
|
||||
string? playerKnife = await connection.QueryFirstOrDefaultAsync<string>(query, new { steamid = player.SteamId });
|
||||
@@ -28,53 +30,47 @@ namespace WeaponPaints
|
||||
WeaponPaints.g_playersKnife[player.Slot] = playerKnife;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utility.Log(e.Message);
|
||||
return;
|
||||
Utility.Log($"An error occurred in GetKnifeFromDatabase: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task GetGloveFromDatabase(PlayerInfo player)
|
||||
public async Task GetGloveFromDatabase(PlayerInfo player)
|
||||
{
|
||||
if (!_config.Additional.GloveEnabled) return;
|
||||
|
||||
try
|
||||
{
|
||||
// Ensure proper disposal of resources using "using" statement
|
||||
if (!_config.Additional.GloveEnabled || string.IsNullOrEmpty(player?.SteamId))
|
||||
return;
|
||||
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
|
||||
// Construct the SQL query with specific columns for better performance
|
||||
string query = "SELECT `weapon_defindex` FROM `wp_player_gloves` WHERE `steamid` = @steamid";
|
||||
|
||||
// Execute the query and retrieve glove data
|
||||
ushort? gloveData = await connection.QueryFirstOrDefaultAsync<ushort?>(query, new { steamid = player.SteamId });
|
||||
|
||||
// Check if glove data is retrieved successfully
|
||||
if (gloveData != null)
|
||||
{
|
||||
// Update g_playersGlove dictionary with glove data
|
||||
WeaponPaints.g_playersGlove[player.Slot] = gloveData.Value;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Log any exceptions occurred during database operation
|
||||
Utility.Log("An error occurred while fetching glove data: " + e.Message);
|
||||
Utility.Log($"An error occurred in GetGloveFromDatabase: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task GetWeaponPaintsFromDatabase(PlayerInfo player)
|
||||
public async Task GetWeaponPaintsFromDatabase(PlayerInfo player)
|
||||
{
|
||||
if (!_config.Additional.SkinEnabled || player == null || player.SteamId == null) return;
|
||||
|
||||
try
|
||||
{
|
||||
if (!_config.Additional.SkinEnabled || player == null || string.IsNullOrEmpty(player.SteamId))
|
||||
return;
|
||||
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
string query = "SELECT * FROM `wp_player_skins` WHERE `steamid` = @steamid";
|
||||
var playerSkins = await connection.QueryAsync<dynamic>(query, new { steamid = player.SteamId });
|
||||
|
||||
if (playerSkins == null) return;
|
||||
if (playerSkins == null)
|
||||
return;
|
||||
|
||||
var weaponInfos = new ConcurrentDictionary<int, WeaponInfo>();
|
||||
|
||||
@@ -97,9 +93,9 @@ namespace WeaponPaints
|
||||
|
||||
WeaponPaints.gPlayerWeaponsInfo[player.Slot] = weaponInfos;
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utility.Log($"Database error occurred: {e.Message}");
|
||||
Utility.Log($"An error occurred in GetWeaponPaintsFromDatabase: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +115,6 @@ namespace WeaponPaints
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal async Task SyncGloveToDatabase(PlayerInfo player, int defindex)
|
||||
{
|
||||
if (!_config.Additional.GloveEnabled || player == null || string.IsNullOrEmpty(player.SteamId)) return;
|
||||
@@ -167,6 +162,5 @@ namespace WeaponPaints
|
||||
Utility.Log($"Error syncing weapon paints to database: {e.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -14,4 +14,4 @@
|
||||
"wp_skin_menu_weapon_title": "Ieroču Izvēlne",
|
||||
"wp_skin_menu_skin_title": "Izvēlieties ādu {lime}{0}{default}",
|
||||
"wp_skin_menu_select": "Jūs esat izvēlējies {lime}{0}{default} kā savu ādu"
|
||||
}
|
||||
}
|
||||
@@ -14,4 +14,4 @@
|
||||
"wp_skin_menu_weapon_title": "Menu Broni",
|
||||
"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ę"
|
||||
}
|
||||
}
|
||||
@@ -14,4 +14,4 @@
|
||||
"wp_skin_menu_weapon_title": "Menu de Armas",
|
||||
"wp_skin_menu_skin_title": "Selecione uma skin para {lime}{0}{default}",
|
||||
"wp_skin_menu_select": "Você escolheu {lime}{0}{default} como sua skin"
|
||||
}
|
||||
}
|
||||
@@ -14,4 +14,4 @@
|
||||
"wp_skin_menu_weapon_title": "Menu de Armas",
|
||||
"wp_skin_menu_skin_title": "Selecione uma skin para {lime}{0}{default}",
|
||||
"wp_skin_menu_select": "Você escolheu {lime}{0}{default} como sua skin"
|
||||
}
|
||||
}
|
||||
@@ -14,4 +14,4 @@
|
||||
"wp_skin_menu_weapon_title": "Silah Menüsü",
|
||||
"wp_skin_menu_skin_title": "{lime}{0}{default} için bir skin seçin",
|
||||
"wp_skin_menu_select": "{lime}{0}{default} olarak bir skin seçtiniz"
|
||||
}
|
||||
}
|
||||
@@ -14,4 +14,4 @@
|
||||
"wp_skin_menu_weapon_title": "武器菜单",
|
||||
"wp_skin_menu_skin_title": "为 {lime}{0}{default} 选择皮肤",
|
||||
"wp_skin_menu_select": "您已选择 {lime}{0}{default} 作为您的皮肤"
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user