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:
parent
659f69d0f0
commit
b606b78cda
4 changed files with 34 additions and 11 deletions
|
|
@ -31,7 +31,8 @@ CR_DECLARE_SCOPED_ENUM (NetMsg,
|
|||
FlashBat = 20,
|
||||
Fashlight = 21,
|
||||
ItemStatus = 22,
|
||||
ScoreInfo = 23
|
||||
ScoreInfo = 23,
|
||||
ScoreAttrib = 24
|
||||
)
|
||||
|
||||
// vgui menus (since latest steam updates is obsolete, but left for old cs)
|
||||
|
|
@ -118,6 +119,10 @@ private:
|
|||
void netMsgNVGToggle ();
|
||||
void netMsgFlashBat ();
|
||||
void netMsgScoreInfo ();
|
||||
void netMsgScoreAttrib ();
|
||||
|
||||
private:
|
||||
Bot *pickBot (int32 index);
|
||||
|
||||
public:
|
||||
MessageDispatcher ();
|
||||
|
|
|
|||
|
|
@ -3001,10 +3001,6 @@ void Bot::update () {
|
|||
m_team = game.getTeam (ent ());
|
||||
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)) {
|
||||
m_hasC4 = !!(pev->weapons & cr::bit (Weapon::C4));
|
||||
|
||||
|
|
|
|||
|
|
@ -1235,7 +1235,6 @@ void Bot::newRound () {
|
|||
|
||||
m_navTimeset = game.time ();
|
||||
m_team = game.getTeam (ent ());
|
||||
m_isVIP = false;
|
||||
|
||||
resetPathSearchType ();
|
||||
|
||||
|
|
@ -1243,7 +1242,6 @@ void Bot::newRound () {
|
|||
m_states = 0;
|
||||
clearTasks ();
|
||||
|
||||
m_isVIP = false;
|
||||
m_isLeader = false;
|
||||
m_hasProgressBar = false;
|
||||
m_canChooseAimDirection = true;
|
||||
|
|
|
|||
|
|
@ -331,10 +331,7 @@ void MessageDispatcher::netMsgScoreInfo () {
|
|||
if (m_args.length () < min) {
|
||||
return;
|
||||
}
|
||||
auto &client = util.getClient (m_args[index].long_ - 1);
|
||||
|
||||
// get the bot in this msg
|
||||
auto bot = bots[client.ent];
|
||||
auto bot = pickBot (index);
|
||||
|
||||
// if we're have bot, set the kd ratio
|
||||
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 () {
|
||||
enum args { enabled = 0, min = 1 };
|
||||
|
||||
|
|
@ -426,6 +442,7 @@ MessageDispatcher::MessageDispatcher () {
|
|||
addWanted ("NVGToggle", NetMsg::NVGToggle, &MessageDispatcher::netMsgNVGToggle);
|
||||
addWanted ("FlashBat", NetMsg::FlashBat, &MessageDispatcher::netMsgFlashBat);
|
||||
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
|
||||
addWanted ("BotVoice", NetMsg::BotVoice, nullptr);
|
||||
|
|
@ -542,3 +559,10 @@ void MessageDispatcher::ensureMessages () {
|
|||
int32 MessageDispatcher::id (NetMsg 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];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue