-
Notifications
You must be signed in to change notification settings - Fork 20
More bot names #1285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More bot names #1285
Conversation
| continue; | ||
| } | ||
|
|
||
| for (int k = availableList.Count() - 1; k >= 0; --k) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be an optimization nit, but it might be cleaner to use a hashmap to check if a name was used, instead of using a double nest of for loops.
Something like:
CUtlStringMap<bool> usedNames;
for (int j = 1; j <= gpGlobals->maxClients; ++j) {
auto player = UTIL_PlayerByIndex(j);
if (player) {
usedNames.Insert(player->GetPlayerName(), true);
}
}|
|
||
| for (int k = availableList.Count() - 1; k >= 0; --k) | ||
| { | ||
| if (V_stristr(player->GetPlayerName(), nameList[availableList[k]])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably fine for the current list, but if we ever add more short names like "Ed" to the list, a partial match could potentially lead to an accidental collision. Changing "Ed" to "0edit" made this case even more rare, but up to you if you think this would be worth being more explicit about.
A more explicit string comparison would be along the lines of:
if (V_stricmp(playerName, nameList[availableList[k]]) == 0)An exact match could also be faster than a substring match, but I'd be surprised if it makes a difference here.
|
|
||
| return nameList[availableList[RandomInt(0, availableList.Count() - 1)]]; | ||
|
|
||
| //return nameList[RandomInt(0, ARRAYSIZE(nameList) - 1)]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you come back with another commit, might be worth cleaning up this previous line.
|
This will probably be closed in favour of #1289 but will leave it up until it gets merged. |
Description
More bot names, and there should never be any duplicate names on a 32 player server now
Toolchain