improve: use ScoreAttrib message to detect if bot is a VIP or not. (#356)

This should resolve problems with bot behavior, when plugins changes VIP player model to something else.
This commit is contained in:
jeefo 2022-08-03 23:59:57 +03:00 committed by GitHub
commit b606b78cda
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 11 deletions

View file

@ -31,7 +31,8 @@ CR_DECLARE_SCOPED_ENUM (NetMsg,
FlashBat = 20, FlashBat = 20,
Fashlight = 21, Fashlight = 21,
ItemStatus = 22, ItemStatus = 22,
ScoreInfo = 23 ScoreInfo = 23,
ScoreAttrib = 24
) )
// vgui menus (since latest steam updates is obsolete, but left for old cs) // vgui menus (since latest steam updates is obsolete, but left for old cs)
@ -118,6 +119,10 @@ private:
void netMsgNVGToggle (); void netMsgNVGToggle ();
void netMsgFlashBat (); void netMsgFlashBat ();
void netMsgScoreInfo (); void netMsgScoreInfo ();
void netMsgScoreAttrib ();
private:
Bot *pickBot (int32 index);
public: public:
MessageDispatcher (); MessageDispatcher ();

View file

@ -3001,10 +3001,6 @@ void Bot::update () {
m_team = game.getTeam (ent ()); m_team = game.getTeam (ent ());
m_healthValue = cr::clamp (pev->health, 0.0f, 100.0f); m_healthValue = cr::clamp (pev->health, 0.0f, 100.0f);
if (game.mapIs (MapFlags::Assassination) && !m_isVIP) {
m_isVIP = util.isPlayerVIP (ent ());
}
if (m_team == Team::Terrorist && game.mapIs (MapFlags::Demolition)) { if (m_team == Team::Terrorist && game.mapIs (MapFlags::Demolition)) {
m_hasC4 = !!(pev->weapons & cr::bit (Weapon::C4)); m_hasC4 = !!(pev->weapons & cr::bit (Weapon::C4));

View file

@ -1235,7 +1235,6 @@ void Bot::newRound () {
m_navTimeset = game.time (); m_navTimeset = game.time ();
m_team = game.getTeam (ent ()); m_team = game.getTeam (ent ());
m_isVIP = false;
resetPathSearchType (); resetPathSearchType ();
@ -1243,7 +1242,6 @@ void Bot::newRound () {
m_states = 0; m_states = 0;
clearTasks (); clearTasks ();
m_isVIP = false;
m_isLeader = false; m_isLeader = false;
m_hasProgressBar = false; m_hasProgressBar = false;
m_canChooseAimDirection = true; m_canChooseAimDirection = true;

View file

@ -331,10 +331,7 @@ void MessageDispatcher::netMsgScoreInfo () {
if (m_args.length () < min) { if (m_args.length () < min) {
return; return;
} }
auto &client = util.getClient (m_args[index].long_ - 1); auto bot = pickBot (index);
// get the bot in this msg
auto bot = bots[client.ent];
// if we're have bot, set the kd ratio // if we're have bot, set the kd ratio
if (bot != nullptr) { if (bot != nullptr) {
@ -342,6 +339,25 @@ void MessageDispatcher::netMsgScoreInfo () {
} }
} }
void MessageDispatcher::netMsgScoreAttrib () {
// this message updates the scoreboard attribute for the specified player
enum args { index = 0, flags = 1, min = 2 };
// check the minimum states
if (m_args.length () < min) {
return;
}
auto bot = pickBot (index);
// if we're have bot, set the vip state
if (bot != nullptr) {
constexpr int32 kPlayerIsVIP = cr::bit (2);
bot->m_isVIP = !!(m_args[flags].long_ & kPlayerIsVIP);
}
}
void MessageDispatcher::netMsgBarTime () { void MessageDispatcher::netMsgBarTime () {
enum args { enabled = 0, min = 1 }; enum args { enabled = 0, min = 1 };
@ -426,6 +442,7 @@ MessageDispatcher::MessageDispatcher () {
addWanted ("NVGToggle", NetMsg::NVGToggle, &MessageDispatcher::netMsgNVGToggle); addWanted ("NVGToggle", NetMsg::NVGToggle, &MessageDispatcher::netMsgNVGToggle);
addWanted ("FlashBat", NetMsg::FlashBat, &MessageDispatcher::netMsgFlashBat); addWanted ("FlashBat", NetMsg::FlashBat, &MessageDispatcher::netMsgFlashBat);
addWanted ("ScoreInfo", NetMsg::ScoreInfo, &MessageDispatcher::netMsgScoreInfo); addWanted ("ScoreInfo", NetMsg::ScoreInfo, &MessageDispatcher::netMsgScoreInfo);
addWanted ("ScoreAttrib", NetMsg::ScoreAttrib, &MessageDispatcher::netMsgScoreAttrib);
// we're need next messages IDs but we're won't handle them, so they will be removed from wanted list as soon as they get engine IDs // we're need next messages IDs but we're won't handle them, so they will be removed from wanted list as soon as they get engine IDs
addWanted ("BotVoice", NetMsg::BotVoice, nullptr); addWanted ("BotVoice", NetMsg::BotVoice, nullptr);
@ -542,3 +559,10 @@ void MessageDispatcher::ensureMessages () {
int32 MessageDispatcher::id (NetMsg msg) { int32 MessageDispatcher::id (NetMsg msg) {
return m_maps[msg]; return m_maps[msg];
} }
Bot *MessageDispatcher::pickBot (int32 index) {
const auto &client = util.getClient (m_args[index].long_ - 1);
// get the bot in this msg
return bots[client.ent];
}