Пример #1
0
//-----------------------------------------------------------------------------
// Purpose: Create a new Bot and put it in the game.
// Output : Pointer to the new Bot, or NULL if there's no free clients.
//-----------------------------------------------------------------------------
CBasePlayer *BotPutInServer( bool bFrozen, int iTeam )
{
	g_iNextBotTeam = iTeam;

	char botname[ 64 ];
	Q_snprintf( botname, sizeof( botname ), "Bot%02i", BotNumber );

	// This is an evil hack, but we use it to prevent sv_autojointeam from kicking in.

	edict_t *pEdict = engine->CreateFakeClient( botname );

	if (!pEdict)
	{
		Msg( "Failed to create Bot.\n");
		return NULL;
	}

	// Allocate a CBasePlayer for the bot, and call spawn
	//ClientPutInServer( pEdict, botname );
	CHL2MP_Player *pPlayer = ((CHL2MP_Player *)CBaseEntity::Instance( pEdict ));
	pPlayer->ClearFlags();
	pPlayer->AddFlag( FL_CLIENT | FL_FAKECLIENT );

	if ( bFrozen )
		pPlayer->AddEFlags( EFL_BOT_FROZEN );

	BotNumber++;

	g_BotData[pPlayer->entindex()-1].m_WantedTeam = iTeam;
	g_BotData[pPlayer->entindex()-1].m_flJoinTeamTime = gpGlobals->curtime + 0.3;

	return pPlayer;
}
Пример #2
0
//-----------------------------------------------------------------------------
// Purpose: Create a new Bot and put it in the game.
// Output : Pointer to the new Bot, or NULL if there's no free clients.
//-----------------------------------------------------------------------------
CBasePlayer *BotPutInServer( bool bFrozen, int iTeam )
{
    g_iNextBotTeam = iTeam;

    char botname[ 64 ];
    Q_snprintf( botname, sizeof( botname ), "Bot%02i", BotNumber );

    // This is an evil hack, but we use it to prevent sv_autojointeam from kicking in.

    edict_t *pEdict = engine->CreateFakeClient( botname );

    if (!pEdict)
    {
        Msg( "Failed to create Bot.\n");
        return NULL;
    }

    // Allocate a CBasePlayer for the bot, and call spawn
    //ClientPutInServer( pEdict, botname );
    CHL2MP_Player *pPlayer = ((CHL2MP_Player *)CBaseEntity::Instance( pEdict ));
    pPlayer->ClearFlags();
    pPlayer->AddFlag( FL_CLIENT | FL_FAKECLIENT );

    if ( bFrozen )
        pPlayer->AddEFlags( EFL_BOT_FROZEN );

    BotNumber++;

    g_BotData[pPlayer->entindex()-1].m_WantedTeam = iTeam;
    g_BotData[pPlayer->entindex()-1].m_flJoinTeamTime = gpGlobals->curtime + 0.3;

    //DHL - Skillet - Spawn the bot
    pPlayer->ChangeTeam( TEAM_UNASSIGNED ); //This is required for PickDefaultSpawnTeam() to work
    pPlayer->Spawn();
    //pPlayer->SetModelName( MAKE_STRING(bot_playermodel.GetString()) );
    if ( Q_strlen( bot_playermodel.GetString() ) > 2 )
        pPlayer->SetModel( bot_playermodel.GetString() );

    return pPlayer;
}