targeting question.

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.

targeting question.

Post by fps »

How do I target a pawn by its group type, then return the current targets ent name and visa versa?
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Post by Juutis »

If I got you right, I guess you could save the 'current target' to a variable, and then change the pawn's 'target group' with TargetGroup() command and use FindTargetOrder() to target the new pawn. You could then go back to the first target with SetTarget() command, using the variable containing the first target's name.
Pain is only psychological.
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 »

I dont know how to save to varriables.
How do you save to varriables?
What kind values can be saved to varriables?
How do I recall stored varriables?

Just so you know what i am trying to do,

The pawn searches for an enemy with a certian health attribute that is >0.
Once the pawn finds the target it returns its group name.
If groupname = foe store ent name then store goto an attacking order.
If groupname = friendly then ingore

Attacking order: Attack pawn with stored ent name, check distance to target w/ ent name check targets health. if lost target search for new target.

also i want this pawn to tatrget the player.
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Post by Juutis »

Ah, then you just need to add these to the script. Preferably to the spawn order, or some other setup order.

Code: Select all

HostilePlayer(true);
HostileDifferent(true);
TargetGroup("foe");
Now when you use the FindTargetOrder() command it will automatically ignore all pawns that are not in the group called "foe". In other words it can only target the player or pawns that belong to group "foe".
Pain is only psychological.
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 »

I was trying to use the script that came with the physics demo because its so good but the pawn can only attack or die if the ent in the SetTarget command is within hear_range and that (Target) is a scripted player that I don't plan on using. If the target ent gets too far away the script jumps from drawing its weapon to holstering it. Thats why i need to return the targets ent name.
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Post by Juutis »

Ohh, sorry! I've totally forgotten about this topic!

Could you upload the script?
Then I could take a look at how it's written and try to come up with a solution.
Pain is only psychological.
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 »

{
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 [enemy_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]

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(false);
BoxWidth(BOX);
AttributeOrder(HEALTHATTRIB,HEALTHAMOUNT,"Die");
LowLevel("Setup");
}]

Setup[()
{
SetTarget("CAMERA");
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";
self.think="Draw_A_Weapon";
}

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="Draw_A_Weapon";
}
}
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="Draw_A_Weapon";
}

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="Draw_A_Weapon";
}
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="Draw_A_Weapon";
}
}


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;
}
}]

Draw_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_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 »

First things first.
I dont know how to save to varriables.
How do you save to varriables?
What kind values can be saved to varriables?
How do I recall stored varriables?
All those things in the start of the script are variables. Like 'FIREAMMO', 'FIREEFFECT' etc..
Variables can be anything, almost. Strings, integers, floats...
You can define a variable and save a starting value to it in the start of a script. Just like in that script of yours.
You can change variables in the script like this: VARIABLE = VALUE. It saves a new value to the variable.
You have probably used these things already but haven't just known that they are 'variables'.

But I don't think you need to save the target's name.
Wouldn't it work if you named the pawns 'enemy1_1', 'enemy2_1', 'friend1_2' etc... the last number in the name would be the "group" they belong in. Enemys would be in group 1 and friends in 2. Then you could check in which group they are, just by checking the last digit of the name.

Code: Select all

if(RightCopy(self.target_name,1) = "1")
{
     //attack
}
else
{
     //start searching for other targets
}

However, the problem with that script is that it can only have an entity called 'CAMERA' as target.
You need to make the pawn look for other pawns around it if you want this to work. And I don't know how to do that... :(


I'm sorry if I confused you, right now I'm a bit confused myself too.
Pain is only psychological.
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 »

you are right i just didnt know how to save new values to varriable in the script.
I think I can use a search for health attribute command or somthing cant I?
Thanks,
fps
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico »

wow, really did I write all that things? :D

ok. If I correcly understood the first problem is to have the enemies targetting the "real" player instead of the player_pawn. In the Setup Order
there is the SetTarget("CAMERA"); command. Change it with TargetPlayer();
Please check if the command is repeated in the remaining part of the script and eventually replace it.
Now your enemies will target your player. About the hear_range I didn't understand the problem.
I hope this 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 »

Ive tryed the TargetPlayer(); command before but the pawns just ignored the player.
Besides i want the pawn to target many pawns and the player.
The problem with the hear distance being set to the distance from "camera" is that if the pawn is attacking somthing besides the camera, when it goes to draw its weapon it checks the distance from camera and if camera is too far away it says to holster the weapon before attacking.
I want it to...
find a target.
and if said target moves out of range.
and their are no other targets within a search area while the pawn is. checking and searching for about 10 secconds.
then holster the weapon and continue following paths or what not while still searching for a new target.

I am going to try that if(RightCopy(self.target_name,1) = "1") attack thing out when i have time,

Otherwise your script is very advanced and impressive, i am just having trouble modifying it with my limited successful scripting experience.

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

Post by federico »

sorry I didn't understand at first.
It can't be so hard to change so I will try to help you asap.
:wink:
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico »

Code: Select all

 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;
}
} 
the problem shoud be here.
First delete all the CAMERA. calls and instead add to the variables the keys you use with the player. they should be these accordingly to his page (viewtopic.php?t=282&highlight=scancodes)

Code: Select all

K_FOR [15] //w
K_BAK [27] //s
K_LEFT [26] //a
K_RIGHT [28] //d
K_FIRE [72] //should be the left mouse button
K_RUN [36] //left shift
K_JUMP [46] //space
instead I really don't know how to simulate the enemy hearing tracking id the player fail to shoot (ammo finished or fake firing for reloading). It was (CAMERA.BULLET < 5) and (CAMERA.MAG >0) and for now we can just delete it thinking to an alternative.
Next we need to replace the GetDistancetTo commands.
So this part of the script should change this way.

Warning!! I'm at work I can't test it!

Code: Select all

if(self.in_pain)
{
PlaySound("Pain1.wav");
UpdateEnemyVis();
RANDOM_ATTACK = 0;
}
if((IsKeyDown(K_FIRE))and(self.player_range   < HEAR_RANGE))
{
if((BULLET < 5) and (MAG >0) and (GetDistanceTo("CAMERA") < HEAR_RANGE) and (GetEntityAlpha("SMG")=255))
{
RANDOM_ATTACK = 0;
}
}
if(((IsKeyDown(K_FOR))or(IsKeyDown(K_BAK))or(IsKeyDown(K_LEFT))or(IsKeyDown(K_RIGHT))or(IsKeyDown(K_JUMP))))
{
if((self.player_range   < HEAR_RANGE/2) and (IsKeyDown(K_RUN)))
{
UpdateEnemyVis();
RANDOM_ATTACK = 0;
}
if((self.player_range   < HEAR_RANGE/4) and (IsKeyDown(K_RUN)=false))
{
UpdateEnemyVis();
RANDOM_ATTACK = 0;
}
}
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 »

what if instead of having the pawn track the player, we used a pawn attached to the player, this would make it easier to do that if(RightCopy(self.target_name,1) = "1") attack thing (so we could target many enemies), and we could keep track of running, jumping, crouching, noises ect...
Heck i really always wanted to use that partial scripted player that worked like that theif 2 game. I still have those scripts stored somewere. all i would want to do to modify that is have an available switch between 1st and 3rd person.

If I wanted to get really tricky i could have a scripted object int the level that kept track of all the ammos for the selected weapon slots and use If(keypress=fire and currentweaponCLIPammo=0) then goto "hear shot",
we could even keep track of if the player has his flashlight on, and such other things that would alert enemies to the players position.

what do you think about that?
Post Reply