Is there a better way to get the player's weapon without throwing projectiles?
The method currently in use
PHP Code:
int g_iGrenadeThrower[MAXPLAYERS + 1];
public void OnEntityCreated(int entity, const char[] classname)
{
if(classname[0] != 'm' && classname[0] != 'p' && classname[0] != 'v')
return;
if(strncmp(classname, "molotov_projectile", 19) == 0 || strncmp(classname, "pipe_bomb_projectile", 21) == 0 || strncmp(classname, "vomitjar_projectile", 20) == 0)
SDKHook(entity, SDKHook_SpawnPost, Hook_SpawnPost);
}
void Hook_SpawnPost(int entity)
{
SDKUnhook(entity, SDKHook_SpawnPost, Hook_SpawnPost);
if(entity <= MaxClients || !IsValidEntity(entity))
return;
int iOwner = GetEntPropEnt(entity, Prop_Data, "m_hOwnerEntity");
if(0 < iOwner <= MaxClients && IsClientInGame(iOwner) && GetClientTeam(iOwner) == 2)
{
int iSlot = GetPlayerWeaponSlot(iOwner, 2);
if(iSlot > MaxClients)
g_iGrenadeThrower[iOwner] = EntIndexToEntRef(iSlot);
}
}
char sWeapon [32];
int iSlot = GetPlayerWeaponSlot(client, 2);
if(iSlot > MaxClients)
{
if(EntIndexToEntRef(iSlot) != g_iGrenadeThrower[client])
{
GetEntityClassname(iSlot, sWeapon, sizeof(sWeapon));
}
}