If I do not misunderstand he want to force weapon switch for the best available weapon, if that's the case my code does exactly what he want.
Ham_Weapon_RetireWeapon call GetNextBestWeapon.
https://github.com/s1lentq/ReGameDLL...pons.cpp#L1420
Spoiler
Code:
// RetireWeapon - no more ammo for this gun, put it away.
void CBasePlayerWeapon::RetireWeapon()
{
// first, no viewmodel at all.
m_pPlayer->pev->viewmodel = iStringNull;
m_pPlayer->pev->weaponmodel = iStringNull;
g_pGameRules->GetNextBestWeapon(m_pPlayer, this);
}
https://github.com/s1lentq/ReGameDLL...ules.cpp#L3159
Spoiler
Code:
BOOL EXT_FUNC CHalfLifeMultiplay::__API_HOOK(GetNextBestWeapon)(CBasePlayer *pPlayer, CBasePlayerItem *pCurrentWeapon)
{
CBasePlayerItem *pCheck;
CBasePlayerItem *pBest; // this will be used in the event that we don't find a weapon in the same category.
int iBestWeight;
int i;
if (!pCurrentWeapon->CanHolster())
{
// can't put this gun away right now, so can't switch.
return FALSE;
}
iBestWeight = -1; // no weapon lower than -1 can be autoswitched to
pBest = nullptr;
for (i = 0; i < MAX_ITEM_TYPES; i++)
{
pCheck = pPlayer->m_rgpPlayerItems[i];
while (pCheck)
{
// don't reselect the weapon we're trying to get rid of
if (pCheck->iWeight() > iBestWeight && pCheck != pCurrentWeapon)
{
//ALERT (at_console, "Considering %s\n", STRING(pCheck->pev->classname));
// we keep updating the 'best' weapon just in case we can't find a weapon of the same weight
// that the player was using. This will end up leaving the player with his heaviest-weighted weapon.
if (pCheck->CanDeploy())
{
// if this weapon is useable, flag it as the best
iBestWeight = pCheck->iWeight();
pBest = pCheck;
}
}
pCheck = pCheck->m_pNext;
}
}
// if we make it here, we've checked all the weapons and found no useable
// weapon in the same catagory as the current weapon.
// if pBest is null, we didn't find ANYTHING. Shouldn't be possible- should always
// at least get the crowbar, but ya never know.
if (!pBest)
{
return FALSE;
}
pPlayer->SwitchWeapon(pBest);
return TRUE;
}
__________________