Fix bots choosing empty weapon slots#2007
Conversation
Fix bots choosing empty weapon slots after they choose a different class, where they previously selected a weapon with a selection index that would be an empty weapon slot with their new class.
|
Addresses an issue where bots would attempt to pick a weapon, but the selected a slot that was invalid, so they end up falling back to the default MPN choice. This often leads to bots with higher ranks being forced to pick the rankless weapon default. The symptoms coincide with the following error logging: // in IServerNetworkable *CEntityFactoryDictionary::Create( const char *pClassName )
Warning("Attempted to create unknown entity type %s!\n", pClassName );
// where pClassName was "weapon_empty"
// in bool CNEO_Player::RequestSetLoadout(int loadoutNumber)
Warning("NULL Ent in RequestSetLoadout!\n");
// where loadoutNumber ended up being an index that was outside of the class's valid weapon slot range
// in bool CNEO_Player::RequestSetLoadout(int loadoutNumber)
DevMsg("Insufficient XP for %s\n", pszWepName);
// where for example pszWepName was "weapon_pz"To my understanding from looking at the debugger, it seems that bots don't update their requested loadout index before calling RequestSetLoadout, even if they had just changed their class in Spawn code. This can result in the existing loadout index ending up being past the valid index range for a present class and rank. My proposal is to improve the consistency of bots selecting a class and then loadout, by first making sure the class choice index is set early, and to then select another random loadout choice index immediately after, My thinking is that this will make sure that the loadout index is always in a valid range for the bot's selected class/rank. For my testing using the debug build for asserts, I ran a match with 31 bots with the following script: ... and let the game run in the background while waiting for any triggered asserts. I checked that after this change, the aforementioned asserts no longer happen, and that I don't see any Support bots getting stuck with the MPN at higher ranks. |
| void CNEOBot::ChooseRandomWeapon() | ||
| { | ||
| m_iLoadoutWepChoice = ChooseRandomWeaponIndex(); | ||
| } |
| m_iLoadoutWepChoice = iChosenWeps[RandomInt(0, iChosenWepsSize - 1)]; | ||
| } | ||
| } | ||
| ChooseRandomWeapon(); |
There was a problem hiding this comment.
Refactored this section below as ChooseRandomWeapon()



Description
Fix bots choosing empty weapon slots after they choose a different class, where they previously selected a weapon with a selection index that would be an invalid/empty weapon slot with their new class.
Toolchain