IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Adding bots without needing cheats in TF2
Cheeseh
post Apr 2 2014, 01:06 PM
Post #1


Admin
*****

Group: Admin
Posts: 3,018
Joined: 11-September 03
From: uk
Member No.: 1



Well fellas, I've finally got it working, so it seems, to add bots without needing cheats. First it worked no problem in DOD:S but then the same code didn't work in TF2 because the TF2 bot command checks for sv_cheats to be on no matter if it is a cheat command or not (It actually isn't a cheat command but it just checks if sv_cheats is on or not).

But now I worked around it.



Here's just a bit of code on how to do it because I miss the good old bot programming days

CODE

plugin::load()
{
...
    sv_cheats = cvar->FindVar("sv_cheats");

    puppet_bot_cmd = cvar->FindCommand("bot");
...
}



botadd(szOVName){
        char cmd[128];

        extern ConCommandBase *puppet_bot_cmd;
        extern ConVar bot_cmd_nocheats;

        // Attempt to make puppet bot command cheat free
        if ( puppet_bot_cmd != NULL )
        {
                        // Just incase if bot command needs cheats -- remove the cheats flag
            if ( bot_cmd_nocheats.GetBool() && puppet_bot_cmd->IsFlagSet(FCVAR_CHEAT) )
            {
                int *m_nFlags = (int*)((unsigned long)puppet_bot_cmd + 20); // 20 is offset to flags
            
                *m_nFlags &= ~FCVAR_CHEAT;
            }
        }

        extern ConVar *sv_cheats;
    
        const char *pparg[1];

        pparg[0] = cmd;

                // NOTE: NAME Doesn't work -- it will be added as Bot01 etc
        sprintf(cmd,"%s -name \"%s\"\n",BOT_ADD_PUPPET_COMMAND,szOVName);

        CCommand *com = new CCommand(1,pparg);

                // Trick the bot command that SV_Cheats is on but actually it isn't
        sv_cheats->SetValue(1);
                // THIS NEEDS TO BE HERE because the bot will be added as soon as we call Dispatch()
        m_bControlNext = true;
                // directly call the bot command through the engine
        ((ConCommand*)puppet_bot_cmd)->Dispatch(*com);
        sv_cheats->SetValue(0); // reset sv_cheats

        delete com;
}

plugin::client_put_in_server(edict_t *pEntity, char const *playername)
{
     CBots::handlePlayerJoin(pEntity,playername);
}

CBots :: handlePlayerJoin ( edict_t *pEdict, const char *name )
{
    static int botnum;

    if ( m_bControlNext && ((strcmp(&name[strlen(name)-strlen(m_szNextName)],m_szNextName) == 0)) || (sscanf(name,"Bot%d",&botnum) == 1) )
    {
        m_ControlQueue.push(pEdict);
        m_bControlNext = false;
        engine->SetFakeClientConVarValue(pEdict,"tf_medigun_autoheal","1");    

        return true;
    }

    return false;
}

void CBots :: handleAutomaticControl ()
{
    if ( !m_ControlQueue.empty() )
    {
        edict_t *pEdict = (edict_t*)m_ControlQueue.front();

        IPlayerInfo *p = playerinfomanager->GetPlayerInfo(pEdict);

        // wait until fake client flag is set
        if ( p && p->IsFakeClient() )
        {
            // until it has an 'unknown' remove from queue and create bot
            if ( pEdict->GetUnknown() )
            {
                //extern ConVar rcbot_runplayercmd;

                m_ControlQueue.pop();

                HookPlayerRunCommand(pEdict);

                //engine->SetFakeClientConVarValue( pEdict, "name",m_pNextProfile->getName() );

                m_Bots[slotOfEdict(pEdict)]->createBotFromEdict(pEdict,m_pNextProfile);

                extern ConCommandBase *puppet_bot_cmd;
                extern ConVar bot_cmd_nocheats;
                
                // Reset Cheat Flag
                if ( puppet_bot_cmd != NULL )
                {
                    if ( bot_cmd_nocheats.GetBool() && !puppet_bot_cmd->IsFlagSet(FCVAR_CHEAT) )
                    {
                        int *m_nFlags = (int*)((unsigned long)puppet_bot_cmd + 20); // 20 is offset to flags
            
                        *m_nFlags |= FCVAR_CHEAT;
                    }
                }

            }
        }
        
    }
}



Although you'll still get the 'sv_cheats on and off' messages but they have no effect on the achievements as they're turned on and off so quickly.

Although I also found a simple way to stop the message. To stop the message from showing I did this.
CODE

        int *m_nFlags = (int*)((unsigned long)sv_cheats + 20); // 20 is offset to flags

        if ( sv_cheats->IsFlagSet(FCVAR_NOTIFY) )
            *m_nFlags &= ~FCVAR_NOTIFY;

        sv_cheats->SetValue(1);
        m_bControlNext = true;
        ((ConCommand*)puppet_bot_cmd)->Dispatch(*com);
        sv_cheats->SetValue(0);

        *m_nFlags |= FCVAR_NOTIFY;


so starting next version, bots should be cheat free and achievement activated baby and no darn sv_cheats messages!
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
genmac
post Dec 4 2014, 03:07 AM
Post #2


RCBot Guru
*****

Group: Waypointers
Posts: 571
Joined: 11-November 11
Member No.: 2,098



I don't understand any of that but I think it means....awesomeness hehe!
Glad you finally got around that cheat bot spawner thingy and their navigating speed, I knew you can do it so
rcbot future is still well and good keep up the good work!
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 22nd October 2019 - 02:19 PM