Skip to content

Fix bots choosing empty weapon slots#2007

Open
sunzenshen wants to merge 1 commit into
NeotokyoRebuild:masterfrom
sunzenshen:bot-prevent-selecting-empty-weapon-slots
Open

Fix bots choosing empty weapon slots#2007
sunzenshen wants to merge 1 commit into
NeotokyoRebuild:masterfrom
sunzenshen:bot-prevent-selecting-empty-weapon-slots

Conversation

@sunzenshen

@sunzenshen sunzenshen commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

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

  • Windows MSVC VS2022

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.
@sunzenshen sunzenshen added the Bots Related to bot players label Jul 4, 2026
@sunzenshen

sunzenshen commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

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:

sv_neo_preround_freeze_time 2;
mp_chattime 2; 
host_timescale 3;

... 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.

@sunzenshen sunzenshen requested review from a team and nullsystem July 4, 2026 06:15
@sunzenshen

sunzenshen commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

Example of the error logs:

Screenshot 2026-07-04 003624 Screenshot 2026-07-04 003559

void CNEOBot::ChooseRandomWeapon()
{
m_iLoadoutWepChoice = ChooseRandomWeaponIndex();
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to make this block as similar as possible with what was originally in void CNEOBot::Spawn() , but doesn't quite show up easily in the GitHub diff.

Image

m_iLoadoutWepChoice = iChosenWeps[RandomInt(0, iChosenWepsSize - 1)];
}
}
ChooseRandomWeapon();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored this section below as ChooseRandomWeapon()

@nullsystem nullsystem requested a review from a team July 4, 2026 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bots Related to bot players

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants