if somebody give weapon which client already can pick up and equip it:
new zweapon = GivePlayerItem(client, "weapon_glock");
if(zweapon != -1 ) EquipPlayerWeapon(i, zweapon);
you will need to clear duplication in this table
Code:
g_iMyWeapons = FindSendPropInfo("CBaseCombatCharacter", "m_hMyWeapons");
for (new i = 0; i <= 128; i += 4)
{
new weaponentity = -1;
new String:weaponname[32];
weaponentity = GetEntDataEnt2(client, (g_iMyWeapons + i));
if ( IsValidEdict(weaponentity) )
{
GetEdictClassname(weaponentity, weaponname, sizeof(weaponname));
PrintToChatAll("[%d][%d][%s]", i, weaponentity, weaponname);
}
}
So maybe i found a solution for this problem
https://forums.alliedmods.net/showthread.php?t=281687
When :
Code:
if(knife != -1)
{
PrintToServer("EquipPlayerWeapon(%N, %i)", client, knife);
EquipPlayerWeapon(client, knife);
}
he make duplication in table m_hMyWeapons
This duplication can make server freeze until you restart server manualy
Here is my solution, may not work with grenades:
Code:
int zweapon = GivePlayerItem(client, "weapon_glock");
if(zweapon != -1) EquipPlayerWeapon2(client, zweapon);
bool EquipPlayerWeapon2(int client, int weapon)
{
for (int i = 0; i <= 128; i += 4)
{
int weaponentity = -1;
weaponentity = GetEntDataEnt2(client, (g_iMyWeapons + i));
if (weaponentity == weapon)
{
return false;
}
}
for (int i = 0; i <= 128; i += 4)
{
int weaponentity = -1;
weaponentity = GetEntDataEnt2(client, (g_iMyWeapons + i));
if (!IsValidEdict(weaponentity))
{
SetEntDataEnt2(client, (g_iMyWeapons + i), weapon);
return true;
}
}
return false;
}