View Single Post
I need by some help for the team detecting.
Old
  (#1)
The Storm
Council Member / E[POD]bot developer
 
The Storm's Avatar
 
Status: Offline
Posts: 1,620
Join Date: Jul 2004
Location: Bulgaria
Default I need by some help for the team detecting. - 19-11-2005

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.
  
Reply With Quote