mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-18 02:41:54 +00:00
Some fixes
This commit is contained in:
37
Commands.cs
37
Commands.cs
@@ -16,7 +16,7 @@ namespace WeaponPaints
|
||||
});
|
||||
AddCommand($"css_{Config.Additional.CommandRefresh}", "Skins refresh", (player, info) =>
|
||||
{
|
||||
if (!Utility.IsPlayerValid(player)) return;
|
||||
if (!Utility.IsPlayerValid(player) || !g_bCommandsAllowed) return;
|
||||
OnCommandRefresh(player, info);
|
||||
});
|
||||
if (Config.Additional.CommandKillEnabled)
|
||||
@@ -31,7 +31,7 @@ namespace WeaponPaints
|
||||
}
|
||||
private void SetupKnifeMenu()
|
||||
{
|
||||
if (!Config.Additional.KnifeEnabled) return;
|
||||
if (!Config.Additional.KnifeEnabled || !g_bCommandsAllowed) return;
|
||||
|
||||
var knivesOnly = weaponList
|
||||
.Where(pair => pair.Key.StartsWith("weapon_knife") || pair.Key.StartsWith("weapon_bayonet"))
|
||||
@@ -62,13 +62,11 @@ namespace WeaponPaints
|
||||
|
||||
g_playersKnife[(int)player!.EntityIndex!.Value.Value] = knifeKey;
|
||||
|
||||
if (player!.PawnIsAlive)
|
||||
if (player!.PawnIsAlive && g_bCommandsAllowed)
|
||||
{
|
||||
g_changedKnife.Add((int)player.EntityIndex!.Value.Value);
|
||||
if (PlayerHasKnife(player))
|
||||
{
|
||||
RefreshPlayerKnife(player);
|
||||
}
|
||||
RefreshWeapons(player);
|
||||
//RefreshPlayerKnife(player);
|
||||
|
||||
/*
|
||||
AddTimer(1.0f, () => GiveKnifeToPlayer(player));
|
||||
@@ -85,7 +83,7 @@ namespace WeaponPaints
|
||||
}
|
||||
AddCommand($"css_{Config.Additional.CommandKnife}", "Knife Menu", (player, info) =>
|
||||
{
|
||||
if (!Utility.IsPlayerValid(player)) return;
|
||||
if (!Utility.IsPlayerValid(player) || !g_bCommandsAllowed) return;
|
||||
int playerIndex = (int)player!.EntityIndex!.Value.Value;
|
||||
|
||||
if (commandCooldown != null && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds) && playerIndex > 0 && playerIndex < commandCooldown.Length)
|
||||
@@ -128,9 +126,11 @@ namespace WeaponPaints
|
||||
// Function to handle skin selection for the chosen weapon
|
||||
var handleSkinSelection = (CCSPlayerController? p, ChatMenuOption opt) =>
|
||||
{
|
||||
if (p == null || !p.IsValid) return;
|
||||
if (p == null || !p.IsValid || !p.EntityIndex.HasValue) return;
|
||||
|
||||
var steamId = new SteamID(player.SteamID);
|
||||
playerIndex = (int)p.EntityIndex.Value.Value;
|
||||
|
||||
var steamId = new SteamID(p.SteamID);
|
||||
var firstSkin = skinsList?.FirstOrDefault(skin =>
|
||||
{
|
||||
if (skin != null && skin.TryGetValue("weapon_name", out var weaponName))
|
||||
@@ -151,22 +151,23 @@ namespace WeaponPaints
|
||||
string temp = $" {Config.Prefix} {Config.Messages.ChosenSkinMenu}".Replace("{SKIN}", selectedSkin);
|
||||
p.PrintToChat(Utility.ReplaceTags(temp));
|
||||
|
||||
/*
|
||||
if (!gPlayerWeaponsInfo[playerIndex].ContainsKey(weaponDefIndex))
|
||||
if (!gPlayerWeaponsInfo[playerIndex].ContainsKey(weaponDefIndex))
|
||||
{
|
||||
gPlayerWeaponsInfo[playerIndex][weaponDefIndex] = new WeaponInfo();
|
||||
}
|
||||
*/
|
||||
|
||||
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Paint = paintID;
|
||||
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Wear = 0.0f;
|
||||
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Seed = 0;
|
||||
|
||||
if (weaponSync == null) return;
|
||||
Task.Run(async () =>
|
||||
if (!Config.GlobalShare)
|
||||
{
|
||||
await weaponSync.SyncWeaponPaintsToDatabase(player);
|
||||
});
|
||||
if (weaponSync == null) return;
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await weaponSync.SyncWeaponPaintsToDatabase(p);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -222,7 +223,7 @@ namespace WeaponPaints
|
||||
|
||||
private void OnCommandRefresh(CCSPlayerController? player, CommandInfo command)
|
||||
{
|
||||
if (!Config.Additional.CommandWpEnabled || !Config.Additional.SkinEnabled) return;
|
||||
if (!Config.Additional.CommandWpEnabled || !Config.Additional.SkinEnabled || !g_bCommandsAllowed) return;
|
||||
if (!Utility.IsPlayerValid(player)) return;
|
||||
string temp = "";
|
||||
if (!player!.EntityIndex.HasValue) return;
|
||||
|
||||
11
Events.cs
11
Events.cs
@@ -15,6 +15,7 @@ namespace WeaponPaints
|
||||
//RegisterEventHandler<EventPlayerConnectFull>(OnPlayerConnectFull);
|
||||
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
|
||||
RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre);
|
||||
RegisterEventHandler<EventRoundEnd>(OnRoundEnd);
|
||||
RegisterEventHandler<EventItemPurchase>(OnEventItemPurchasePost);
|
||||
RegisterEventHandler<EventItemPickup>(OnItemPickup);
|
||||
}
|
||||
@@ -66,7 +67,6 @@ namespace WeaponPaints
|
||||
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
||||
_ = weaponSync.GetKnifeFromDatabase(playerIndex);
|
||||
|
||||
|
||||
/*
|
||||
Task.Run(async () =>
|
||||
{
|
||||
@@ -118,8 +118,17 @@ namespace WeaponPaints
|
||||
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
|
||||
NativeAPI.IssueServerCommand("mp_equipment_reset_rounds 0");
|
||||
|
||||
g_bCommandsAllowed = true;
|
||||
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)
|
||||
{
|
||||
g_bCommandsAllowed = false;
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
private HookResult OnItemPickup(EventItemPickup @event, GameEventInfo info)
|
||||
{
|
||||
if (@event.Defindex == 42 || @event.Defindex == 59)
|
||||
|
||||
@@ -196,7 +196,7 @@ namespace WeaponPaints
|
||||
var weapons = player.PlayerPawn.Value.WeaponServices.MyWeapons;
|
||||
if (weapons != null && weapons.Count > 0)
|
||||
{
|
||||
CCSPlayer_ItemServices service = new CCSPlayer_ItemServices(player.PlayerPawn.Value.ItemServices.Handle);
|
||||
CCSPlayer_ItemServices service = new(player.PlayerPawn.Value.ItemServices.Handle);
|
||||
//var dropWeapon = VirtualFunction.CreateVoid<nint, nint>(service.Handle, GameData.GetOffset("CCSPlayer_ItemServices_DropActivePlayerWeapon"));
|
||||
|
||||
foreach (var weapon in weapons)
|
||||
@@ -205,31 +205,38 @@ namespace WeaponPaints
|
||||
{
|
||||
if (!weapon.Value.EntityIndex.HasValue || !weapon.Value.DesignerName.Contains("weapon_")) continue;
|
||||
//if (weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 42 || weapon.Value.AttributeManager.Item.ItemDefinitionIndex == 59)
|
||||
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
|
||||
try
|
||||
{
|
||||
weapon.Value.Remove();
|
||||
GiveKnifeToPlayer(player);
|
||||
}
|
||||
else
|
||||
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
|
||||
{
|
||||
weapon.Value.Remove();
|
||||
GiveKnifeToPlayer(player);
|
||||
}
|
||||
else
|
||||
{
|
||||
int clip1, reservedAmmo;
|
||||
|
||||
clip1 = weapon.Value.Clip1;
|
||||
reservedAmmo = weapon.Value.ReserveAmmo[0];
|
||||
|
||||
weapon.Value.Remove();
|
||||
CBasePlayerWeapon newWeapon = new(player.GiveNamedItem(weapon.Value.DesignerName));
|
||||
|
||||
Server.NextFrame(() =>
|
||||
{
|
||||
newWeapon.Clip1 = clip1;
|
||||
newWeapon.ReserveAmmo[0] = reservedAmmo;
|
||||
});
|
||||
}
|
||||
} catch(Exception ex)
|
||||
{
|
||||
int clip1, reservedAmmo;
|
||||
|
||||
clip1 = weapon.Value.Clip1;
|
||||
reservedAmmo = weapon.Value.ReserveAmmo[0];
|
||||
|
||||
weapon.Value.Remove();
|
||||
CBasePlayerWeapon newWeapon = new CBasePlayerWeapon(player.GiveNamedItem(weapon.Value.DesignerName));
|
||||
|
||||
Server.NextFrame(() =>
|
||||
{
|
||||
newWeapon.Clip1 = clip1;
|
||||
newWeapon.ReserveAmmo[0] = reservedAmmo;
|
||||
});
|
||||
|
||||
Console.WriteLine("[WeaponPaints] Refreshing weapons exception");
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
RefreshSkins(player);
|
||||
if (Config.Additional.SkinVisibilityFix)
|
||||
RefreshSkins(player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,7 +280,7 @@ namespace WeaponPaints
|
||||
if (WeaponPaints.skinsList != null)
|
||||
{
|
||||
// Filter weapons by the provided defindex
|
||||
var filteredWeapons = WeaponPaints.skinsList.FindAll(w => w["weapon_defindex"]?.ToString() == defindex.ToString());
|
||||
var filteredWeapons = skinsList.FindAll(w => w["weapon_defindex"]?.ToString() == defindex.ToString());
|
||||
|
||||
if (filteredWeapons.Count > 0)
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ using CounterStrikeSharp.API.Modules.Cvars;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace WeaponPaints;
|
||||
[MinimumApiVersion(71)]
|
||||
[MinimumApiVersion(82)]
|
||||
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
{
|
||||
public override string ModuleName => "WeaponPaints";
|
||||
@@ -32,6 +32,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
||||
internal static Dictionary<int, int> g_knifePickupCount = new Dictionary<int, int>();
|
||||
internal static Dictionary<int, string> g_playersKnife = new();
|
||||
internal static List<int> g_changedKnife = new();
|
||||
internal bool g_bCommandsAllowed = true;
|
||||
|
||||
internal static List<JObject> skinsList = new List<JObject>();
|
||||
internal static readonly Dictionary<string, string> weaponList = new()
|
||||
|
||||
Reference in New Issue
Block a user