Okay. Well here's the re-write. It's working well so far (no crashes), short of an occasional invalid edict error with GetEdictClassName. Could someone familiar with walking m_hMyWeapons take a look at this and make sure I'm doing it correctly? I wouldn't think I'd get edict errors if I were.
Code:
g_iMyWeapons = FindSendPropOffs("CBaseCombatCharacter", "m_hMyWeapons");
WeaponHandler(client, teamid)
{
if (isFighting)
{
static count = 0;
for (new i = 0; i <= 128; i += 4)
{
new weaponentity = -1;
new String:weaponname[32];
weaponentity = GetEntDataEnt(client, (g_iMyWeapons + i));
if (!IsValidEdict(weaponentity))
{
return;
}
GetEdictClassname(weaponentity, weaponname, sizeof(weaponname));
if (weaponentity != -1 && !StrEqual(weaponname, "worldspawn", false))
{
// if teamid = 0, we've picked up a weapon during a fight, strip and leave with knife.
if (teamid == 0 && !StrEqual(weaponname, "weapon_knife", false))
{
RemovePlayerItem(client, weaponentity);
RemoveEdict(weaponentity);
if (!countdown)
{
EquipKnife(client);
}
}
// Starting a knife fight, remove all weapons and store them for later incase we give them back.
else if (teamid == 3 || teamid == 2)
{
RemovePlayerItem(client, weaponentity);
RemoveEdict(weaponentity);
if (teamid == 3)
{
ctitems[count] = weaponname;
count++;
}
if (teamid == 2)
{
titems[count] = weaponname;
count++;
}
}
}
}
count = 0;
}
}
Thanks!