I'm having an issue with the OnWeaponUse event which I'm trying to use to prevent weapons from being picked up but also not removing the player's current weapon which happens if I don't add the GivePlayerItem at the end and also removing the weapon that gets dropped. The issue is that whenever I try and pick up a weapon, a few seconds after the client/server crashes. I'm not sure what I'm doing wrong.
Code:
public Action OnWeaponCanUse(int client, int weapon)
{
// Exit if a fun round is not in progress
if (!g_startedFunRound) return Plugin_Continue;
// Run some other checks
if (!IsClientInGame(client)) return Plugin_Continue;
if (!IsPlayerAlive(client)) return Plugin_Stop;
// Prevent the weapon from being picked up
if (IsValidEntity(weapon))
{
AcceptEntityInput(weapon, "Kill");
}
if (!StrEqual(g_curRoundWeapon, "weapon_knife"))
{
GivePlayerItem(client, g_curRoundWeapon);
}
return Plugin_Handled;
}