Slavebot , need small help


(Jaquboss) #1

Hi , want to make bot which will attack/ follow players …
But i need few things

  1. make bot look at desired entity
  2. give him a field of vision

of course it is supposed to be little bot open for everyone
if you can help adding more code it will be cool

here is what i got
( ai_main.c , after)

	if (ucmd->weapon != bi->weapon && bi->weapon == WP_BINOCULARS)
		ucmd->wbuttons |= WBUTTON_ZOOM;

ok here is it go , for use just uncomment stock ET bot spawn command



	//////////////////////////////////////////////////////////////////////
	// Slavebot by Jaquboss								START			//
//////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////
// Ironsights handling 
#ifdef FALCKONET // FalckonET only stuff

	if ( BG_IsAdsWeapon(bi->weapon) ) { 
			if ( !(g_entities[bs->client].client->ps.eFlags & EF_AIMING) ) {
		ucmd->wbuttons |= WBUTTON_ZOOM;
			}
		}
#endif
///////////////////////////////////////////////////////
// Prone Handling

	if( g_entities[bs->client].health < 35) {
	bi->actionflags |=	ACTION_PRONE;
			} 

////////////////////////////////////////////////////////
// Reload handling

	if	(g_entities[bs->client].client->ps.ammoclip == 0 &&  g_entities[bs->client].client->ps.ammo > 0 && g_entities[bs->client].client->ps.weaponstate != WEAPON_RELOADING ) {
		ucmd->wbuttons |= WBUTTON_RELOAD;
	}
	
/////////////////////////////////////////////////////////
// Rotate around

	if ( g_entities[bs->client].client) {
		int timer;

//bi->actionflags |= ACTION_MOVEFORWARD | ACTION_MOVELEFT;

timer = 60 - level.time;

	if (timer < 0) {
	ucmd->angles[YAW] = timer;
	timer = -60 + level.time;
	} else {
	ucmd->angles[YAW] = timer;
	}

	}
////////////////////////////////////////////////////////////
// Attack handling

#ifdef FALCKONET
if (  !(g_entities[bs->client].client->ps.pm_flags & PMF_FIREHELD ) ){//1 // learn bots to use semi fire weapons
#endif
		trace_t trace;
		vec3_t target ,  end, point , foward, right, up;

	
	AngleVectors (g_entities[bs->client].client->ps.viewangles, forward, right, up);


	VectorCopy( g_entities[bs->client].r.currentOrigin, point );
	point[2] += g_entities[bs->client].client->ps.viewheight;


	VectorMA (point, 1000, forward, end); // long range



	trap_Trace (&trace, point, NULL, NULL, end, g_entities[bs->client].s.number, CONTENTS_BODY);
//////////////////////////////////////////////
// Client in area
	if (trace.fraction != 1.0) {//2 Client Detected

///////////////////////////////////////////////
// enemy in area
	if (  g_entities[bs->client].client->sess.sessionTeam !=  g_entities[trace.entityNum].client->sess.sessionTeam  ) {//3 Enemy Spotted

bi->actionflags |= ACTION_CROUCH;

///////////////////////////////////////////////
// must go foward if see enemy , but enemy is far
if ( g_entities[bs->client].client->ps.weapon == WP_KNIFE ) {//4 Knife

bi->actionflags &= ~ACTION_CROUCH;
bi->actionflags |= ACTION_MOVEFORWARD;
ucmd->buttons |= BUTTON_SPRINT;

}//4 End Knife

///////////////////////////////////////////////////
// All clear , ATTACK!!
			ucmd->buttons|= BUTTON_ATTACK;
			ucmd->angles[YAW] = ucmd->angles[YAW];

////////////////////////////////////////////////////

	}/*3*//*End Enemy Spotted*/ else {//5 Friend
////////////////////////////////////////////////////
// follow friends
bi->actionflags |= ACTION_MOVEFORWARD;
ucmd->buttons |= BUTTON_SPRINT;
////////////////////////////////////////////////////	
	}//5 End friend


	}//2 End Client Detected

#ifdef FALCKONET
	}//1
#endif

//////////////////////////////////////////////////////////////////////////////
	// Slavebot by Jaquboss								END			//
	//////////////////////////////////////////////////////////////////


i hope we can toggether make a bot that can help on LAN games in every mod that will want to have him

EDIT: added better code with ifdefs , sprint , and changed prone handling


(Jaquboss) #2

Limbo handling code , because stock ET bots wont go to limbo , it needs a func to do it…

	
////////////////////////////////////////////////////////////
// Limbo handling

if ( g_entities[bs->client].client->ps.eFlags & EF_DEAD && !(g_entities[bs->client].client->ps.pm_flags & PMF_LIMBO )){
		int testtime;
		qboolean do_respawn = qfalse; 

 if(g_entities[bs->client].client->sess.sessionTeam == TEAM_AXIS) {
			testtime = (level.dwRedReinfOffset + level.timeCurrent - level.startTime + 1000) % g_redlimbotime.integer;
			do_respawn = (testtime < g_entities[bs->client].client->pers.lastReinforceTime);
			g_entities[bs->client].client->pers.lastReinforceTime = testtime;
		}
		else if (g_entities[bs->client].client->sess.sessionTeam == TEAM_ALLIES) {
			testtime = (level.dwBlueReinfOffset + level.timeCurrent - level.startTime +1000) % g_bluelimbotime.integer;
			do_respawn = (testtime < g_entities[bs->client].client->pers.lastReinforceTime);
			g_entities[bs->client].client->pers.lastReinforceTime = testtime;
		}

		if ( do_respawn ) {
			bi->actionflags |= ACTION_JUMP;
		}

	}

EDIT: repaired to tap it just one second before reinforcements