So as a part of a plugin I have some code that gives you infinite HE grenades or infinite decoy grenades for 1 round. The nade is the only 'weapon' you have to use for the entire round (you can't pick up other guns or use knife).
The way i've done it is a nade is given to you 1.75 seconds after you throw one (you are initially spawned with 1 grenade). However, the issue is that sometimes (i'm not sure what causes it), a player will no longer be able to throw their nade, the nade will appear on their hud and when they try to drop it they get the 'You cant drop your HE grenade' message but their viewmodel of them holding the grenade is not there and they cannot throw the grenade. This ruins the gamemode obviously for the rest of the round for this person.
Any idea what might be causing this?
Code is below.
Thanks in advance
Code:
//The following line is in OnPluginStart()
HookEvent("weapon_fire", Event_GrenadeThrow);
/*
* Give client a grenade after they throw it, used in some events
*/
public Action:Event_GrenadeThrow(Handle:event, const String:name[], bool:dontBroadcast)
{
if (!isEnabled)
return Plugin_Continue;
//Return if not grenade round
if (eventDay != EVENT_HEONLY && eventDay != EVENT_1HPDECOY)
return Plugin_Continue;
new String:weapon[32];
GetEventString(event, "weapon", weapon, sizeof(weapon));
if(StrEqual(weapon, "hegrenade", false) || StrEqual(weapon, "decoy", false))
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
CreateTimer(1.75, Timer_GiveGrenade, client);
return Plugin_Handled;
}
return Plugin_Handled;
}
/*
* Timer - Give client a grenade based on event day
*/
public Action:Timer_GiveGrenade(Handle:timer, any:client)
{
if (eventDay == EVENT_HEONLY)
GivePlayerItem(client, "weapon_hegrenade");
else if (eventDay == EVENT_1HPDECOY)
GivePlayerItem(client, "weapon_decoy");
}