Ok! Here it is. This is just the beta
for the free edition of the AI. It is
bug free. There is one little problem tho,
when there are no enemies near by, it will
shoot you. Make shure there is always an
enemy near by so it wont shoot you. The
AI will follow you wherever you go like
on Halo.

Little note for nemesis,
Hey nemesis, if you could find out how
to make it so the ai wont shoot you anymore
it would be grateful.

anyway, enjoy!
[Smile] [Smile] [Smile] [Smile]

Shall whoever use this script without
credit would be haunted for the rest
of his life
[Mad] [Mad]
When you credit me, Dont put my name, put
ventelation studios.

there might be some functions i did not
include with this script.

Please feel free to delete where i called
functions that i didnt add.

-ChrispiZ
contact me regarding questions and concerns
dzung84088@yahoo.com
code:
 
//Ally_AI
//Basic Edition
//written by Chris Le
//copyright ©2001-2003 Ventelation Studios
//
//This script is used for fps style games
//It makes a character entity a frienly ally
//who helps you on your quest
//The Ally_AI follows you around
//when it spots an enemy, it will fire
//you could change what type of bullets it
//will fire below in the script
//enjoy!
//this version is v1.0
//Check for more updates on this ai
//For more advanced ally ai, purchase the following editions
//
//Silver Edition
//
//contains
//-Could here sounds
//-More advanced pathfinding
//-Could reload weapons
//-Could pickup weapons
//
//Gold Edition
//
//contains
//
//-Could here sounds
//-More advanced pathfinding
//-Could reload weapons
//-Could pickup weapons
//-Could communicate with other friendly AI
//-Could Use melee weapons in battle
//-Could Use Medkits if they could find one
//-Could heal you if they have a med kit
//-New ally ai could be used as bots for tournament style fps's

//please use at your own risk!
//This code uses template code
//also uses the advance_pathfinding code included with this script
//advance_pathfinding.wdl
//Instructions.

//
//
//ally follows player
//pointer
entity* ally_target; // Target entity, used in attacking
var indicator = 0;
synonym ally {type entity;}

action allystate_follow
//based on the actor_follow in the templates
{

if(my._FORCE == 0) { my._FORCE = 2; }
if(my._MOVEMODE == 0) { my._MOVEMODE = _MODE_WALKING; }
if(my._WALKFRAMES == 0) { my._WALKFRAMES = DEFAULT_WALK; }
if(my._RUNFRAMES == 0) { my._RUNFRAMES = DEFAULT_RUN; }
if(my._WALKSOUND == 0) { my._WALKSOUND = _SOUND_WALKER; }
if (my._health <= 0) { allystate_die(); return; }
if (my._health < 30) { allystate_escape(); return;}
anim_init();
my._force = 2.5; //2.5 for running effect
while(1)
{
// calculate a direction to walk into
temp.x = player.x - my.x;
temp.y = player.y - my.y;
temp.z = 0;
vec_to_angle(MY_ANGLE,temp);

// turn towards player
MY_ANGLE.tilt = 0;
MY_ANGLE.roll = 0;
force = my._FORCE * 2;
actor_turn();

// walk towards him
temp = (player.x - my.x)*(player.x - my.x)+(player.y - my.y)*(player.y - my.y);
if(temp < 50000) // 100^2
{
allystate_wait();
return;
}
if(temp > 50000) // 100^2
{
force = my._FORCE;
my._MOVEMODE = _MODE_WALKING;
actor_move();
}
wait(1);
}
}


//Dying Function
//You could modify this to do other several things like:
//when ally dies, you could add functions so that your ally
//could scream in pain

function allystate_die()
{
my._animdist = 0; // reset entity's animation time to zero
while (my._animdist < 100)
{
ent_frame("death",my._animdist); // set the frame from the percentage
my._animdist += 5 * time; // calculate next percentage for death in 1.25 secs
wait(1);
}
my.enable_scan = off; // becomes insensible
my.enable_shoot = off;
my.event = null; // does not react anymore
}

// event function that recieves hits
function myfight_event()
{
if (((event_type == event_scan) && (indicator == _explode)))
|| ((event_type == event_shoot) && (indicator == _gunfire))
{
my._signal = 1;
EMIT 30,my.POS,bloodspray;
if (my._armor <= 0) { my._health -= damage; }
else { my._armor -= damage; }
}
if ((event_type == event_detect) && (you != player) && (you.flag1 >0) && (you.skill9 > 0) ) {
my._signal = 1; }
ally_target = you;
wait(1);
}


//wait function. Ally stands
function allystate_wait()
{
my._animdist = 0;
while (1) {
if (my._health <= 0) { allystate_die(); return; }
if (my._health < 30) { allystate_escape(); return;}
ent_cycle("wait", my._animdist);
my._animdist += 5 * time;
// scan for the enemy
temp.pan = 180;
temp.tilt = 180;
temp.z = 1000;
indicator = _watch;
scan_entity(my.x,temp);
if (my._signal == 1) { allystate_attack(); return; }

force = 0; // no force from this actor
actor_move(); // react to outside forces (gravity, etc) even while waiting

waitt(1);
}
}


//attack state, my favorite!!!
// here is where you could modify what type on bullets it will shoot
// and how much damage it causes

function allystate_attack()
{

my._animdist = 0;
while (1) {
my._MOVEMODE = _MODE_ATTACK;
if (my._health <= 0) { allystate_die(); return; }
if (my._health < 30) { allystate_escape(); return; }
if (ally_target == null){allystate_follow(); return;}

//turns towards enemy
temp.x = ally_target.x - my.x;
temp.y = ally_target.y - my.y;
temp.z = ally_target.z - my.z;
vec_to_angle(my_angle,temp);
force = 4;
actor_turn();
ent_cycle("attack", my._animdist);
my._animdist += 5 * time;
if (my._animdist > 100) {
my._animdist -= 100;
shot_speed.x = 100;
shot_speed.y = 0;
shot_speed.z = 0;
my_angle.pan = my.pan;
vec_rotate(shot_speed, my_angle);
damage = 20;
fire_mode = 302.2;
create(fireball, my.x, bullet_shot);
wait(1);

}
wait(1);
}
}

//escape state. makes the ally a chicken and runoff
function allystate_escape()
{
while(1) {
if (my._health <= 0) { allystate_die(); return; }
temp.x = my.x - player.x;
temp.y = my.y - player.y;
temp.z = my.z - player.z;
vec_to_angle(my_angle,temp);
force = 4;
actor_turn();
//walks away like a chicken
actor_move();
wait(1);
}
}



action b_ally_ai_v1
{
ally = me;
my._walkframes = 1;
my._entforce = 0.7;
my._armor = 100;
my._health = 100;
my._signal = 0;
my._MUZZLE_VERT = 691;
my.enable_scan = on;
my.enable_shoot = on;
my.enable_detect = on;
my.event = myfight_event;

allystate_wait();

}





.,.,.,., SiGh,