Willkommen ~Gast!
Registrieren || Einloggen || Hilfe/FAQ || Staff
Probleme mit der Registrierung im Forum? Melde dich unter registerEin Bild.
Autor Beitrag
000
27.09.2006, 20:38
RikkuZooo



Hallo, ich hab mal ne frage und zwar wenn ich einen Bot in mein Server lade
dann und dann denn bot um bringe dann Spwant der nicht mehr kann mir mal da einer helfen achso und der rennt die ganze zeit nur mit der Grafy rum
das muss man doch auch andern können oder hier der code von bot:

Quellcode:#include "cbase.h"
#include "player.h"
#include "hl2mp_player.h"
#include "in_buttons.h"
#include "movehelper_server.h"

void ClientPutInServer( edict_t *pEdict, const char *playername );
void Bot_Think( CHL2MP_Player *pBot );

#ifdef _BOT_IMPL

ConVar bot_forcefireweapon( "bot_forcefireweapon", "", 0, "Force bots with the specified weapon to fire." );
ConVar bot_forceattack2( "bot_forceattack2", "0", 0, "When firing, use attack2." );
ConVar bot_forceattackon( "bot_forceattackon", "0", 0, "When firing, don't tap fire, hold it down." );
ConVar bot_flipout( "bot_flipout", "0", 0, "When on, all bots fire their guns." );
ConVar bot_defend( "bot_defend", "0", 0, "Set to a team number, and that team will all keep their combat shields raised." );
ConVar bot_changeclass( "bot_changeclass", "0", 0, "Force all bots to change to the specified class." );
ConVar bot_zombie( "bot_zombie", "0", 0, "Brraaaaaiiiins." );
static ConVar bot_mimic( "bot_mimic", "0", 0, "Bot uses usercmd of player by index." );
static ConVar bot_mimic_yaw_offset( "bot_mimic_yaw_offset", "0", 0, "Offsets the bot yaw." );
ConVar bot_attack( "bot_attack", "1", 0, "Shoot!" );

ConVar bot_sendcmd( "bot_sendcmd", "", 0, "Forces bots to send the specified command." );

ConVar bot_crouch( "bot_crouch", "0", 0, "Bot crouches" );

static int BotNumber = 1;
static int g_iNextBotTeam = -1;
static int g_iNextBotClass = -1;

typedef struct
{
    bool            backwards;

    float            nextturntime;
    bool            lastturntoright;

    float            nextstrafetime;
    float            sidemove;

    QAngle            forwardAngle;
    QAngle            lastAngles;
    
    float            m_flJoinTeamTime;
    int                m_WantedTeam;
    int                m_WantedClass;
} botdata_t;

static botdata_t g_BotData[ MAX_PLAYERS ];

CBasePlayer *BotPutInServer( bool bFrozen, int iTeam )
{
    g_iNextBotTeam = iTeam;

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

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

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

    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;
}

void Bot_RunAll( void )
{
    for ( int i = 1; i <= gpGlobals->maxClients; i++ )
    {
        CHL2MP_Player *pPlayer = ToHL2MPPlayer( UTIL_PlayerByIndex( i ) );

        if ( pPlayer && (pPlayer->GetFlags() & FL_FAKECLIENT) )
        {
            Bot_Think( pPlayer );
        }
    }
}

bool RunMimicCommand( CUserCmd& cmd )
{
    if ( bot_mimic.GetInt() <= 0 )
        return false;

    if ( bot_mimic.GetInt() > gpGlobals->maxClients )
        return false;

    
    CBasePlayer *pPlayer = UTIL_PlayerByIndex( bot_mimic.GetInt()  );
    if ( !pPlayer )
        return false;

    if ( !pPlayer->GetLastUserCommand() )
        return false;

    cmd = *pPlayer->GetLastUserCommand();
    cmd.viewangles[YAW] += bot_mimic_yaw_offset.GetFloat();

    return true;
}

static void RunPlayerMove( CHL2MP_Player *fakeclient, const QAngle& viewangles, float forwardmove, float sidemove, float upmove, unsigned short buttons, byte impulse, float frametime )
{
    if ( !fakeclient )
        return;

    CUserCmd cmd;

    float flOldFrametime = gpGlobals->frametime;
    float flOldCurtime = gpGlobals->curtime;

    float flTimeBase = gpGlobals->curtime + gpGlobals->frametime - frametime;
    fakeclient->SetTimeBase( flTimeBase );

    Q_memset( &cmd, 0, sizeof( cmd ) );

    if ( !RunMimicCommand( cmd ) && !bot_zombie.GetBool() )
    {
        VectorCopy( viewangles, cmd.viewangles );
        cmd.forwardmove = forwardmove;
        cmd.sidemove = sidemove;
        cmd.upmove = upmove;
        cmd.buttons = buttons;
        cmd.impulse = impulse;
        cmd.random_seed = random->RandomInt( 0, 0x7fffffff );
    }

    if( bot_crouch.GetInt() )
        cmd.buttons |= IN_DUCK;

    if ( bot_attack.GetBool() )
        cmd.buttons |= IN_ATTACK;

    MoveHelperServer()->SetHost( fakeclient );
    fakeclient->PlayerRunCommand( &cmd, MoveHelperServer() );

    fakeclient->SetLastUserCommand( cmd );

    fakeclient->pl.fixangle = FIXANGLE_NONE;

    gpGlobals->frametime = flOldFrametime;
    gpGlobals->curtime = flOldCurtime;
}

void Bot_Think( CHL2MP_Player *pBot )
{
    pBot->AddFlag( FL_FAKECLIENT );

    botdata_t *botdata = &g_BotData[ ENTINDEX( pBot->edict() ) - 1 ];

    QAngle vecViewAngles;
    float forwardmove = 0.0;
    float sidemove = botdata->sidemove;
    float upmove = 0.0;
    unsigned short buttons = 0;
    byte  impulse = 0;
    float frametime = gpGlobals->frametime;

    vecViewAngles = pBot->GetLocalAngles();

--

AirChina Mobile

zum Seitenanfang zum Seitenende Profil || Suche
001
27.09.2006, 20:39
RikkuZooo



Teil 2 von source.

Quellcode:if ( pBot->IsAlive() && (pBot->GetSolid() == SOLID_BBOX) )
    {
        trace_t trace;

        if ( !pBot->IsEFlagSet(EFL_BOT_FROZEN) )
        {
            if ( pBot->m_iHealth == 100 )
            {
                forwardmove = 600 * ( botdata->backwards ? -1 : 1 );
                if ( botdata->sidemove != 0.0f )
                {
                    forwardmove *= random->RandomFloat( 0.1, 1.0f );
                }
            }
            else
            {
                forwardmove = 0;
            }
        }

        if ( !pBot->IsEFlagSet(EFL_BOT_FROZEN) && pBot->m_iHealth == 100 )
        {
            Vector vecEnd;
            Vector forward;

            QAngle angle;
            float angledelta = 15.0;

            int maxtries = (int)360.0/angledelta;

            if ( botdata->lastturntoright )
            {
                angledelta = -angledelta;
            }

            angle = pBot->GetLocalAngles();

            Vector vecSrc;
            while ( --maxtries >= 0 )
            {
                AngleVectors( angle, &forward );

                vecSrc = pBot->GetLocalOrigin() + Vector( 0, 0, 36 );

                vecEnd = vecSrc + forward * 10;

                UTIL_TraceHull( vecSrc, vecEnd, VEC_HULL_MIN, VEC_HULL_MAX,
                    MASK_PLAYERSOLID, pBot, COLLISION_GROUP_NONE, &trace );

                if ( trace.fraction == 1.0 )
                {
                    if ( gpGlobals->curtime < botdata->nextturntime )
                    {
                        break;
                    }
                }

                angle.y += angledelta;

                if ( angle.y > 180 )
                    angle.y -= 360;
                else if ( angle.y < -180 )
                    angle.y += 360;

                botdata->nextturntime = gpGlobals->curtime + 2.0;
                botdata->lastturntoright = random->RandomInt( 0, 1 ) == 0 ? true : false;

                botdata->forwardAngle = angle;
                botdata->lastAngles = angle;

            }


            if ( gpGlobals->curtime >= botdata->nextstrafetime )
            {
                botdata->nextstrafetime = gpGlobals->curtime + 1.0f;

                if ( random->RandomInt( 0, 5 ) == 0 )
                {
                    botdata->sidemove = -600.0f + 1200.0f * random->RandomFloat( 0, 2 );
                }
                else
                {
                    botdata->sidemove = 0;
                }
                sidemove = botdata->sidemove;

                if ( random->RandomInt( 0, 20 ) == 0 )
                {
                    botdata->backwards = true;
                }
                else
                {
                    botdata->backwards = false;
                }
            }

            pBot->SetLocalAngles( angle );
            vecViewAngles = angle;
        }

        if ( bot_defend.GetInt() == pBot->GetTeamNumber() )
        {
            buttons |= IN_ATTACK2;
        }

        else if ( bot_forcefireweapon.GetString() )
        {
            CBaseCombatWeapon *pWeapon = pBot->Weapon_OwnsThisType( bot_forcefireweapon.GetString() );
            if ( pWeapon )
            {
                CBaseCombatWeapon *pActiveWeapon = pBot->GetActiveWeapon();

--

AirChina Mobile

zum Seitenanfang zum Seitenende Profil || Suche
002
27.09.2006, 20:40
RikkuZooo



Teil 3 von Source.

Quellcode:if ( pActiveWeapon != pWeapon )
                {
                    pBot->Weapon_Switch( pWeapon );
                }
                else
                {
                    if ( bot_forceattackon.GetBool() || (RandomFloat(0.0,1.0) > 0.5) )
                    {
                        buttons |= bot_forceattack2.GetBool() ? IN_ATTACK2 : IN_ATTACK;
                    }
                }
            }
        }

        if ( bot_flipout.GetInt() )
        {
            if ( bot_forceattackon.GetBool() || (RandomFloat(0.0,1.0) > 0.5) )
            {
                buttons |= bot_forceattack2.GetBool() ? IN_ATTACK2 : IN_ATTACK;
            }
        }
        
        if ( strlen( bot_sendcmd.GetString() ) > 0 )
        {
            pBot->ClientCommand( bot_sendcmd.GetString() );

            bot_sendcmd.SetValue("");
        }
    }
    else
    {
        if ( !pBot->IsAlive() )
        {
            if ( random->RandomInt( 0, 100 ) > 80 )
            {
                if ( random->RandomInt( 0, 1 ) == 0 )
                {
                    buttons |= IN_JUMP;
                }
                else
                {
                    buttons = 0;
                }
            }
        }
    }    if ( bot_flipout.GetInt() >= 2 )
    {

        QAngle angOffset = RandomAngle( -1, 1 );

        botdata->lastAngles += angOffset;

        for ( int i = 0 ; i < 2; i++ )
        {
            if ( fabs( botdata->lastAngles[ i ] - botdata->forwardAngle[ i ] ) > 15.0f )
            {
                if ( botdata->lastAngles[ i ] > botdata->forwardAngle[ i ] )
                {
                    botdata->lastAngles[ i ] = botdata->forwardAngle[ i ] + 15;
                }
                else
                {
                    botdata->lastAngles[ i ] = botdata->forwardAngle[ i ] - 15;
                }
            }
        }

        botdata->lastAngles[ 2 ] = 0;

        pBot->SetLocalAngles( botdata->lastAngles );
    }

    pBot->PostClientMessagesSent();

    RunPlayerMove( pBot, pBot->GetLocalAngles(), forwardmove, sidemove, upmove, buttons, impulse, frametime );
}

#endif
Sorry wegen der 3 folgenden post aber man kann das alles nicht in einen rein machen... :-(

--

AirChina Mobile

zum Seitenanfang zum Seitenende Profil || Suche
003
28.09.2006, 18:10
Backofen



Das wird glaub ich das kleinere Problem sein mit den 3 posts! Aber wie haste die Datei genannt und wo haste die reingepackt? Das möchte ich wissen, weil ich den code ma ausprobiern will, ob dat bei mir auch so ist!

--

zum Seitenanfang zum Seitenende Profil || Suche
004
28.09.2006, 18:21
RikkuZooo



ich denke eher du wilst nur Bots in deiner mod haben hehe. ^^ Such das
sdk durch dann wirst du fündig hab das problem gefunden und jetzt geht
der bot bei mir der fehler war bei ner dummen sache um einen bot spawnen
zu lassen muss man einen info_player_deahtmatch machen ich hatte
auf meiner map aber nur 1 start punkt als info_player_start :-P

--

AirChina Mobile

zum Seitenanfang zum Seitenende Profil || Suche
005
28.09.2006, 18:31
Backofen



Tja! Aber stört dich das wenn ich auch bots in meiner HL2 mod hab?

--

zum Seitenanfang zum Seitenende Profil || Suche
006
28.09.2006, 18:45
RikkuZooo



Ne eigenlich nicht, Also die dateien sind in:
dlls\hl2mp_dll\hl2mp_bot_temp.cpp

aber ne anleitung mach ich jetzt nich hab keine zeit jetzt muss grade
was wichtiges programmieren... kotz teammenü... KOTZ NEUES SDK...

--

AirChina Mobile


Dieser Beitrag wurde am 28.09.2006 um 18:46 von Rikku2000 bearbeitet.
zum Seitenanfang zum Seitenende Profil || Suche
007
29.09.2006, 14:01
Backofen



na dann!
Dann will ich ma viel glück wünschen :D
trotzdem danke!

--

zum Seitenanfang zum Seitenende Profil || Suche