.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Bot Coding (http://forums.bots-united.com/forumdisplay.php?f=24)
-   -   I need by some help for the team detecting. (http://forums.bots-united.com/showthread.php?t=4688)

The Storm 19-11-2005 17:45

I need by some help for the team detecting.
 
Hi all,

Some of you already know that I code a bot for the HL mod Sands of War.
So I have a little problem. The bots shoot at the theyer teammates and I can't fix that. I code directly in to the SoW source. Here what I use:

Code:

void SearchForEnemy(CBasePlayer *bot)
{ //Function to find enemies.

        EHANDLE nearestenemy;
        nearestenemy = NULL;

        for ( int i = 1; i <= gpGlobals->maxClients; i++ )
        {
                EHANDLE pPlayer;
                pPlayer = GetClientByIndex(i);
                float Dist1;
                float closest1 = 1000;

                // skip invalid players and skip self (i.e. this bot)
                if ((pPlayer == NULL) || (pPlayer == bot))
                        continue;
 
                // skip this player if not alive (i.e. dead or dying)
                if (pPlayer->pev->deadflag != DEAD_NO)
                        continue;

                // skip players that are in botcam mode...
                if (pPlayer->pev->effects & EF_NODRAW)
                        continue;
/*
                // skip the teammates... This is commented out because its not work.
                if (bot->pev->team == pPlayer->pev->team)
                        continue;*/
/*
                // skip the teammates... This is commented out because its not work.
                if (g_pGameRules->GetTeamID(bot) == g_pGameRules->GetTeamID(pPlayer))
                        continue;*/
                // This too its not work.
                if (UTIL_TeamsMatch(bot->TeamID(), pPlayer->TeamID()))
                        continue;

                if (pPlayer != NULL && pPlayer->pev)
                        Dist1 = (bot->pev->origin - pPlayer->pev->origin).Length();

                        if ((bot->pev->origin - pPlayer->pev->origin).Length() < closest1)
                        {
                            closest1 = (bot->pev->origin - pPlayer->pev->origin).Length();
                                nearestenemy = pPlayer;
                        }
        } //This will find the nearest enemy

        if (nearestenemy != NULL)
        {
                bot->enemy = nearestenemy;
        } //If we found someone, set them as our enemy.
}

I know that SoW is closed source but if can help me I will be very happy.

Pierre-Marie Baty 21-11-2005 00:01

Re: I need by some help for the team detecting.
 
The coders of this mod may use their own technique for storing the players' team (such as in a new variable in their private data). Just ask them to write into pev->team like well-educated persons :)

The Storm 22-11-2005 18:48

Re: I need by some help for the team detecting.
 
OK. So the teams are defined in this way:
pPlayer->m_iTeam. I must set this to spawn the bot correct.
So I tryed this:
Code:

if (bot->m_iTeam == pPlayer->m_iTeam)
        continue;

But still its not working. I don't have more ideas. :(

Pierre-Marie Baty 22-11-2005 18:53

Re: I need by some help for the team detecting.
 
In that case, it's your bots that don't fill their team number correctly, heh ! ;)


All times are GMT +2. The time now is 23:36.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.