AI problems with targeting

Topics regarding Scripting with Reality Factory
Post Reply
User avatar
fps
Posts: 504
Joined: Mon Sep 26, 2005 9:54 pm
Location: in a magical land devoid of hope, happiness, and sanity.

AI problems with targeting

Post by fps »

I am having trouble getting the ai scripts to work for my friendly and foe scripts. they are modified versions of the fede_ai scripts and I am running them in close proximity in a modified version of the new scripted player physics demo. they are supposed to find a pawn with HEALTHATTRIB then check if the pawns ent name is followed by a 1 or a 0 and then respond accordingly.
this is a continuation of the old ai post of mine from a while back (ive just got around to working on it now).

the scripts are below. can anyone find why the pawns do not see or target eachother?

Thanks,
Fps

friendly

{
FIREAMMO [pistolbullet] // Projectile fired by pawn
FIREEFFECT [RocketExplosion] // muzzleflash effect
WEAPONMODEL [Laser] // Weapon held by pawn
FIRERATE [0.5] // Weapon firing rate
GROUP [friendly] // Pawn Group - must be targetted by enemies
PLAYERSPEED [60] // Walk Speed
HEALTHATTRIB [health] // health attribute given to pawn
HEALTHAMOUNT [50] // amount of health given to pawn
DAMAGEATTRIB [health] // Atribute damaged by pawn
BOX [24] // Box width
FIREOFFSET [0]
FOV [130]
HEAR_RANGE [700]
ENEMYRANGE [800]
FALSE [false]
TRUE [true]

WALK_IDLEANIM [Idle_Walk] // Idle
WALK_WALKANIM [Walk_N] // Walk anim
WALK_BACKANIM [Walk_S] // walk back anim
WALK_STRAFELEFT [Walk_W] // Strafe left anim
WALK_STRAFERIGHT [Walk_E] // Strafe right anim
WALK_NE [Walk_NE] // Walk anim
WALK_SE [Walk_SE] // walk back anim
WALK_NW [Walk_NW] // Strafe left anim
WALK_SW [Walk_SW]
WALK_HOLD [Idle_Walk_Hold]
WALK_MELEE [Swing]
WALK_FIREAMMO [pistolbullet] // Projectile fired by pawn
WALK_FIREEFFECT [RocketExplosion] // muzzleflash effect
WALK_FIRERATE [0.5] // Weapon firing rate

C_WALK_IDLEANIM [Crouch_Idle_Hide] // Idle AnimationSpeed
C_WALK_SHOOTANIM [Shoot_SMG] // Shoot anim
C_WALK_WALKANIM [Crouch_Walk_N] // Walk anim
C_WALK_BACKANIM [Crouch_Walk_S] // walk back anim
C_WALK_STRAFELEFT [Crouch_Walk_W] // Strafe left anim
C_WALK_STRAFERIGHT [Crouch_Walk_E] // Strafe right anim
C_WALK_WALK_NE [Crouch_Walk_NE] // Walk anim
C_WALK_WALK_SE [Crouch_Walk_SE] // walk back anim
C_WALK_WALK_NW [Crouch_Walk_NW] // Strafe left anim
C_WALK_WALK_SW [Crouch_Walk_SW] // Strafe right anim

C_TO_WALK [Crouch_Idle_Hide_To_Stand]
WALK_TO_C [Stand_To_Crouch_Idle_Hide]

PISTOL_WALK_IDLEANIM [Pistol_Stand_Aim] // Idle AnimationSpeed
PISTOL_WALK_WALKANIM [Pistol_Walk_N] // Walk anim
PISTOL_WALK_BACKANIM [Pistol_Walk_S] // walk back anim
PISTOL_WALK_STRAFELEFT [Pistol_Walk_W] // Strafe left anim
PISTOL_WALK_STRAFERIGHT [Pistol_Walk_E] // Strafe right anim
PISTOL_WALK_NE [Pistol_Walk_NE_Aim] // Walk anim
PISTOL_WALK_SE [Pistol_Walk_SE] // walk back anim
PISTOL_WALK_NW [Pistol_Walk_NW_Aim] // Strafe left anim
PISTOL_WALK_SW [Pistol_Walk_SW_Aim]
PISTOL_WALK_HOLD [Pistol_Stand]
PISTOL_WALK_RELOADANIM [Pistol_Reload]
PISTOL_WALK_DRAW [Pistol_Draw]
PISTOL_WALK_UNDRAW [Pistol_UnDraw]
PISTOL_WALK_MELEE [Pistol_Melee]
PISTOL_FIREAMMO [pistolbullet] // Projectile fired by pawn
PISTOL_FIREEFFECT [RocketExplosion] // muzzleflash effect
PISTOL_FIRERATE [0.5] // Weapon firing rate

C_PISTOL_WALK_IDLEANIM [Pistol_Crouch_Stand_Aim] // Idle AnimationSpeed
C_PISTOL_WALK_WALKANIM [Pistol_Walk_Crouch_N] // Walk anim
C_PISTOL_WALK_BACKANIM [Pistol_Walk_Crouch_S] // walk back anim
C_PISTOL_WALK_STRAFELEFT [Pistol_Walk_Crouch_W] // Strafe left anim
C_PISTOL_WALK_STRAFERIGHT [Pistol_Walk_Crouch_E] // Strafe right anim
C_PISTOL_WALK_NE [Pistol_Walk_Crouch_NE_Aim] // Walk anim
C_PISTOL_WALK_SE [Pistol_Walk_Crouch_SE_Aim] // walk back anim
C_PISTOL_WALK_NW [Pistol_Walk_Crouch_NW_Aim] // Strafe left anim
C_PISTOL_WALK_SW [Pistol_Walk_Crouch_SW_Aim]
C_PISTOL_WALK_HOLD [Pistol_Crouch_Stand]
C_PISTOL_WALK_RELOADANIM [Pistol_Crouch_Reload]
C_PISTOL_WALK_DRAW [Pistol_Crouch_Draw]
C_PISTOL_WALK_UNDRAW [Pistol_Crouch_UnDraw]
C_PISTOL_WALK_MELEE [Pistol_Crouch_Melee]

PISTOL_C_TO_WALK [Pistol_Crouch_To_Pistol_Idle]
PISTOL_WALK_TO_C [Pistol_Idle_To_Pistol_Crouch]

JUMPANIM_JUMP [Jump_Run]
JUMPANIM_GLIDE [jump_glide]
JUMPANIM_LAND [jump_land]

INTERANIM [recon_strike] // Pawn interact anim
DEATHANIM [recon_die] // Death Anim
ROOTBONE [Bip01] // Pawn root bone
WEAPONHAND [ValveBiped.Bip01_R_Hand] // Pawn weapon bone

ANIM [string] // Do Not Edit
ANC [0] // Do Not Edit
LASTANC [0] // Do Not Edit
DIR [0] // Do Not Edit
AT [0.5] // Do Not Edit
INTER [string] // Do Not Edit
TM [0] // Do Not Edit
SPEED [0] //Do Not Edit
TIME [0]
SOUND_TIME [0]
ANIM_TIME [0]
ACTION_TIME [0]
SEARCH_TIME [0]
ATTACK_TIME [0]

SEARCH_NUMBER [0]
MAX_SEARCH_NUMBER [2] // how many time the pawn search the player
BACK_TO_PATROL [3]

MAG [300]
BULLET [0]
Reload [bool]
Hold [bool]
Melee[bool]
Run [bool]
Moving_Success [bool]
FALLING_TIME [0]
LAST_ORDER [string]
NEXT_ORDER [string]
ROTATION_ADD [0]
FIRE_PAUSE [2]
Patrol [bool]
WAIT_TIME [0]
Bot_State [string]
PREVIOUS_YAW [0]

ENEMYRANGE [700]
RANDOM_ATTACK [0]
X_CAMERA[0]

Spawn[()
{
SetFOV(FOV);
Console(true);
HostilePlayer(FALSE);
HostileDifferent(TRUE);
HostileSame(TRUE);
BoxWidth(BOX);
FindTargetOrder(1000,FOUNDENEMY,DAMAGEATTRIB);
AttributeOrder(HEALTHATTRIB,HEALTHAMOUNT,"Die");
LowLevel("Setup");
}]

Setup[()
{
self.yaw_speed=270;
AnimationSpeed(1.2);
SetBoundingBox(WALK_IDLEANIM, BOX );
self.think="Walk_NOWEAPON";

}]

Attack[()
{

if(self.health < 1)
{

AddExplosion("BloodExplosion",GetLastBoneHit(),0,0,0);
SetTargetPoint(random(500,1000),70,random(500,1000));
FireProjectile("bloodbullet", "ValveBiped.Bip01_L_UpperArm",0,0,0,"none",0);
SetTargetPoint(random(-1000,-500),-100000000,random(-500,-1000));
FireProjectile("bloodbullet", "ValveBiped.Bip01_R_Foot",0,0,0,"none",0);
SetTargetPoint(random(-1000,-200),-50,random(1000,200));
FireProjectile("bloodbullet", "ValveBiped.Bip01_R_Forearm",0,0,0,"none",0);
PlaySound("Die1.wav");
SetEventState(EntityName # "_RagDollize_Me", true);
SetEventState("Show_RagDoll", true);
self.think="Pain_Order";
}

if(GetLastBoneHit() = "ValveBiped.Bip01_Head1")
{
PlaySound("Die1.wav");
SetEventState(EntityName # "_RagDollize_Me", true);
SetEventState("Show_RagDoll", true);
self.think="Pain_Order";
}
SetRelBoneRotation(EntityName, "ValveBiped.Bip01_Spine2",0,0,X_CAMERA);
SetRelBoneRotation(EntityName, "ValveBiped.Bip01_Spine1",0,0,X_CAMERA);

X_CAMERA = Integer((self.enemy_pitch / 0.017))/3;

if(X_CAMERA > 30)
{
X_CAMERA = 30;
}
if(X_CAMERA < -5)
{
X_CAMERA = -5;
}


if(self.in_pain)
{
PlaySound("Pain1.wav");
UpdateEnemyVis();
RANDOM_ATTACK = 0;
}
if((IsKeyDown(CAMERA.K_FIRE))and(GetDistanceTo("CAMERA") < HEAR_RANGE))
{
if((CAMERA.BULLET < 5) and (CAMERA.MAG >0) and (GetDistanceTo("CAMERA") < HEAR_RANGE) and (GetEntityAlpha("SMG")=255))
{
RANDOM_ATTACK = 0;
}
}
if(((IsKeyDown(CAMERA.K_FOR))or(IsKeyDown(CAMERA.K_BAK))or(IsKeyDown(CAMERA.K_LEFT))or(IsKeyDown(CAMERA.K_RIGHT))or(IsKeyDown(CAMERA.K_JUMP))) and (LeftCopy(CAMERA.order_name, 6) != "Crouch"))
{
if((GetDistanceTo("CAMERA") < HEAR_RANGE/2) and (IsKeyDown(CAMERA.K_RUN)))
{
UpdateEnemyVis();
RANDOM_ATTACK = 0;
}
if((GetDistanceTo("CAMERA") < HEAR_RANGE/4) and (IsKeyDown(CAMERA.K_RUN)=false))
{
UpdateEnemyVis();
RANDOM_ATTACK = 0;
}
}


debug(self.enemy_vis);


if((IsKeyDown(4)))
{
MAG = 2;
RANDOM_ATTACK = 0;
}


if((self.enemy_range < 200))
{

if(RANDOM_ATTACK = 0)
{
ACTION_TIME= time;
RANDOM_ATTACK = random(8,15);
}
}
if((self.enemy_range > 200))
{
if(RANDOM_ATTACK = 0)
{
ACTION_TIME= time;
RANDOM_ATTACK = random(1,15);
}
}
if((self.enemy_vis) and (Reload=false))
{

if(time > TIME + 0.2)
{
UpdateEnemyVis();
debug("I see you");
}
self.ideal_yaw=self.last_enemy_yaw;


if((RANDOM_ATTACK >= 10))
{
if((BULLET < 5))
{
if(time >ACTION_TIME + 1)
{
RANDOM_ATTACK = 0;
}
if((self.time > TM+PISTOL_FIRERATE) )
{
if(self.enemy_range < 60)
{
TM = time;
PlaySound("metal_reverse.wav");
Melee = true;
}
else
{
TM=self.time;
BULLET = BULLET + 1;
FireProjectileBlind(PISTOL_FIREAMMO,WEAPONHAND,0,0,0,"health", enemy_pitch);
AddExplosion("PMuzzleFlash","ValveBiped.Bip01_R_Hand",0,0,0);
FIREOFFSET = 20;
}
}
}
else
{
if((MAG > = 1))
{
RANDOM_ATTACK = 0;
TM=self.time;
PlaySound("Weapon/reload3.wav");
Reload = true;
}
if((MAG < 1) and (time > TM + PISTOL_FIRERATE))
{
RANDOM_ATTACK = 0;
if(self.enemy_range < 60)
{
TM = time;
PlaySound("metal_reverse.wav");
Melee = true;
}
else
{
RANDOM_ATTACK = 0;
TM=self.time;
PlaySound("pistol_empty.wav");
}
}
}
}
if((RANDOM_ATTACK >= 6) and (RANDOM_ATTACK < 10))
{
ANC=11; // different anc values needed to blend again
AT=0.2;
ANIM=StringCopy(PISTOL_WALK_WALKANIM#"_Aim");
DIR=ConvertDegrees(0);
TIME=self.time;
if((time >ACTION_TIME + 1) or (Moving_Success=false) or (GetEventState(EntityName # "_trig")=true))
{
RANDOM_ATTACK = 0;
}
SPEED=Integer(PLAYERSPEED);
ForceForward(1);
}
if((RANDOM_ATTACK > 3) and (RANDOM_ATTACK < 6))
{
ANC=13; // different anc values needed to blend again
AT=0.2;
ANIM=StringCopy(PISTOL_WALK_STRAFELEFT#"_Aim");
DIR=ConvertDegrees(90);
TIME=self.time;
if((time >ACTION_TIME + 1) or (Moving_Success=false) or (GetEventState(EntityName # "_trig")=true))
{
RANDOM_ATTACK = 0;
}
SPEED=Integer(PLAYERSPEED);
ForceForward(1);
}
if((RANDOM_ATTACK > 0) and (RANDOM_ATTACK <= 3))
{
ANC=14; // different anc values needed to blend again
AT=0.2;
ANIM=StringCopy(PISTOL_WALK_STRAFERIGHT#"_Aim");
DIR=ConvertDegrees(-90);
TIME=self.time;
if((time >ACTION_TIME + 1) or (Moving_Success=false) or (GetEventState(EntityName # "_trig")=true))
{
RANDOM_ATTACK = 0;
}
SPEED=Integer(PLAYERSPEED);
ForceForward(1);
}
SEARCH_TIME = RANDOM_ATTACK;
}

if(Melee = true)
{
SPEED=0;
TIME = time-0.3;
ANC = 87;
AT = 0.2;
ANIM=StringCopy(WALK_MELEE);
//AddExplosion("PMuzzleFlash","ValveBiped.Bip01_R_Hand",0,0,0);
//DamageAtBone(10, 50, "enemy_health", "ValveBiped.Bip01_R_Hand" );
if(time>TM+0.5) // weapon need some latency over the animation
{
SetEventState(EntityName # "_Melee_Exp", true);
}
if(self.animate_at_end)
{
Melee=false;
}
TM=time+0.3;
}
else
{
SetEventState(EntityName # "_Melee_Exp", false);
}



if(self.enemy_vis = false)
{
//self.ideal_yaw=GetYawToPoint();

if(time < ACTION_TIME + (SEARCH_TIME/4))
{
debug("F1");
if(SEARCH_NUMBER = 1)
{
SEARCH_NUMBER = 2;
}
TIME=time;
if(Moving_Success)
{
self.ideal_yaw= self.last_enemy_yaw;
}
else
{
//SEARCH_TIME = SEARCH_TIME * 0.9;
self.ideal_yaw = GetYawToPoint();
}
DIR=0;
SPEED = Integer(PLAYERSPEED);
ANIM=StringCopy(PISTOL_WALK_WALKANIM);
ForceForward(1);
AT=0.3;
ANC=645;
}
if((time > ACTION_TIME+ (SEARCH_TIME/4)) and (time < ACTION_TIME + ((SEARCH_TIME/4)*2)))
{
debug("F2");
TIME=time;
DIR=0;
SPEED =0;
ANIM=StringCopy(PISTOL_WALK_HOLD);
AT=0.3;
ANC=905;

}
if((time > ACTION_TIME + ((SEARCH_TIME/4)*2)) and (time < ACTION_TIME + ((SEARCH_TIME/4)*3)))
{
debug("F3a");
TIME=time;

ChangeYaw();
SPEED = Integer(PLAYERSPEED / 2);
if(Moving_Success = false)
{
self.ideal_yaw = self.last_enemy_yaw + ConvertDegrees(70);
ANIM=StringCopy(PISTOL_WALK_SW);
ANC=83;
DIR = ConvertDegrees(90);
}
else
{
self.ideal_yaw = self.last_enemy_yaw - ConvertDegrees(70);
ANIM=StringCopy(PISTOL_WALK_SE);
ANC=81;
DIR = ConvertDegrees(-90);
}
AT=0.2;

if(Integer(self.current_yaw/0.017) = Integer(self.ideal_yaw/0.017))
{
debug("F3b");
TIME=time;
DIR=0;
SPEED =0;
ANIM=StringCopy(PISTOL_WALK_HOLD);
AT=0.3;
ANC=655;
}
}
if((time > ACTION_TIME + ((SEARCH_TIME/4)*3)) and (time < ACTION_TIME + ((SEARCH_TIME))))
{
debug("F4a");
if(SEARCH_NUMBER = 0)
{
SEARCH_NUMBER = 1;
}
TIME=time;
ChangeYaw();
SPEED = Integer(PLAYERSPEED / 3);
if(Moving_Success = false)
{
self.ideal_yaw = self.last_enemy_yaw - ConvertDegrees(70);
ANIM=StringCopy(PISTOL_WALK_SW);
ANC=83;
DIR = ConvertDegrees(90);
}
else
{
self.ideal_yaw = self.last_enemy_yaw + ConvertDegrees(70);
ANIM=StringCopy(PISTOL_WALK_SE);
ANC=81;
DIR = ConvertDegrees(-90);
}
AT=0.2;

if(Integer(self.current_yaw/0.017) = Integer(self.ideal_yaw/0.017))
{
debug("F4b");
TIME=time;
DIR=0;
SPEED =0;
ANIM=StringCopy(PISTOL_WALK_HOLD);
AT=0.3;
ANC=65;
}
}
if(time > ACTION_TIME + ((SEARCH_TIME)))
{
debug("F5");

if(SEARCH_NUMBER < MAX_SEARCH_NUMBER)
{
SEARCH_TIME = time;
RANDOM_ATTACK = 0; // this resets the self.enemy_vis sequence
}

if(((self.point_vis = false) or (Moving_Success = false)) and (time > TIME +5))
{
NEXT_ORDER=self.order_name;
HighLevel("Lost_Target");
return 0;
}
if(self.point_vis)
{

TIME = time;
DIR=0;
SPEED = Integer(PLAYERSPEED);
ANIM=StringCopy(PISTOL_WALK_WALKANIM);
AT=0.3;
ANC=5;
}
}
}

if((GetDistanceTo("CAMERA")> HEAR_RANGE*1.5))
{
AnimateBlend(PISTOL_WALK_UNDRAW, 0.1);
ANIM=StringCopy(WALK_IDLEANIM);
NEXT_ORDER="Walk_NOWEAPON";
self.think="UnDraw_A_Weapon";
}


if(FastPointCheck(40))
{
NextPoint();
}

if(FIREOFFSET >0)
{
FIREOFFSET = FIREOFFSET -2;
}
SetRelBoneRotation(EntityName, "ValveBiped.Bip01_L_Forearm",FIREOFFSET/6,0,-FIREOFFSET/7);
SetRelBoneRotation(EntityName, "ValveBiped.Bip01_R_Forearm",FIREOFFSET/3,0,-FIREOFFSET);

if((Reload = true))
{
//back
TIME=time;
ANIM=StringCopy(PISTOL_WALK_RELOADANIM);
ANC=5;
AT=0.2;
SPEED=0;
if((self.animate_at_end))//and(time > TM))
{
Reload = false;
BULLET = 0;
ANC=0;
if(MAG > 0)
{
MAG = MAG -1;
}
}
}

if(SPEED != 0)
{
if(time > SOUND_TIME + 0.35)
{
SOUND_TIME = time;
PlaySound("footstep.wav");
}
ChangeYaw();
}

if((time > TIME +0.4))
{
DIR=0; // Default straight
//SPEED=0; //Default - no motion
AT=0.2; //Default
ANC=0; //Default
}

if((ANC < 1))
{
//no button
AT=0.3;
SPEED = 0;
ANIM=StringCopy(PISTOL_WALK_IDLEANIM);
}

//handle animations
if(Integer(LASTANC) != Integer(ANC))
{
AnimateBlend(ANIM,AT);
}
LASTANC=Integer(ANC);
if(self.animate_at_end)
{
AnimateHold(ANIM);
}
//handle motions
Moving_Success = walkmove(self.current_yaw+DIR, SPEED);

//handle health status

if(self.IsFalling)
{
FALLING_TIME = time;
if/*(FALLING_TIME > 1)*/(GetCollideDistance("ValveBiped.Bip01_R_Foot", 0,-50,0 ) = -1)
{
AnimateBlend(JUMPANIM_GLIDE, 0.7);
TIME= time;
LAST_ORDER = self.order_name;
self.think= "Jump";
}
}

debug(GetLastBoneHit());
}]






Walk_NOWEAPON[()
{
if(IsKeyDown(3))
{
HighLevel("Die");
return 0;
}
if(self.health < 1)
{

AddExplosion("BloodExplosion",GetLastBoneHit(),0,0,0);
SetTargetPoint(random(500,1000),70,random(500,1000));
FireProjectile("bloodbullet", "ValveBiped.Bip01_L_UpperArm",0,0,0,"none",0);
SetTargetPoint(random(-1000,-500),-100000000,random(-500,-1000));
FireProjectile("bloodbullet", "ValveBiped.Bip01_R_Foot",0,0,0,"none",0);
SetTargetPoint(random(-1000,-200),-50,random(1000,200));
FireProjectile("bloodbullet", "ValveBiped.Bip01_R_Forearm",0,0,0,"none",0);
PlaySound("Die1.wav");
SetEventState(EntityName # "_RagDollize_Me", true);
SetEventState("Show_RagDoll", true);
self.think="Pain_Order";
}

if(GetLastBoneHit() = "ValveBiped.Bip01_Head1")
{
HighLevel("Die");
return 0;
}

debug(self.enemy_vis);

if((self.enemy_vis) and (self.enemy_range < ENEMYRANGE))
{
PlaySound("Alert1.wav");
TM = time;
AnimateBlend(PISTOL_WALK_DRAW, 0.1);
ANIM=StringCopy(PISTOL_WALK_IDLEANIM);
NEXT_ORDER="Attack";
HighLevel("Die");
}

if(IsKeyDown(CAMERA.K_FIRE))
{
if((CAMERA.BULLET < 5) and (CAMERA.MAG >0) and (GetDistanceTo("CAMERA") < HEAR_RANGE) and (GetEntityAlpha("SMG")=255))
{
PlaySound("Alert1.wav");
TM = time;
AnimateBlend(PISTOL_WALK_DRAW, 0.1);
ANIM=StringCopy(PISTOL_WALK_IDLEANIM);
NEXT_ORDER="Attack";
self.think="FOUNDENEMY";
}
}
if(self.in_pain)
{
PlaySound("Alert1.wav");
UpdateEnemyVis();
TM = time;
AnimateBlend(PISTOL_WALK_DRAW, 0.1);
ANIM=StringCopy(PISTOL_WALK_IDLEANIM);
NEXT_ORDER="Attack";
self.think="FOUNDENEMY";
}

if(((IsKeyDown(CAMERA.K_FOR))or(IsKeyDown(CAMERA.K_BAK))or(IsKeyDown(CAMERA.K_LEFT))or(IsKeyDown(CAMERA.K_RIGHT))or(IsKeyDown(CAMERA.K_JUMP))) and (LeftCopy(CAMERA.order_name, 6) != "Crouch"))
{

if((GetDistanceTo("CAMERA") < HEAR_RANGE/2) and (IsKeyDown(CAMERA.K_RUN)))
{
PlaySound("Alert1.wav");
UpdateEnemyVis();
TM = time;
AnimateBlend(PISTOL_WALK_DRAW, 0.1);
ANIM=StringCopy(PISTOL_WALK_IDLEANIM);
NEXT_ORDER="Attack";
self.think="FOUNDENEMY";
}
if((GetDistanceTo("CAMERA") < HEAR_RANGE/4) and (IsKeyDown(CAMERA.K_RUN)=false))
{
PlaySound("Alert1.wav");
UpdateEnemyVis();
TM = time;
AnimateBlend(PISTOL_WALK_DRAW, 0.1);
ANIM=StringCopy(PISTOL_WALK_IDLEANIM);
NEXT_ORDER="Attack";
self.think="FOUNDENEMY";
}
}


if(LeftCopy(point_name,1) = "P")
{
if(WAIT_TIME = 0)
{
WAIT_TIME = random (2,5); // random is executed one time only
}
TIME = time;
Bot_State = "Walk";
}

if(LeftCopy(point_name,1) = "B")
{
WAIT_TIME = 12;
// stay a while in the walking direction
if(time < TIME+ (WAIT_TIME/3))
{
PREVIOUS_YAW = Integer(self.current_yaw/0.017);
Bot_State = "Stand";
}
// then look behind and stand
if((time > (TIME+ WAIT_TIME/3)) and (time < (TIME+ (WAIT_TIME/3)*2)))
{
Bot_State = "LookBehind";
self.ideal_yaw = ConvertDegrees(PREVIOUS_YAW - 180);
ChangeYaw();
ANIM=StringCopy(WALK_SE);
ANC=8;
AT=0.2;

if(Integer(self.current_yaw/0.017) = Integer(self.ideal_yaw/0.017))
{
Bot_State = "Stand";
SPEED = 0;
}
}
//then forward again
if((time > (TIME+ (WAIT_TIME/3)*2)) and (time < (TIME+ WAIT_TIME)))
{
Bot_State = "LookBehind";
self.ideal_yaw = ConvertDegrees(PREVIOUS_YAW);
ChangeYaw();
ANIM=StringCopy(WALK_SW);
ANC=8;
AT=0.2;

if(Integer(self.current_yaw/0.017) = Integer(self.ideal_yaw/0.017))
{
Bot_State = "Stand";
SPEED = 0;
}
}
// time is over
if(time > (TIME+ WAIT_TIME))
{
Bot_State = "Walk";
WAIT_TIME = 0;
}
}

if(LeftCopy(point_name,1) = "I")
{
if(time < TIME+ WAIT_TIME)
{
Bot_State = "Stand";
}
else
{
Bot_State = "Walk";
WAIT_TIME = 0;
}
}

debug(ANC);
if(Bot_State = "Walk")
{
DIR=0;
SPEED = Integer(PLAYERSPEED);
ANIM=StringCopy(WALK_WALKANIM);
AT=0.3;
ANC=5;
}

if((Bot_State = "Stand"))
{
SPEED = 0;
ANIM=StringCopy(WALK_HOLD);
ANC=0;
AT=0.2;
}

debug(Bot_State);
debug(ANIM);

DIR=0; // Default straight
AT=0.2; //Default
//ANC=0; //Default

if(ANC < 1)
{
//no button
ANIM=StringCopy(WALK_IDLEANIM);
AT=0.2;
}
//handle animations
if(Integer(LASTANC) != Integer(ANC))
{
AnimateBlend(ANIM,AT);
}
LASTANC=Integer(ANC);
if(self.animate_at_end)
{
AnimateHold(ANIM);
}

//handle motions
//AutoWalk(self.current_yaw+DIR, SPEED, 30);
Moving_Success = walkmove(self.ideal_yaw, SPEED);

if(Bot_State != "LookBehind")
{
if(Moving_Success)
{
self.ideal_yaw= GetYawToPoint();
SEARCH_TIME = time;
}
else
{
//SEARCH_TIME = SEARCH_TIME * 0.9;
if(self.last_enemy_yaw!=0)
{
self.ideal_yaw = self.last_enemy_yaw;
}
else
{
ForceBackward(30);
}
if(time > SEARCH_TIME + 5)
{
HighLevel("Find_a_Point");
return 0;
}
}
}

if(SPEED != 0)
{
if(time > SOUND_TIME + 0.35)
{
SOUND_TIME = time;
PlaySound("footstep.wav",100);
}
ChangeYaw();
}

if(FastPointCheck(40))
{
NextPoint();
}


if(self.IsFalling)
{
FALLING_TIME = time;
if(GetCollideDistance("ValveBiped.Bip01_R_Foot", 0,-50,0 ) = -1)
{
AnimateBlend(JUMPANIM_GLIDE, 0.3);
TIME= time;
LAST_ORDER = self.order_name;
self.think= "Jump";
}
}

}]

Jump[()
{
debug("fall "# GetCollideDistance("ValveBiped.Bip01_R_Foot", 0,-50,0 ));
debug("fall "# self.IsFalling);
walkmove(self.current_yaw+DIR,SPEED);

self.ideal_yaw = self.camera_yaw;
ChangeYaw();

if((self.IsFalling = false) or(IsKeyDown(9)))
{
AnimateBlend(JUMPANIM_LAND,0.1);
SPEED = 0;
self.think="AfterJump";
}

}]

AfterJump[()
{
if((self.animate_at_end))
{
ANC=0;
AnimateBlend(ANIM, 0.1);
self.think=LAST_ORDER;
}
}]

FOUNDENEMY[()
{
debug(found target now evaluating);
if(LeftCopy(self.target_name,1) = "1");
{
debug(found valid enemy target so draw weapon);
Lowlevel("Draw_A_weapon");
}
else
{
debug(bad target or allied return to walk no weapon);
self.think="Walk_NOWEAPON";
}
}]


Draw_A_Weapon[()
{
debug("draw a weapon");
if((RightCopy(self.target_name,1) = "1") or (LeftCopy(self.target_name,1) = "1"));
{
debug("drawing");
debug("NEXT_ORDER");
if((self.animate_at_end))
{
ANC=0;
LASTANC=0;
TM=time;
//TIME=time+0.4;
//self.think=NEXT_ORDER;
//AnimateBlend(ANIM, 0.2);
self.think="Step_Ahead";
return 0;
}
else
{
debug("canceling drawing");
self.think="Walk_NOWEAPON";
}
}]


Step_Ahead[()
{
if((self.animate_at_end))
//if(time > TIME +0.4)
{
ANC=0;
TM=time;
self.think=NEXT_ORDER;

//HighLevel("Find_a_Point");
return 0;
}
}]


UnDraw_A_Weapon[()
{
debug(NEXT_ORDER);
if((self.animate_at_end))
{
ANC=0;
LASTANC=0;
TM=time;
//TIME=time+0.4;
//self.think=NEXT_ORDER;
//AnimateBlend(ANIM, 0.2);
self.think="Step_Ahead";
return 0;
}
}]
Step_Behind[()
{
if((self.animate_at_end))
//if(time > TIME +0.4)
{
ANC=0;
TM=time;
//self.think=NEXT_ORDER;

HighLevel("Find_a_Point");
return 0;
}
}]
Find_a_Point[()
{
Delay(WALK_HOLD, 3, "" );
FindPointOrder("FoundPoint");
//FindTargetOrder(700, "Back_To_The_Battle", "health");
}]

FoundPoint[()
{
RotateToPoint(WALK_NE, 180, false, "footstep.wav" );
LowLevel("Walk_NOWEAPON");
return 0;
}]

Lost_Target[()
{
Delay(PISTOL_WALK_HOLD, 3, "" );
FindPointOrder("Back_To_The_Root");
//FindTargetOrder(700, "Back_To_The_Battle", "health");
}]

Back_To_The_Root[()
{
RotateToPoint(PISTOL_WALK_NE, 180, false, "footstep.wav" );
LowLevel("Attack");
return 0;
}]

Back_To_The_Battle[()
{

LowLevel("Attack");
return 0;
}]

Die[()
{
LowLevel("Pain_Order");
return 0;
}]

Pain_Order[()
{
PawnRender(false);
SetEventState(EntityName # "_Show_RagDoll", true);
SetEventState(EntityName # "_RagDollize_Me", false);


if(IsKeyDown(9))
{
SetEventState(EntityName # "_Show_RagDoll", false);
PawnRender(true);
self.think ="Attack";
}
}]

}

FOE

{
FIREAMMO [pistolbullet] // Projectile fired by pawn
FIREEFFECT [RocketExplosion] // muzzleflash effect
WEAPONMODEL [Laser] // Weapon held by pawn
FIRERATE [0.5] // Weapon firing rate
GROUP [robot] // Pawn Group - must be targetted by enemies
PLAYERSPEED [60] // Walk Speed
HEALTHATTRIB [health] // health attribute given to pawn
HEALTHAMOUNT [50] // amount of health given to pawn
DAMAGEATTRIB [health] // Atribute damaged by pawn
BOX [24] // Box width
FIREOFFSET [0]
FOV [130]
HEAR_RANGE [700]
ENEMYRANGE [800]
FALSE [false]
TRUE [true]

WALK_IDLEANIM [Idle_Walk] // Idle
WALK_WALKANIM [Walk_N] // Walk anim
WALK_BACKANIM [Walk_S] // walk back anim
WALK_STRAFELEFT [Walk_W] // Strafe left anim
WALK_STRAFERIGHT [Walk_E] // Strafe right anim
WALK_NE [Walk_NE] // Walk anim
WALK_SE [Walk_SE] // walk back anim
WALK_NW [Walk_NW] // Strafe left anim
WALK_SW [Walk_SW]
WALK_HOLD [Idle_Walk_Hold]
WALK_MELEE [Swing]
WALK_FIREAMMO [pistolbullet] // Projectile fired by pawn
WALK_FIREEFFECT [RocketExplosion] // muzzleflash effect
WALK_FIRERATE [0.5] // Weapon firing rate

C_WALK_IDLEANIM [Crouch_Idle_Hide] // Idle AnimationSpeed
C_WALK_SHOOTANIM [Shoot_SMG] // Shoot anim
C_WALK_WALKANIM [Crouch_Walk_N] // Walk anim
C_WALK_BACKANIM [Crouch_Walk_S] // walk back anim
C_WALK_STRAFELEFT [Crouch_Walk_W] // Strafe left anim
C_WALK_STRAFERIGHT [Crouch_Walk_E] // Strafe right anim
C_WALK_WALK_NE [Crouch_Walk_NE] // Walk anim
C_WALK_WALK_SE [Crouch_Walk_SE] // walk back anim
C_WALK_WALK_NW [Crouch_Walk_NW] // Strafe left anim
C_WALK_WALK_SW [Crouch_Walk_SW] // Strafe right anim

C_TO_WALK [Crouch_Idle_Hide_To_Stand]
WALK_TO_C [Stand_To_Crouch_Idle_Hide]

PISTOL_WALK_IDLEANIM [Pistol_Stand_Aim] // Idle AnimationSpeed
PISTOL_WALK_WALKANIM [Pistol_Walk_N] // Walk anim
PISTOL_WALK_BACKANIM [Pistol_Walk_S] // walk back anim
PISTOL_WALK_STRAFELEFT [Pistol_Walk_W] // Strafe left anim
PISTOL_WALK_STRAFERIGHT [Pistol_Walk_E] // Strafe right anim
PISTOL_WALK_NE [Pistol_Walk_NE_Aim] // Walk anim
PISTOL_WALK_SE [Pistol_Walk_SE] // walk back anim
PISTOL_WALK_NW [Pistol_Walk_NW_Aim] // Strafe left anim
PISTOL_WALK_SW [Pistol_Walk_SW_Aim]
PISTOL_WALK_HOLD [Pistol_Stand]
PISTOL_WALK_RELOADANIM [Pistol_Reload]
PISTOL_WALK_DRAW [Pistol_Draw]
PISTOL_WALK_UNDRAW [Pistol_UnDraw]
PISTOL_WALK_MELEE [Pistol_Melee]
PISTOL_FIREAMMO [pistolbullet] // Projectile fired by pawn
PISTOL_FIREEFFECT [RocketExplosion] // muzzleflash effect
PISTOL_FIRERATE [0.5] // Weapon firing rate

C_PISTOL_WALK_IDLEANIM [Pistol_Crouch_Stand_Aim] // Idle AnimationSpeed
C_PISTOL_WALK_WALKANIM [Pistol_Walk_Crouch_N] // Walk anim
C_PISTOL_WALK_BACKANIM [Pistol_Walk_Crouch_S] // walk back anim
C_PISTOL_WALK_STRAFELEFT [Pistol_Walk_Crouch_W] // Strafe left anim
C_PISTOL_WALK_STRAFERIGHT [Pistol_Walk_Crouch_E] // Strafe right anim
C_PISTOL_WALK_NE [Pistol_Walk_Crouch_NE_Aim] // Walk anim
C_PISTOL_WALK_SE [Pistol_Walk_Crouch_SE_Aim] // walk back anim
C_PISTOL_WALK_NW [Pistol_Walk_Crouch_NW_Aim] // Strafe left anim
C_PISTOL_WALK_SW [Pistol_Walk_Crouch_SW_Aim]
C_PISTOL_WALK_HOLD [Pistol_Crouch_Stand]
C_PISTOL_WALK_RELOADANIM [Pistol_Crouch_Reload]
C_PISTOL_WALK_DRAW [Pistol_Crouch_Draw]
C_PISTOL_WALK_UNDRAW [Pistol_Crouch_UnDraw]
C_PISTOL_WALK_MELEE [Pistol_Crouch_Melee]

PISTOL_C_TO_WALK [Pistol_Crouch_To_Pistol_Idle]
PISTOL_WALK_TO_C [Pistol_Idle_To_Pistol_Crouch]

JUMPANIM_JUMP [Jump_Run]
JUMPANIM_GLIDE [jump_glide]
JUMPANIM_LAND [jump_land]

INTERANIM [recon_strike] // Pawn interact anim
DEATHANIM [recon_die] // Death Anim
ROOTBONE [Bip01] // Pawn root bone
WEAPONHAND [ValveBiped.Bip01_R_Hand] // Pawn weapon bone

ANIM [string] // Do Not Edit
ANC [0] // Do Not Edit
LASTANC [0] // Do Not Edit
DIR [0] // Do Not Edit
AT [0.5] // Do Not Edit
INTER [string] // Do Not Edit
TM [0] // Do Not Edit
SPEED [0] //Do Not Edit
TIME [0]
SOUND_TIME [0]
ANIM_TIME [0]
ACTION_TIME [0]
SEARCH_TIME [0]
ATTACK_TIME [0]

SEARCH_NUMBER [0]
MAX_SEARCH_NUMBER [2] // how many time the pawn search the player
BACK_TO_PATROL [3]

MAG [300]
BULLET [0]
Reload [bool]
Hold [bool]
Melee[bool]
Run [bool]
Moving_Success [bool]
FALLING_TIME [0]
LAST_ORDER [string]
NEXT_ORDER [string]
ROTATION_ADD [0]
FIRE_PAUSE [2]
Patrol [bool]
WAIT_TIME [0]
Bot_State [string]
PREVIOUS_YAW [0]

ENEMYRANGE [700]
RANDOM_ATTACK [0]
X_CAMERA[0]

Spawn[()
{
SetFOV(FOV);
Console(true);
HostilePlayer(TRUE);
HostileDifferent(TRUE);
HostileSame(TRUE);
BoxWidth(BOX);
FindTargetOrder(ENEMYRANGE,FOUNDENEMY,DAMAGEATTRIB);
AttributeOrder(HEALTHATTRIB,HEALTHAMOUNT,"Die");
LowLevel("Setup");
}]

Setup[()
{
self.yaw_speed=270;
AnimationSpeed(1.2);
SetBoundingBox(WALK_IDLEANIM, BOX );
self.think="Walk_NOWEAPON";

}]

Attack[()
{

if(self.health < 1)
{

AddExplosion("BloodExplosion",GetLastBoneHit(),0,0,0);
SetTargetPoint(random(500,1000),70,random(500,1000));
FireProjectile("bloodbullet", "ValveBiped.Bip01_L_UpperArm",0,0,0,"none",0);
SetTargetPoint(random(-1000,-500),-100000000,random(-500,-1000));
FireProjectile("bloodbullet", "ValveBiped.Bip01_R_Foot",0,0,0,"none",0);
SetTargetPoint(random(-1000,-200),-50,random(1000,200));
FireProjectile("bloodbullet", "ValveBiped.Bip01_R_Forearm",0,0,0,"none",0);
PlaySound("Die1.wav");
SetEventState(EntityName # "_RagDollize_Me", true);
SetEventState("Show_RagDoll", true);
self.think="Pain_Order";
}

if(GetLastBoneHit() = "ValveBiped.Bip01_Head1")
{
PlaySound("Die1.wav");
SetEventState(EntityName # "_RagDollize_Me", true);
SetEventState("Show_RagDoll", true);
self.think="Pain_Order";
}
SetRelBoneRotation(EntityName, "ValveBiped.Bip01_Spine2",0,0,X_CAMERA);
SetRelBoneRotation(EntityName, "ValveBiped.Bip01_Spine1",0,0,X_CAMERA);

X_CAMERA = Integer((self.enemy_pitch / 0.017))/3;

if(X_CAMERA > 30)
{
X_CAMERA = 30;
}
if(X_CAMERA < -5)
{
X_CAMERA = -5;
}


if(self.in_pain)
{
PlaySound("Pain1.wav");
UpdateEnemyVis();
RANDOM_ATTACK = 0;
}
if((IsKeyDown(CAMERA.K_FIRE))and(GetDistanceTo("CAMERA") < HEAR_RANGE))
{
if((CAMERA.BULLET < 5) and (CAMERA.MAG >0) and (GetDistanceTo("CAMERA") < HEAR_RANGE) and (GetEntityAlpha("SMG")=255))
{
RANDOM_ATTACK = 0;
}
}
if(((IsKeyDown(CAMERA.K_FOR))or(IsKeyDown(CAMERA.K_BAK))or(IsKeyDown(CAMERA.K_LEFT))or(IsKeyDown(CAMERA.K_RIGHT))or(IsKeyDown(CAMERA.K_JUMP))) and (LeftCopy(CAMERA.order_name, 6) != "Crouch"))
{
if((GetDistanceTo("CAMERA") < HEAR_RANGE/2) and (IsKeyDown(CAMERA.K_RUN)))
{
UpdateEnemyVis();
RANDOM_ATTACK = 0;
}
if((GetDistanceTo("CAMERA") < HEAR_RANGE/4) and (IsKeyDown(CAMERA.K_RUN)=false))
{
UpdateEnemyVis();
RANDOM_ATTACK = 0;
}
}


debug(self.enemy_vis);


if((IsKeyDown(4)))
{
MAG = 2;
RANDOM_ATTACK = 0;
}


if((self.enemy_range < 200))
{

if(RANDOM_ATTACK = 0)
{
ACTION_TIME= time;
RANDOM_ATTACK = random(8,15);
}
}
if((self.enemy_range > 200))
{
if(RANDOM_ATTACK = 0)
{
ACTION_TIME= time;
RANDOM_ATTACK = random(1,15);
}
}
if((self.enemy_vis) and (Reload=false))
{

if(time > TIME + 0.2)
{
UpdateEnemyVis();
debug("I see you");
}
self.ideal_yaw=self.last_enemy_yaw;


if((RANDOM_ATTACK >= 10))
{
if((BULLET < 5))
{
if(time >ACTION_TIME + 1)
{
RANDOM_ATTACK = 0;
}
if((self.time > TM+PISTOL_FIRERATE) )
{
if(self.enemy_range < 60)
{
TM = time;
PlaySound("metal_reverse.wav");
Melee = true;
}
else
{
TM=self.time;
BULLET = BULLET + 1;
FireProjectileBlind(PISTOL_FIREAMMO,WEAPONHAND,0,0,0,"health", enemy_pitch);
AddExplosion("PMuzzleFlash","ValveBiped.Bip01_R_Hand",0,0,0);
FIREOFFSET = 20;
}
}
}
else
{
if((MAG > = 1))
{
RANDOM_ATTACK = 0;
TM=self.time;
PlaySound("Weapon/reload3.wav");
Reload = true;
}
if((MAG < 1) and (time > TM + PISTOL_FIRERATE))
{
RANDOM_ATTACK = 0;
if(self.enemy_range < 60)
{
TM = time;
PlaySound("metal_reverse.wav");
Melee = true;
}
else
{
RANDOM_ATTACK = 0;
TM=self.time;
PlaySound("pistol_empty.wav");
}
}
}
}
if((RANDOM_ATTACK >= 6) and (RANDOM_ATTACK < 10))
{
ANC=11; // different anc values needed to blend again
AT=0.2;
ANIM=StringCopy(PISTOL_WALK_WALKANIM#"_Aim");
DIR=ConvertDegrees(0);
TIME=self.time;
if((time >ACTION_TIME + 1) or (Moving_Success=false) or (GetEventState(EntityName # "_trig")=true))
{
RANDOM_ATTACK = 0;
}
SPEED=Integer(PLAYERSPEED);
ForceForward(1);
}
if((RANDOM_ATTACK > 3) and (RANDOM_ATTACK < 6))
{
ANC=13; // different anc values needed to blend again
AT=0.2;
ANIM=StringCopy(PISTOL_WALK_STRAFELEFT#"_Aim");
DIR=ConvertDegrees(90);
TIME=self.time;
if((time >ACTION_TIME + 1) or (Moving_Success=false) or (GetEventState(EntityName # "_trig")=true))
{
RANDOM_ATTACK = 0;
}
SPEED=Integer(PLAYERSPEED);
ForceForward(1);
}
if((RANDOM_ATTACK > 0) and (RANDOM_ATTACK <= 3))
{
ANC=14; // different anc values needed to blend again
AT=0.2;
ANIM=StringCopy(PISTOL_WALK_STRAFERIGHT#"_Aim");
DIR=ConvertDegrees(-90);
TIME=self.time;
if((time >ACTION_TIME + 1) or (Moving_Success=false) or (GetEventState(EntityName # "_trig")=true))
{
RANDOM_ATTACK = 0;
}
SPEED=Integer(PLAYERSPEED);
ForceForward(1);
}
SEARCH_TIME = RANDOM_ATTACK;
}

if(Melee = true)
{
SPEED=0;
TIME = time-0.3;
ANC = 87;
AT = 0.2;
ANIM=StringCopy(WALK_MELEE);
//AddExplosion("PMuzzleFlash","ValveBiped.Bip01_R_Hand",0,0,0);
//DamageAtBone(10, 50, "enemy_health", "ValveBiped.Bip01_R_Hand" );
if(time>TM+0.5) // weapon need some latency over the animation
{
SetEventState(EntityName # "_Melee_Exp", true);
}
if(self.animate_at_end)
{
Melee=false;
}
TM=time+0.3;
}
else
{
SetEventState(EntityName # "_Melee_Exp", false);
}



if(self.enemy_vis = false)
{
//self.ideal_yaw=GetYawToPoint();

if(time < ACTION_TIME + (SEARCH_TIME/4))
{
debug("F1");
if(SEARCH_NUMBER = 1)
{
SEARCH_NUMBER = 2;
}
TIME=time;
if(Moving_Success)
{
self.ideal_yaw= self.last_enemy_yaw;
}
else
{
//SEARCH_TIME = SEARCH_TIME * 0.9;
self.ideal_yaw = GetYawToPoint();
}
DIR=0;
SPEED = Integer(PLAYERSPEED);
ANIM=StringCopy(PISTOL_WALK_WALKANIM);
ForceForward(1);
AT=0.3;
ANC=645;
}
if((time > ACTION_TIME+ (SEARCH_TIME/4)) and (time < ACTION_TIME + ((SEARCH_TIME/4)*2)))
{
debug("F2");
TIME=time;
DIR=0;
SPEED =0;
ANIM=StringCopy(PISTOL_WALK_HOLD);
AT=0.3;
ANC=905;

}
if((time > ACTION_TIME + ((SEARCH_TIME/4)*2)) and (time < ACTION_TIME + ((SEARCH_TIME/4)*3)))
{
debug("F3a");
TIME=time;

ChangeYaw();
SPEED = Integer(PLAYERSPEED / 2);
if(Moving_Success = false)
{
self.ideal_yaw = self.last_enemy_yaw + ConvertDegrees(70);
ANIM=StringCopy(PISTOL_WALK_SW);
ANC=83;
DIR = ConvertDegrees(90);
}
else
{
self.ideal_yaw = self.last_enemy_yaw - ConvertDegrees(70);
ANIM=StringCopy(PISTOL_WALK_SE);
ANC=81;
DIR = ConvertDegrees(-90);
}
AT=0.2;

if(Integer(self.current_yaw/0.017) = Integer(self.ideal_yaw/0.017))
{
debug("F3b");
TIME=time;
DIR=0;
SPEED =0;
ANIM=StringCopy(PISTOL_WALK_HOLD);
AT=0.3;
ANC=655;
}
}
if((time > ACTION_TIME + ((SEARCH_TIME/4)*3)) and (time < ACTION_TIME + ((SEARCH_TIME))))
{
debug("F4a");
if(SEARCH_NUMBER = 0)
{
SEARCH_NUMBER = 1;
}
TIME=time;
ChangeYaw();
SPEED = Integer(PLAYERSPEED / 3);
if(Moving_Success = false)
{
self.ideal_yaw = self.last_enemy_yaw - ConvertDegrees(70);
ANIM=StringCopy(PISTOL_WALK_SW);
ANC=83;
DIR = ConvertDegrees(90);
}
else
{
self.ideal_yaw = self.last_enemy_yaw + ConvertDegrees(70);
ANIM=StringCopy(PISTOL_WALK_SE);
ANC=81;
DIR = ConvertDegrees(-90);
}
AT=0.2;

if(Integer(self.current_yaw/0.017) = Integer(self.ideal_yaw/0.017))
{
debug("F4b");
TIME=time;
DIR=0;
SPEED =0;
ANIM=StringCopy(PISTOL_WALK_HOLD);
AT=0.3;
ANC=65;
}
}
if(time > ACTION_TIME + ((SEARCH_TIME)))
{
debug("F5");

if(SEARCH_NUMBER < MAX_SEARCH_NUMBER)
{
SEARCH_TIME = time;
RANDOM_ATTACK = 0; // this resets the self.enemy_vis sequence
}

if(((self.point_vis = false) or (Moving_Success = false)) and (time > TIME +5))
{
NEXT_ORDER=self.order_name;
HighLevel("Lost_Target");
return 0;
}
if(self.point_vis)
{

TIME = time;
DIR=0;
SPEED = Integer(PLAYERSPEED);
ANIM=StringCopy(PISTOL_WALK_WALKANIM);
AT=0.3;
ANC=5;
}
}
}

if((GetDistanceTo("CAMERA")> HEAR_RANGE*1.5))
{
AnimateBlend(PISTOL_WALK_UNDRAW, 0.1);
ANIM=StringCopy(WALK_IDLEANIM);
NEXT_ORDER="Walk_NOWEAPON";
self.think="UnDraw_A_Weapon";
}


if(FastPointCheck(40))
{
NextPoint();
}

if(FIREOFFSET >0)
{
FIREOFFSET = FIREOFFSET -2;
}
SetRelBoneRotation(EntityName, "ValveBiped.Bip01_L_Forearm",FIREOFFSET/6,0,-FIREOFFSET/7);
SetRelBoneRotation(EntityName, "ValveBiped.Bip01_R_Forearm",FIREOFFSET/3,0,-FIREOFFSET);

if((Reload = true))
{
//back
TIME=time;
ANIM=StringCopy(PISTOL_WALK_RELOADANIM);
ANC=5;
AT=0.2;
SPEED=0;
if((self.animate_at_end))//and(time > TM))
{
Reload = false;
BULLET = 0;
ANC=0;
if(MAG > 0)
{
MAG = MAG -1;
}
}
}

if(SPEED != 0)
{
if(time > SOUND_TIME + 0.35)
{
SOUND_TIME = time;
PlaySound("footstep.wav");
}
ChangeYaw();
}

if((time > TIME +0.4))
{
DIR=0; // Default straight
//SPEED=0; //Default - no motion
AT=0.2; //Default
ANC=0; //Default
}

if((ANC < 1))
{
//no button
AT=0.3;
SPEED = 0;
ANIM=StringCopy(PISTOL_WALK_IDLEANIM);
}

//handle animations
if(Integer(LASTANC) != Integer(ANC))
{
AnimateBlend(ANIM,AT);
}
LASTANC=Integer(ANC);
if(self.animate_at_end)
{
AnimateHold(ANIM);
}
//handle motions
Moving_Success = walkmove(self.current_yaw+DIR, SPEED);

//handle health status

if(self.IsFalling)
{
FALLING_TIME = time;
if/*(FALLING_TIME > 1)*/(GetCollideDistance("ValveBiped.Bip01_R_Foot", 0,-50,0 ) = -1)
{
AnimateBlend(JUMPANIM_GLIDE, 0.7);
TIME= time;
LAST_ORDER = self.order_name;
self.think= "Jump";
}
}

debug(GetLastBoneHit());
}]






Walk_NOWEAPON[()
{
if(IsKeyDown(3))
{
HighLevel("Die");
return 0;
}
if(self.health < 1)
{

AddExplosion("BloodExplosion",GetLastBoneHit(),0,0,0);
SetTargetPoint(random(500,1000),70,random(500,1000));
FireProjectile("bloodbullet", "ValveBiped.Bip01_L_UpperArm",0,0,0,"none",0);
SetTargetPoint(random(-1000,-500),-100000000,random(-500,-1000));
FireProjectile("bloodbullet", "ValveBiped.Bip01_R_Foot",0,0,0,"none",0);
SetTargetPoint(random(-1000,-200),-50,random(1000,200));
FireProjectile("bloodbullet", "ValveBiped.Bip01_R_Forearm",0,0,0,"none",0);
PlaySound("Die1.wav");
SetEventState(EntityName # "_RagDollize_Me", true);
SetEventState("Show_RagDoll", true);
self.think="Pain_Order";
}

if(GetLastBoneHit() = "ValveBiped.Bip01_Head1")
{
HighLevel("Die");
return 0;
}

debug(self.enemy_vis);

if((self.enemy_vis) and (self.enemy_range < ENEMYRANGE))
{
PlaySound("Alert1.wav");
TM = time;
AnimateBlend(PISTOL_WALK_DRAW, 0.1);
ANIM=StringCopy(PISTOL_WALK_IDLEANIM);
NEXT_ORDER="Attack";
HighLevel("Die");
}

if(IsKeyDown(CAMERA.K_FIRE))
{
if((CAMERA.BULLET < 5) and (CAMERA.MAG >0) and (GetDistanceTo("CAMERA") < HEAR_RANGE) and (GetEntityAlpha("SMG")=255))
{
PlaySound("Alert1.wav");
TM = time;
AnimateBlend(PISTOL_WALK_DRAW, 0.1);
ANIM=StringCopy(PISTOL_WALK_IDLEANIM);
NEXT_ORDER="Attack";
self.think="FOUNDENEMY";
}
}
if(self.in_pain)
{
PlaySound("Alert1.wav");
UpdateEnemyVis();
TM = time;
AnimateBlend(PISTOL_WALK_DRAW, 0.1);
ANIM=StringCopy(PISTOL_WALK_IDLEANIM);
NEXT_ORDER="Attack";
self.think="FOUNDENEMY";
}

if(((IsKeyDown(CAMERA.K_FOR))or(IsKeyDown(CAMERA.K_BAK))or(IsKeyDown(CAMERA.K_LEFT))or(IsKeyDown(CAMERA.K_RIGHT))or(IsKeyDown(CAMERA.K_JUMP))) and (LeftCopy(CAMERA.order_name, 6) != "Crouch"))
{

if((GetDistanceTo("CAMERA") < HEAR_RANGE/2) and (IsKeyDown(CAMERA.K_RUN)))
{
PlaySound("Alert1.wav");
UpdateEnemyVis();
TM = time;
AnimateBlend(PISTOL_WALK_DRAW, 0.1);
ANIM=StringCopy(PISTOL_WALK_IDLEANIM);
NEXT_ORDER="Attack";
self.think="FOUNDENEMY";
}
if((GetDistanceTo("CAMERA") < HEAR_RANGE/4) and (IsKeyDown(CAMERA.K_RUN)=false))
{
PlaySound("Alert1.wav");
UpdateEnemyVis();
TM = time;
AnimateBlend(PISTOL_WALK_DRAW, 0.1);
ANIM=StringCopy(PISTOL_WALK_IDLEANIM);
NEXT_ORDER="Attack";
self.think="FOUNDENEMY";
}
}


if(LeftCopy(point_name,1) = "P")
{
if(WAIT_TIME = 0)
{
WAIT_TIME = random (2,5); // random is executed one time only
}
TIME = time;
Bot_State = "Walk";
}

if(LeftCopy(point_name,1) = "B")
{
WAIT_TIME = 12;
// stay a while in the walking direction
if(time < TIME+ (WAIT_TIME/3))
{
PREVIOUS_YAW = Integer(self.current_yaw/0.017);
Bot_State = "Stand";
}
// then look behind and stand
if((time > (TIME+ WAIT_TIME/3)) and (time < (TIME+ (WAIT_TIME/3)*2)))
{
Bot_State = "LookBehind";
self.ideal_yaw = ConvertDegrees(PREVIOUS_YAW - 180);
ChangeYaw();
ANIM=StringCopy(WALK_SE);
ANC=8;
AT=0.2;

if(Integer(self.current_yaw/0.017) = Integer(self.ideal_yaw/0.017))
{
Bot_State = "Stand";
SPEED = 0;
}
}
//then forward again
if((time > (TIME+ (WAIT_TIME/3)*2)) and (time < (TIME+ WAIT_TIME)))
{
Bot_State = "LookBehind";
self.ideal_yaw = ConvertDegrees(PREVIOUS_YAW);
ChangeYaw();
ANIM=StringCopy(WALK_SW);
ANC=8;
AT=0.2;

if(Integer(self.current_yaw/0.017) = Integer(self.ideal_yaw/0.017))
{
Bot_State = "Stand";
SPEED = 0;
}
}
// time is over
if(time > (TIME+ WAIT_TIME))
{
Bot_State = "Walk";
WAIT_TIME = 0;
}
}

if(LeftCopy(point_name,1) = "I")
{
if(time < TIME+ WAIT_TIME)
{
Bot_State = "Stand";
}
else
{
Bot_State = "Walk";
WAIT_TIME = 0;
}
}

debug(ANC);
if(Bot_State = "Walk")
{
DIR=0;
SPEED = Integer(PLAYERSPEED);
ANIM=StringCopy(WALK_WALKANIM);
AT=0.3;
ANC=5;
}

if((Bot_State = "Stand"))
{
SPEED = 0;
ANIM=StringCopy(WALK_HOLD);
ANC=0;
AT=0.2;
}

debug(Bot_State);
debug(ANIM);

DIR=0; // Default straight
AT=0.2; //Default
//ANC=0; //Default

if(ANC < 1)
{
//no button
ANIM=StringCopy(WALK_IDLEANIM);
AT=0.2;
}
//handle animations
if(Integer(LASTANC) != Integer(ANC))
{
AnimateBlend(ANIM,AT);
}
LASTANC=Integer(ANC);
if(self.animate_at_end)
{
AnimateHold(ANIM);
}

//handle motions
//AutoWalk(self.current_yaw+DIR, SPEED, 30);
Moving_Success = walkmove(self.ideal_yaw, SPEED);

if(Bot_State != "LookBehind")
{
if(Moving_Success)
{
self.ideal_yaw= GetYawToPoint();
SEARCH_TIME = time;
}
else
{
//SEARCH_TIME = SEARCH_TIME * 0.9;
if(self.last_enemy_yaw!=0)
{
self.ideal_yaw = self.last_enemy_yaw;
}
else
{
ForceBackward(30);
}
if(time > SEARCH_TIME + 5)
{
HighLevel("Find_a_Point");
return 0;
}
}
}

if(SPEED != 0)
{
if(time > SOUND_TIME + 0.35)
{
SOUND_TIME = time;
PlaySound("footstep.wav",100);
}
ChangeYaw();
}

if(FastPointCheck(40))
{
NextPoint();
}


if(self.IsFalling)
{
FALLING_TIME = time;
if(GetCollideDistance("ValveBiped.Bip01_R_Foot", 0,-50,0 ) = -1)
{
AnimateBlend(JUMPANIM_GLIDE, 0.3);
TIME= time;
LAST_ORDER = self.order_name;
self.think= "Jump";
}
}

}]

Jump[()
{
debug("fall "# GetCollideDistance("ValveBiped.Bip01_R_Foot", 0,-50,0 ));
debug("fall "# self.IsFalling);
walkmove(self.current_yaw+DIR,SPEED);

self.ideal_yaw = self.camera_yaw;
ChangeYaw();

if((self.IsFalling = false) or(IsKeyDown(9)))
{
AnimateBlend(JUMPANIM_LAND,0.1);
SPEED = 0;
self.think="AfterJump";
}

}]

AfterJump[()
{
if((self.animate_at_end))
{
ANC=0;
AnimateBlend(ANIM, 0.1);
self.think=LAST_ORDER;
}
}]

FOUNDENEMY[()
{
debug("found target now evaluating");
if(RightCopy(self.target_name,1) = "0");
{
debug("found valid enemy target so draw weapon");
Lowlevel("Draw_A_weapon");
}
else
{
debug("bad target or allied return to walk no weapon");
self.think="Walk_NOWEAPON";
}
}]


Draw_A_Weapon[()
{
debug("draw a weapon");
if(RightCopy(self.target_name,1) = "0");
{
debug("drawing");
debug("NEXT_ORDER");
if((self.animate_at_end))
{
ANC=0;
LASTANC=0;
TM=time;
//TIME=time+0.4;
//self.think=NEXT_ORDER;
//AnimateBlend(ANIM, 0.2);
self.think="Step_Ahead";
return 0;
}
else
{
debug("canceling drawing");
self.think="Walk_NOWEAPON";
}
}]


Step_Ahead[()
{
if((self.animate_at_end))
//if(time > TIME +0.4)
{
ANC=0;
TM=time;
self.think=NEXT_ORDER;

//HighLevel("Find_a_Point");
return 0;
}
}]


UnDraw_A_Weapon[()
{
debug(NEXT_ORDER);
if((self.animate_at_end))
{
ANC=0;
LASTANC=0;
TM=time;
//TIME=time+0.4;
//self.think=NEXT_ORDER;
//AnimateBlend(ANIM, 0.2);
self.think="Step_Ahead";
return 0;
}
}]
Step_Behind[()
{
if((self.animate_at_end))
//if(time > TIME +0.4)
{
ANC=0;
TM=time;
//self.think=NEXT_ORDER;

HighLevel("Find_a_Point");
return 0;
}
}]
Find_a_Point[()
{
Delay(WALK_HOLD,3,"");
FindPointOrder("FoundPoint");
//FindTargetOrder(700, "Back_To_The_Battle", "health");
}]

FoundPoint[()
{
RotateToPoint(WALK_NE, 180, false, "footstep.wav" );
LowLevel("Walk_NOWEAPON");
return 0;
}]

Lost_Target[()
{
Delay(PISTOL_WALK_HOLD,3,"");
FindPointOrder("Back_To_The_Root");
//FindTargetOrder(700, "Back_To_The_Battle", "health");
}]

Back_To_The_Root[()
{
RotateToPoint(PISTOL_WALK_NE, 180, false, "footstep.wav" );
LowLevel("Attack");
return 0;
}]

Back_To_The_Battle[()
{

LowLevel("Attack");
return 0;
}]

Die[()
{
LowLevel("Pain_Order");
return 0;
}]

Pain_Order[()
{
PawnRender(false);
SetEventState(EntityName # "_Show_RagDoll", true);
SetEventState(EntityName # "_RagDollize_Me", false);


if(IsKeyDown(9))
{
SetEventState(EntityName # "_Show_RagDoll", false);
PawnRender(true);
self.think ="Attack";
}
}]

}
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Post by Juutis »

I think the problem is that the script goes to low level immediately in the beginning. You see, the pawn must be in a high level part in order to acquire a target with the FindTargetOrder() command.
You could fix this by using high level orders until the pawn finds a target, or create some sort of system in low level that somehow scans for pawns and targets them. I haven't been doing much enemy scripting so I can't tell anything more detailed. :(
Pain is only psychological.
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico »

First things first.

if the parameter FOUNDENEMY is the name of an Order, then it should be inside brackets "".
So it should be:
FindTargetOrder(ENEMYRANGE,"FOUNDENEMY",DAMAGEATTRIB);

Could this change something?
shadow
Posts: 81
Joined: Mon Jul 25, 2005 5:37 am

Post by shadow »

There also seems to be mixing of high level and low level commands.

I would strongly suggest going back to the "Working script", make one or two changes to the script and then test it in a game.
If you get your desired results then continue with more changes. If not then its should be fairly easy to pinpoint the problem.

Making lots of changes through out a script can be a major pain when it doesn't work and try to find the error!

Hope that helps
User avatar
fps
Posts: 504
Joined: Mon Sep 26, 2005 9:54 pm
Location: in a magical land devoid of hope, happiness, and sanity.

Post by fps »

The problem with that shadow is that i am doing that and i never get results that work.
Just about every time I try to edit a script, the first thing i change (no matter what it is that i try) messes up. :roll:
I havent done very much to fredricos script at all but it seems that the first step in making it do what i want it to do is going to be that hardest.

If the script can truly only check for targets with the FindTargetOrder() command while in a high leevel function then i will need to find a kind of low level solution to the problem.

Does anyone have any idea of how i would do somthing like this?

I have one idea. I could make a seccond pawn that acts as a highlevel pair of eyes for the pawn.
I would just need the eyes to communicate with the pawn somehow.
I would also need the eyes pawn to keep the rotation of the enemy pawn but i dont think that that will be very hard.
I will just need a pair of eyes for each pawn.

This way the pawns can continue following paths and stuff with out jumping between high and low level to often.


eyes would search in high level for a target, when one is spotted it would need to make the enemy pawn return to a SetTarget command and return the szEntName of the targeted pawn as its value.

Also I can give it its own health and pain commands for use with flashbangs and blindness.

I think that this option would allow for the most flexibility but if anyone else knows of a better option I would be glad to hear about it.

Thanks,
Fps
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico »

no, fps, this isn't a good idea. You should keep the entities number as little as possible.
The point is to make the script work in the right way. So you should follow this general rules: Test it step-by-step using the debug.
Why should you use a second script te same thing you could do with the first?

I've quite understood what is your goal with this script modification but it isn't clear what is the error you get. You say the pawns don't target themselves each other but this doesn't mean nothing more than "it doesn't work!". :wink:
Do you get a script error?If not, what does mean that they don't "see" the other pawns (they are following correctly a path? At what distance are they from each other?) Does instead the script remains highlevel? If yes in what Order? Do they have to target only the player (as in your previous post) or do they have to target every foe they see?
Please be more precie. If you don't know at what distance your pawns are please debug it using debug(DistanceTo(szEntityname));
A last tip. To get the target commands work correctly always debug the self.enemy_vis also with the console turned off. So in every lowlevel script insert debug(enemy_vis);
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Post by Juutis »

As I said:
I think the problem is that the script goes to low level immediately in the beginning. You see, the pawn must be in a high level part in order to acquire a target with the FindTargetOrder() command.
I can't find ANY other command that refers to acquiring a target than the FindTargetOrder(), which doesn't work in low level. If I'm not COMPLETELY lost here, this is the reason.

***EDIT***
And yeah, fps. Your idea to make two seperate pawns would probably work, but as federico said, you should try to keep the entity count to a minimum. I would consider it as a last option, if there isn't any way to make it with just one pawn.
Pain is only psychological.
Post Reply