fix: safe weapon kill (hope no more crash)

This commit is contained in:
StefanX
2026-01-24 04:02:16 +02:00
parent 129b34f5c0
commit 1f03e1c4f0

View File

@@ -332,13 +332,27 @@ namespace WeaponPaints
if (!PlayerHasKnife(player) && hasKnife)
{
var newKnife = new CBasePlayerWeapon(player.GiveNamedItem(CsItem.Knife));
newKnife.AddEntityIOEvent("Kill", newKnife, null, "", 0.01f);
var newWeapon = new CBasePlayerWeapon(player.GiveNamedItem(CsItem.USP));
player.GiveNamedItem(CsItem.Knife);
player.ExecuteClientCommand("slot3");
newWeapon.AddEntityIOEvent("Kill", newWeapon, null, "", 0.01f);
Server.NextFrame(() =>
{
try
{
if (newKnife != null && newKnife.IsValid)
newKnife.AddEntityIOEvent("Kill", newKnife, null, "", 0.01f);
if (newWeapon != null && newWeapon.IsValid)
newWeapon.AddEntityIOEvent("Kill", newWeapon, null, "", 0.01f);
}
catch (Exception ex)
{
Logger.LogWarning("Error AddEntityIOEvent " + ex.Message);
}
});
}
foreach (var entry in weaponsWithAmmo)
{
foreach (var ammo in entry.Value)