Really Need HELP - Respawn

Topics regarding Scripting with Reality Factory
Post Reply
User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Really Need HELP - Respawn

Post by metal_head » Tue Apr 01, 2008 1:02 pm

http://www.realityfactory.info/forum/vi ... sc&start=0

I Really need to do this ( The pawn respawns when gets killed )
I made a Script Point and in the pawn's script I made the Death order look like this :

Code: Select all

Death[()
	{
		DelTimerOrder(1);					// remove alert timer
		AddPainOrder("PainToAlert", 0);				// remove pain order
		FindTargetOrder(0, "FoundTarget", DAMAGEATTRIBUTE);	// remove target finding
		DelTriggerOrder("IdleToAlert");				// remove alert trigger
            
		SetNoCollision();					// remove bounding box so there are no collisions with corpse
		AnimateStop(DIE, DIEHOLD, "");		
		FadeOut(DIEFADE, 0);
                TeleportEntity(self.EntityName, spawn_point); 
                SetAttribute("enemy_health",100); 
                HighLevel("Spawn"); 
                Remove(false);
The pawn dies and fades out,but doesn't respawn :(

User avatar
creekmonkey
Posts: 116
Joined: Tue Oct 23, 2007 2:55 pm

Re: Really Need HELP - Respawn

Post by creekmonkey » Tue Apr 01, 2008 3:47 pm

I use a switch statement to re-spawn to random script points after the fadeout command.

Try this after fadeout order


/////////////
switch(random(1,4)) // chose random script point to re-spawn to
{
case 1
{
TeleportToPoint("p2",0,0,0);
NewPoint("p2");
RotateToAlign("idle",500,false,"");
}
case 2
{
TeleportToPoint("p5",0,0,0);
NewPoint("p5");
RotateToAlign("idle",500,false,"");
}
case 3
{
TeleportToPoint("p11",0,0,0);
NewPoint("p11");
RotateToAlign("idle",500,false,"");
}
case 4
{
TeleportToPoint("p7",0,0,0);
NewPoint("p7");
RotateToAlign("idle",500,false,"");
}

}





FadeIn(DIEFADE,255);
AttributeOrder("enemy_health",100, "Death");
NewOrder("LostTarget");

}

User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Really Need HELP - Respawn

Post by metal_head » Tue Apr 01, 2008 5:23 pm

THANKS they now respawn,but when they respawn they can't walk they start shaking and thats all.When I go near them,they start shooting at me,but they cant walk they only shake...strange

Here's my death oreder:

Code: Select all

Death[()
	{
		DelTimerOrder(1);					// remove alert 

timer
		AddPainOrder("PainToAlert", 0);				// remove pain 

order
		FindTargetOrder(0, "FoundTarget", DAMAGEATTRIBUTE);	// remove target 

finding
		DelTriggerOrder("IdleToAlert");				// remove alert 

trigger
            
		SetNoCollision();					// remove bounding 

box so there are no collisions with corpse
		AnimateStop(DIE, DIEHOLD, "");		
		FadeOut(DIEFADE, 0);
                switch(random(1,4)) // chose random script point to re-spawn to
{
case 1
{
TeleportToPoint("p2",0,0,0);
NewPoint("p2");
RotateToAlign("idle",500,false,"");
}
case 2
{
TeleportToPoint("p5",0,0,0);
NewPoint("p5");
RotateToAlign("idle",500,false,"");
}
case 3
{
TeleportToPoint("p11",0,0,0);
NewPoint("p11");
RotateToAlign("idle",500,false,"");
}
case 4
{
TeleportToPoint("p7",0,0,0);
NewPoint("p7");
RotateToAlign("idle",500,false,"");
}

}





FadeIn(DIEFADE,255);
AttributeOrder("enemy_health",100, "Death");
NewOrder("LostTarget");

}
I deleted the

Code: Select all

Remove(true);

User avatar
darksmaster923
Posts: 1857
Joined: Wed Jan 03, 2007 10:32 pm
Location: Huntington Beach, California, USA
Contact:

Re: Really Need HELP - Respawn

Post by darksmaster923 » Wed Apr 02, 2008 1:09 am

what do you mean shake?
Herp derp.

User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Really Need HELP - Respawn

Post by metal_head » Wed Apr 02, 2008 1:03 pm

They play the run animation,but they dont move instead they some sort of shake

User avatar
darksmaster923
Posts: 1857
Joined: Wed Jan 03, 2007 10:32 pm
Location: Huntington Beach, California, USA
Contact:

Re: Really Need HELP - Respawn

Post by darksmaster923 » Thu Apr 03, 2008 1:29 am

i remember i had that problem. i fixed it but i forgot how. sorry.
Herp derp.

User avatar
creekmonkey
Posts: 116
Joined: Tue Oct 23, 2007 2:55 pm

Re: Really Need HELP - Respawn

Post by creekmonkey » Thu Apr 03, 2008 4:03 am

I am experienceing some problems problems with re-spawning in a level im building.

The pawns will re-spawn either in the ceiling or in the floor, but not always.

Also after re-spawning they will sometimes not die after being shot, unless the player moves close to them and then they just fall dead.

Also they will sometimes die automatically if the player is in the field of view of their new spawn point.

any suggestions?

User avatar
bernie
RF Moderator
Posts: 1249
Joined: Tue Nov 15, 2005 10:07 am
Location: Ireland

Re: Really Need HELP - Respawn

Post by bernie » Thu Apr 03, 2008 11:58 am

Creekmonkey...
Here is a perfectai script I modifed so that a pawn was made unconcious for a few seconds if he was clubbed with a cosh and respawns when he comes round. If he is struck with any other weapon he is killed. If you look through it you will see how I did the respawn. This script works ok for me no problems. Hope this helps you.



{
// Perfect AI
// by Peter Coleman
// Modified by Bernard Parkin 2006
// monster will fire missiles or melee if close enough
// Changes to ai-run and Check-Any-Attack

MAXPOINTS [7] //Number of Scriptpoints in level for this pawn
SCALE [1] // scale of actor
GROUP [soldier] // name of monster group
BOXWIDTH [25] // width and depth of bounding box
HOSTILEPLAYER [true] // hostile to player
HOSTILEDIFFERENT [false] // hostile to different Pawn group
HOSTILESAME [false] // hostile to same Pawn group
HEALTHATTRIBUTE [health] // name of health attribute
CONATTRIBUTE [conciousness]
CON [10]
HEALTH [50] // initial amount of health
SIGHTDIST [200] // max distance monster can see at idle
ALERTSIGHTDIST [150] // max distance monster can see when alert
FOV [160] // field of view in degrees
ATTACKFOV [360] // attacking field of view
YAWSPEED [360] // speed of rotation in deg/sec
DAMAGEATTRIBUTE [health] // attribute damaged by attack
ALERTTRIGGER [AlertG] // name of alert trigger

// define the type of monster this will be

ATTACKTYPE [melee] // type of attack - melee or missile
PATROL [true] // false - ambush or true - patrol
PC [0] // make any visible point the next point

// idling and turning

STAND [Idle] // idle animation
TURNL [Idle] // turn left animation
TURNR [Idle] // turn right animation

// when in pain

PAIN [Injury] // pain animations
PAIN1 [Injury]
PAIN2 [Injury]
PAIN3 [Injury]
PAINPERCENT [50] // percentage of time pain is shown
PAINSOUND [pl_pain2.wav] // sounds played when in pain
PAINSOUND1 [injury1.wav]
PAINSOUND2 [injury1.wav]
PAINSOUND3 [injury1.wav]

// when dying

DIE [Die] // dying animations
DIE1 [Die]
DIE2 [Die]
DIE3 [Die]
DIEHOLD [false] // time corpse still appears
DIEFADE [false] // fadeout time of corpse
DIESOUND [deathyell.wav] // sounds played when dying
DIESOUND1 [die1.wav]
DIESOUND2 [die1.wav]
DIESOUND3 [deathyell.wav]

// when running to attack

RUN [Run] // running animation
RUNSPEED [200] // average run speed
RUNSOUNDDELAY [2] // delay between making sounds when running to attack
RUNSOUND [breath.wav] // sound played while running to attack

// when walking while patroling

WALK [Walk] // walking animation
WALKSPEED [100] // average walking speed
WALKSOUND [breath.wav] // walking sound

// the projectile attack mode

MISSILEATTACK [Run]//[crouch_shoot_xm4_blend1] // missile attacking animations
MISSILEATTACK1 [Run]//[ref_shoot_xm4_blend1]
MISSILEATTACK2 [Run]//[crouch_shoot_xm4_blend1]
SHOOTUP [Run]//[ref_shoot_xm4_blend2]
SHOOTDOWN [Run]//[ref_shoot_xm4_blend1]
FIREDELAY [0.3] // delay after animation starts before projectile launch
FIREDELAY1 [0.3]
FIREDELAY2 [0.3]
MISSILESOUND [shoot1.wav] // sounds played when shooting
MISSILESOUND1 [shoot1.wav]
MISSILESOUND2 [shoot1.wav]
MISSILERANGE [1]//[700] // max distance to start missile attack
PROJECTILE [PlasmaBullet] // projectile name
FIREBONE [Bip01 R Finger1] // projectile launch bone
OFFSETX [0] // launch offsets
OFFSETY [0]
OFFSETZ [0]
ATTACKDELAY [0.3] // time between shots
SKILL [5] // skill level 1 to 10

// the melee attack mode

MELEEATTACK [Punch] // melee attacking animations
MELEEATTACK1 [Slash1]
MELEEATTACK2 [Slash2]
MELEESOUND [uuh.wav] // sounds played when melee attacking
MELEESOUND1 [uuh.wav]
MELEESOUND2 [uuh.wav]
MELEERANGE [35] // max distance to start melee attack
//MAXMELEERANGE [100] // max distance for melee mode
MINMELEEDAMAGE [10] // minimum amount of damage per melee attack
MAXMELEEDAMAGE [10] // maximum amount of damage per melee attack
MELEEDELAY [2] // number of seconds between melee damages
MELEEDAMAGESOUND [melee2.wav] // sound played when damage is done

// search for enemy

LOSTTIME [10] // time to search for enemy before giving up
POINTRADIUS [20] // radius from point when considered there

// obstacle avoidance forces for jumping

FORCEUP [65] // obstacle avoidance jump speed
FORCEFORWARD [20] // obstacle avoidance forward speed
FORCESIDE [20] // obstacle avoidance sideways speed

// local variables - do not change


RUNFUNC [monster_run_start] // monster run to attack function
MISSILEFUNC [monster_missile_start] // monster missile function
MELEEFUNC [monster_melee_start] // monster melee function
LOSTFUNC [monster_lost_target_start] // monster lost target function

AS_NONE [0]
AS_MELEE [1]
AS_MISSILE [2]
AS_STRAIGHT [3]
attack_delay [0]
melee_time [0]
lost_time [0]
back_up [false]
back_time [0]
left_time [0]
back_flag [false]
fire_delay [0]
skill_time [0]
attack_state [0]
run_sound_time [0]
missile_sound [NULL]
door_check [TRUE] // always check first to see if obstacle is a door
LENGTH [0] //Length of time to delay at script point do not change -- is set elsewhere

// spawn pawn and do setup work

Spawn[ ()
{
Console(true); // false = console off
Scale(SCALE); // scale the actor
if(BOXWIDTH > 0)
{
BoxWidth(BOXWIDTH*SCALE); // set bounding box width/depth
}
AttributeOrder(HEALTHATTRIBUTE, HEALTH, "Death"); // give monster health
HostilePlayer(HOSTILEPLAYER); // set who monster is hostile to
HostileSame(HOSTILESAME);
HostileDifferent(HOSTILEDIFFERENT);
SetFOV(160,"Bip01 Head"); // set field of view
SetGroup(GROUP); // assign a group to belong to
FindTargetOrder(SIGHTDIST, "FoundTarget", DAMAGEATTRIBUTE); // seen a target to chase
AddPainOrder("IdlePain", 100); // show pain and trigger alert
AvoidOrder("Avoidance"); // avoid obstacles
AddTriggerOrder("IdleToAlert", ALERTTRIGGER, 0); // go to alert when triggered
//SetWeapon("Sword"); // give the monster a big gun
RotateToPoint(STAND, YAWSPEED, false, ""); // go to point if any specified
MoveToPoint(WALK, WALKSPEED*SCALE, WALKSOUND);
if(PATROL = true)
{
NewOrder("Patrol");
}
else
{
NewOrder("Idle");
}
} ]

// avoid objects when doing a MoveToPoint

Avoidance[ ()
{

if(door_check=true)
{
MoveBackward(WALK, WALKSPEED*SCALE, (WALKSPEED/2)*SCALE, ""); // if it's a door try again
door_check=false; // if it wasn't a door try other ways
Return();
}
if(random(1,10)<3) // backup and move sideways sometimes
{
MoveBackward(WALK, WALKSPEED*SCALE, (WALKSPEED/2)*SCALE, "");
MoveRight(WALK, WALKSPEED*SCALE, (WALKSPEED/2)*SCALE, "");
}
else
{
Jump(RUN, FORCEUP*SCALE, true, "");
if(random(1,10)<6)
{
Move("", FORCEFORWARD*SCALE, (FORCEFORWARD/2)*SCALE, 0, 90, 0, "");
}
else
{
Move("", FORCEFORWARD*SCALE, (FORCEFORWARD/2)*SCALE, 0, -90, 0, "");
}
}
Return();
} ]

// idle in place waiting for something to happen

Idle[ ()
{
PlayAnimation(STAND, true, "");
RestartOrder();
} ]



// walk the beat from point to point

Patrol[ ()
{
SetFOV(FOV,"Bip01 Head"); // set field of view
NextPoint();

LENGTH=random(5,10); // Set delay time between 5 and 10 secs

if(self.point_name="CStart2")
{

Delay("Idle",LENGTH,""); // Wait at CStart for BETWEEN 5 & 10 secs

}

LENGTH=random(5,10); // Set delay time between 5 and 10 secs

if(self.point_name="Cspc3")
{

Delay("Idle",LENGTH,""); // Wait at Cspc3 BETWEEN 5 & 10 secs

}
RotateMoveToPoint(WALK, YAWSPEED, WALKSPEED*SCALE, false, WALKSOUND);
MoveToPoint(WALK, WALKSPEED*SCALE, WALKSOUND);
door_check=true; // ready to check for doors again
RestartOrder();
//}

} ]

// show pain at idle then trigger to alert

IdlePain[ ()
{

NewOrder("FoundTarget");
} ]

// start shifting from idle to alert

IdleToAlert[ ()
{
NewOrder("FoundTarget");
} ]

// look around at alert looking for enemy

Alert[ ()
{
NewOrder("FoundTarget");
} ]

// show pain at alert

AlertPain[ ()
{
NewOrder("FoundTarget");
} ]

// timed out at alert

AlertToIdle[ ()
{
NewOrder("FoundTarget");
} ]

// found a target to attack

FoundTarget[ ()
{
SetFOV(360,"Bip01 Head"); // set field of view
LowLevel(RUNFUNC); // attack functions are low level
} ]

// lost target while attacking so go back to idle again

LostTarget[ ()
{
SetFOV(FOV,"Bip01 Head"); // set field of view
FindTargetOrder(SIGHTDIST, "FoundTarget", DAMAGEATTRIBUTE); // seen a target to chase
//FindPointOrder("Patrol"); // do point stuff
PC=1;
LowLevel("Conscious");

if(PATROL = true)
{
NewOrder("Patrol");
}
else
{
NewOrder("Idle");
}
} ]

// you died
Death[()
{
LowLevel("death_biz");
return 0;
} ]


Death_1[ ()
{
SetNoCollision(); // remove bounding box so there are no collisions with corpse
FadeOut(5,0);
Remove(true); // remove actor
//RemoveWeapon(true); // remove the current weapon actor.

return 0;
}]

// Low level attack routines

// Start of run to attack

monster_run_start[ ()
{
TargetPlayer();
UpdateEnemyVis(true); //always aware of player position
UpdateTarget();
Animate(RUN); // play run animation
self.ThinkTime = 0; // start thinking on next frame
self.think = "monster_run"; // go to run attack routine
self.ideal_yaw = enemy_yaw; // set direction to run
self.yaw_speed = YAWSPEED; // set rotation speed
back_up = false; // initialize obstacle avoidance
attack_state = AS_NONE; // not attacking yet
melee_time = time;
run_sound_time = time;
} ]

// run to enemy to attack

monster_run[ ()
{
self.ThinkTime = 0;
if(self.health<=0)
{
self.think = "death_biz"; // dead
return 0;
}
if((self.in_pain = true) and (random(1,100)<PAINPERCENT))
{
self.think = "monster_run_pain_start"; // in pain
return 0;
}
if(EnemyExist(DAMAGEATTRIBUTE) < 3)
{
HighLevel("LostTarget"); // enemy is gone or dead
return 0;
}
if(enemy_vis = false)
{
self.think = LOSTFUNC; // lost sight of enemy
lost_time = time + LOSTTIME;
return 0;
}
if(run_sound_time < time)
{
if(random(1,10)>7)
{
run_sound_time = time + RUNSOUNDDELAY;
PlaySound(RUNSOUND);
}
}
ai_run(random((RUNSPEED-2)*SCALE,(RUNSPEED+2)*SCALE)); // run toward enemy
} ]

// start of pain while running

monster_run_pain_start[ ()
{
switch(random(1,4)) // play one of 4 pain animations
{
case 1
{
Animate(PAIN);
PlaySound("pl_pain2.wav", 500);
}
case 2
{
Animate(PAIN1);
PlaySound("pl_pain2.wav", 500);
}
case 3
{
Animate(PAIN2);
PlaySound("pl_pain2.wav", 500);
}
case 4
{
Animate(PAIN3);
PlaySound("pl_pain2.wav", 500);
}
}
SetHoldAtEnd(true); // set to stop at animation end
self.ThinkTime = 0;
self.think = "monster_run_pain";
} ]

// wait for animation to stop

monster_run_pain[ ()
{
self.ThinkTime = 0;
if(self.animate_at_end = true) // wait for end of animation
{
self.think = "monster_run_start"; // start running again
SetHoldAtEnd(false); // remove animation stop
self.ThinkTime = 0;
}
} ]

// start of lost sight of enemy routine

monster_lost_target_start[ ()
{
Animate(RUN); // play run animation
self.ThinkTime = 0; // start thinking on next frame
self.think = "monster_lost_target";
run_sound_time = time + RUNSOUNDDELAY;
} ]

// go to last known location of enemy

monster_lost_target[ ()
{
self.ThinkTime = 0;
if(lost_time<time)
{
HighLevel("LostTarget"); // timed out while looking
return 0;
}
self.ThinkTime = 0;
if(self.health<=0)
{
self.think = "death_biz"; // dead
return 0;
}
if((self.in_pain = true) and (random(1,100)<PAINPERCENT))
{
self.think = "monster_lost_pain_start"; // in pain
return 0;
}
if(EnemyExist(DAMAGEATTRIBUTE) < 3)
{
HighLevel("LostTarget"); // enemy died or was removed
return 0;
}
if(enemy_vis = true)
{
PlaySound("overhere_a.wav", 500);
self.think = "monster_run_start"; // seen again so run to attack
self.ThinkTime = 0;
return 0;
}
if(run_sound_time < time)
{
if(random(1,10)>7)
{
run_sound_time = time + RUNSOUNDDELAY;
PlaySound(RUNSOUND);
}
}
if((enemy_range>POINTRADIUS) and (RUNSPEED > 0)) // get close to last known location
{
walk_movetogoal(random((RUNSPEED-2)*SCALE,(RUNSPEED+2)*SCALE));
}
else
{
HighLevel("LostTarget"); // can't find at last known location
return 0;
}
} ]

// start of showing pain while searching

monster_lost_pain_start[ ()
{
switch(random(1,4)) // play one of 4 pain animations
{
case 1
{
Animate(PAIN);
PlaySound("pl_pain2.wav", 500);
}
case 2
{
Animate(PAIN1);
PlaySound("pl_pain2.wav", 500);
}
case 3
{
Animate(PAIN2);
PlaySound("pl_pain2.wav", 500);
}
case 4
{
Animate(PAIN3);
PlaySound("pl_pain2.wav", 500);
}
}
SetHoldAtEnd(true); // set to stop at end
self.ThinkTime = 0;
self.think = "monster_lost_pain";
} ]

// wait till animation is done

monster_lost_pain[ ()
{
self.ThinkTime = 0;
if(self.animate_at_end = true) // animation done
{
self.think = "monster_lost_target_start"; // go back to finding target
SetHoldAtEnd(false); // remove stop at end
self.ThinkTime = 0;
}
} ]

CheckForPoints[()
{
self.ThinkTime=0; // Process every frame


if((self.point_vis)and(CURPOINTL="C"))
{

// point is visible - go to high level for nav and targetting
HighLevel("LostTarget");
return 0;
}
else
{
// Point not visible - cycle points
PC=PC+1; // Increment point counter variable
if(PC > 27)
{
// Point count has exceeded max - set to 0. (Max was 110 but 27 for me)
PC=1;
}

NextPoint();
}
return 0;
}]

// start of missile attack

monster_missile_start[ ()
{
switch(random(1,3)) // play one of 3 missile animations
{
case 1
{
Animate(MISSILEATTACK);
fire_delay = time + FIREDELAY; // set firing delay
PlaySound("shotfire.wav", 500);
}
case 2
{
Animate(MISSILEATTACK1);
fire_delay = time + FIREDELAY1; // set firing delay
PlaySound("shotfire.wav", 500);
}
case 3
{
Animate(MISSILEATTACK2);
fire_delay = time + FIREDELAY2; // set firing delay
PlaySound("shotfire.wav", 500);
}
}
TargetPlayer();
UpdateEnemyVis(true); //always aware of player position
UpdateTarget();
self.ideal_yaw = enemy_yaw; // set direction to run
SetHoldAtEnd(true);
self.ThinkTime = 0.3;
self.think = "monster_missile";
skill_time = time + (SKILL*0.1); // calculate next update time
attack_delay = time + ATTACKDELAY; // delay until next shot
} ]

// attack target with projectile

monster_missile[ ()
{
self.ThinkTime = 0.3;
if(self.health<=0)
{
self.think = "death_biz";
return 0;
}
if((self.in_pain = true) and (random(1,100)<PAINPERCENT))
{
self.think = "monster_missile_pain_start"; // in pain
SetHoldAtEnd(false);
return 0;
}
exist = EnemyExist(DAMAGEATTRIBUTE);
if(exist < 2)
{
SetHoldAtEnd(false);
HighLevel("LostTarget"); // enemy is dead and gone
return 0;
}
if(exist = 2)
{
SetHoldAtEnd(false);
HighLevel("LostTarget"); // enemy is dead but body remains
return 0;
}
if(enemy_vis = false)
{
self.think = LOSTFUNC; // lost sight of enemy
lost_time = time + LOSTTIME;
SetHoldAtEnd(false);
return 0;
}
if(self.player_Y>self.current_Y)
{
Animate(SHOOTUP);
FireProjectile(PROJECTILE, FIREBONE, OFFSETX, OFFSETY, OFFSETZ, DAMAGEATTRIBUTE);
PlaySound("shotfire.wav", 500);
SetHoldAtEnd(false);
self.ThinkTime = 0.3;
}
if(self.player_Y<self.current_Y)
{
Animate(SHOOTDOWN);
FireProjectile(PROJECTILE, FIREBONE, OFFSETX, OFFSETY, OFFSETZ, DAMAGEATTRIBUTE);
PlaySound("shotfire.wav", 500);
SetHoldAtEnd(false);
self.ThinkTime = 0.3;
}
if(enemy_range>MISSILERANGE)
{
Animate(MISSILEATTACK);
FireProjectile(PROJECTILE, FIREBONE, OFFSETX, OFFSETY, OFFSETZ, DAMAGEATTRIBUTE);
fire_delay = time + FIREDELAY; // set firing delay
PlaySound("shotfire.wav", 500);
self.think = RUNFUNC; // too far away so run toward
SetHoldAtEnd(false);
return 0;
}
if(skill_time<time) // update according to skill level
{
UpdateTarget(); // update target location
skill_time = time + (SKILL*0);
ai_face(); // face enemy while attacking
}

if(fire_delay<time) // delay after animation starts before firing
{
FireProjectile(PROJECTILE, FIREBONE, OFFSETX, OFFSETY, OFFSETZ, DAMAGEATTRIBUTE);
fire_delay = time + 1000; // set delay well ahead so it is ignored
PlaySound("shotfire.wav", 500);
}
if(self.animate_at_end = true)
{
if(attack_delay < time)
{
//self.think = RUNFUNC; // no
self.think = "monster_missile_start";
SetHoldAtEnd(false);
self.ThinkTime = 0;
}
}
} ]


//Is the Pawn dead or just unconscious

death_biz[ ()
{
Animate(DIE);
PlaySound("deathyell.wav", 500);
SetHoldAtEnd(true); // set to stop at end
self.ThinkTime = 0.1;
if(self.player_weapon = 1)
{
SetAttribute(HEALTHATTRIBUTE,HEALTH);
HighLevel("Unconscious");
return 0;
}
HighLevel("Death_2");
return 0;
} ]

Death_2[()
{
NewOrder("Death_1");
return 0;
} ]

Unconscious[()
{
Delay("",20,""); //Stay unconscious for 20 secs
PC=1;
LowLevel("Conscious");
} ]

Conscious[()
{
self.ThinkTime = 0;
if(self.animate_at_end = true) // animation done
{
SetHoldAtEnd(false); // remove stop at end
}

if(self.point_vis)
{

// point is visible - go to high level for nav

HighLevel("Spawn");

return 0;
}
PC=PC+1; //point not visible - increment counter and try next point

if( PC > MAXPOINTS) // tried all points to no avail
{ // Chas totally lost and confused -- send him back to start point and get back to work
PC=1;
NewPoint("CStart2");
TeleportEntity("Chas" , "CStart2" );
HighLevel("Spawn");
return 0;
}

NewPoint("Cspc" # Integer(PC)); //next point for THIS pawn

} ]

// start of showing pain

monster_missile_pain_start[ ()
{
switch(random(1,4)) // play one of 4 pain animations
{
case 1
{
Animate(PAIN);
PlaySound("pl_pain2.wav", 500);
}
case 2
{
Animate(PAIN1);
PlaySound("pl_pain2.wav", 500);
}
case 3
{
Animate(PAIN2);
PlaySound("pl_pain2.wav", 500);
}
case 4
{
Animate(PAIN3);
PlaySound("pl_pain2.wav", 500);
}
}
SetHoldAtEnd(true); // set to stop at end
self.ThinkTime = 0;
self.think = "monster_missile_pain";
} ]

// wait until animation is done

monster_missile_pain[ ()
{
self.ThinkTime = 0;
if(self.animate_at_end = true) // animation is done
{
self.think = "monster_missile_start"; // go back to missile attack
SetHoldAtEnd(false);
self.ThinkTime = 0;
}
} ]

// start of melee attack

monster_melee_start[ ()
{
switch(random(1,3)) // play one of 3 melee animations
{
case 1
{
Animate(MELEEATTACK);
}
case 2
{
Animate(MELEEATTACK1);
}
case 3
{
Animate(MELEEATTACK2);
}
}
SetHoldAtEnd(true); // set to stop at end
self.ThinkTime = 0.1;
self.think = "monster_melee";
} ]

// melee attack

monster_melee[ ()
{
self.ThinkTime = 0;
if(self.health<=0)
{
PlaySound("deathyell.wav", 500);
self.think = "death_biz"; // in pain
return 0;
}
if((self.in_pain = true) and (random(1,100)<PAINPERCENT))
{
SetHoldAtEnd(false);
self.think = "monster_melee_pain_start"; // in pain
return 0.1;
}
exist = EnemyExist(DAMAGEATTRIBUTE); // see if target is around
if(exist < 2)
{
SetHoldAtEnd(false);
HighLevel("LostTarget"); // enemy is dead and gone
return 0;
}
if(exist = 2)
{
SetHoldAtEnd(false);
HighLevel("DeadTarget"); // enemy is dead but body remains
return 0;
}
if(enemy_vis = false)
{
SetHoldAtEnd(false);
self.think = LOSTFUNC; // lost sight of enemy
lost_time = time + LOSTTIME;
return 0;
}
if(enemy_range>(MELEERANGE*SCALE))
{
SetHoldAtEnd(false);
self.think = RUNFUNC; // too far away so run toward
return 0;
}
ai_face(); // face enemy while attacking
if(self.animate_at_end = true) // animation is done
{
SetHoldAtEnd(false);
switch(random(1,3)) // play one of 3 melee animations
{
case 1
{
Animate(MELEEATTACK);
}
case 2
{
Animate(MELEEATTACK1);
}
case 3
{
Animate(MELEEATTACK2);
}
}
SetHoldAtEnd(true); // set to stop at end
}
if(time>melee_time) // if time then damage
{
damage = random(MINMELEEDAMAGE, MAXMELEEDAMAGE); // get damage amount
Damage(damage, DAMAGEATTRIBUTE); // damage target
melee_time = time + MELEEDELAY; // reset time until next damage
}
} ]

// start of showing pain

monster_melee_pain_start[ ()
{
switch(random(1,4)) // play one of 4 pain animations
{
case 1
{
Animate(PAIN);
PlaySound("pl_pain2.wav", 500);
}
case 2
{
Animate(PAIN1);
PlaySound("pl_pain2.wav", 500);
}
case 3
{
Animate(PAIN2);
PlaySound("pl_pain2.wav", 500);
}
case 4
{
Animate(PAIN3);
PlaySound("pl_pain2.wav", 500);
}
}
SetHoldAtEnd(true); // set to stop at end
self.ThinkTime = 0.1;
self.think = "monster_melee_pain";
} ]

// wait until animation is done

monster_melee_pain[ ()
{
self.ThinkTime = 0.1;
if(self.animate_at_end = true) // animation is done
{
self.think = "monster_melee_start"; // go back to melee attack
SetHoldAtEnd(false);
self.ThinkTime = 0.1;
melee_time = time + MELEEDELAY; // reset attack deley
}
} ]

// basic AI routines

// run toward enemy and see if you are ready to attack

ai_run[ (dist)
{
if (attack_state = AS_MELEE) // do melee attack
{
ai_run_melee();
}
if (attack_state = AS_MISSILE) // do missile attack
{
ai_run_missile();
}

attack_state = AS_NONE;

if (CheckAnyAttack()) // check if you can start the actual attack
{
return 0;
}
if(RUNSPEED > 0)
{
walk_movetogoal(dist); // else move toward the enemy
}
} ]

// check if ready to do actual attacking

CheckAnyAttack[ ()
{
if(enemy_range<MELEERANGE)
{
if(enemy_range<(MELEERANGE*SCALE)) // inside melee range
{
attack_state = AS_MELEE; // do a melee attack
return true;
}
return false;
}

if(enemy_range<MISSILERANGE)
{
if(attack_delay>time)
{
return false;
}
if(enemy_range<MISSILERANGE)
{
attack_state = AS_MISSILE; // do a missile attack
return true;
}
}
return false;
} ]

// missile attack setup

ai_run_missile[ ()
{
ai_face();
if(FacingIdeal()) // got close enough
{
self.think = MISSILEFUNC; // start missile attack
attack_state = AS_STRAIGHT;
UpdateTarget();
skill_time = time + (SKILL*0.1);
}
} ]

// melee attack setup

ai_run_melee[ ()
{
ai_face(); // turn to face target
if(FacingIdeal()) // got close enough
{
self.think = MELEEFUNC; // start melee attack
self.attack_state = AS_STRAIGHT;
}
} ]

// face enemy

ai_face[ ()
{
self.ideal_yaw = enemy_yaw;
ChangeYaw(); // rotate to face enemy
} ]

// use walkmove to naviagte to enemy

walk_movetogoal[ (dist)
{
if(IsFalling = true)
{
return 0; // don't move while falling
}
if(dist < 0)
{
return 0;
}
if(back_up = false)
{
ai_face(); // turn to face enemy
if(FacingIdeal())
{
if(walkmove(self.current_yaw, dist) = true)
{
return 0; // can move in current direction
}
else
{
if(random(1,10)<3) // backup and move sideways
{
back_up = true;
back_time = time + 0.5;
back_flag = false;
return 0;
}
else
{
ForceUp(FORCEUP*SCALE); // jump up, forward and to side
ForceForward(FORCEFORWARD*SCALE);
if(random(1,10)<6)
{
ForceRight(FORCESIDE*SCALE);
}
else
{
ForceLeft(FORCESIDE*SCALE);
}
}
}
}
}
else
{
if(back_flag = false) // go backward 1/2 sec
{
if(back_time > time)
{
walkmove((self.current_yaw-(180*0.0174532925199433)), dist);
return 0;
}
else
{
back_time = time + 0.5;
back_flag = true;
}
}
if(back_time > time) // go sideways 1/2 sec
{
walkmove((self.current_yaw-(90*0.0174532925199433)), dist);
return 0;
}
back_up = false;
}
} ]

// check if nearly facing enemy

FacingIdeal[ ()
{
selfangle = self.current_yaw/0.0174532925199433; // your direction in degrees
idealangle = self.ideal_yaw/0.0174532925199433; // his direction in degrees
delta = selfangle - idealangle; // difference in directions
if (delta > -20 and delta < 20) // within 20 degrees is close enough
{
return true;
}
return false;
} ]

}

User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Really Need HELP - Respawn

Post by metal_head » Thu Apr 03, 2008 12:26 pm

Hmm...I don't know,when I used the script on my pawn he was just standing there and playing the Idle animation and that was all he did... any guesses why?

User avatar
creekmonkey
Posts: 116
Joined: Tue Oct 23, 2007 2:55 pm

Re: Really Need HELP - Respawn

Post by creekmonkey » Mon Apr 07, 2008 9:26 pm

Bernie

I started trying your modified AI script. When the pawn spawns, it doesnt move to anypoint.
If I assign a script point to spawn to, it will move from that point to the first script point, then stops but the walk animation continues. And the consol just blinks on and off very fast, saying "move to p1". p1 is the name of the first script point. What am I doing wrong here? Is there a certain way I need to name the script points?

User avatar
bernie
RF Moderator
Posts: 1249
Joined: Tue Nov 15, 2005 10:07 am
Location: Ireland

Re: Really Need HELP - Respawn

Post by bernie » Mon Apr 07, 2008 10:49 pm

You need to set up your script points correctly.

ScriptPoint1
Angle 0 0 0
NextOrder FindPointOrder
NextPoint p2
Origin ---- Whatever it is
SzEntityName p1

Script point2
Angle 0 0 0
NextOrder FindPointOrder
NextPoint p3
Origin ---- Whatever it is
SzEntityName p2

etc..
Last point back to ScriptPoint1
lets say there are only 3

Script point3
Angle 0 0 0
NextOrder FindPointOrder
NextPoint p1
Origin ---- Whatever it is
SzEntityName p3

The pawn will then patrol around the points and keep patroling until he spots you
and attacks or loses you then he will search for the nearest point and go there then
continue patroling.

User avatar
creekmonkey
Posts: 116
Joined: Tue Oct 23, 2007 2:55 pm

Re: Really Need HELP - Respawn

Post by creekmonkey » Mon Apr 07, 2008 11:08 pm

Thanks once again Bernie........you da man!

NextOrder = FindPointOrder is what I was missing.

Dingalling
Posts: 5
Joined: Sat Nov 20, 2010 2:05 am

Re: Really Need HELP - Respawn

Post by Dingalling » Thu Nov 25, 2010 3:45 pm

when i go to shoot the respawned enemy my bullets pass right through, here is my script:

Code: Select all

Death[()
	{
		DelTimerOrder(1);					// remove alert timer
		AddPainOrder("PainToAlert", 0);				// remove pain order
		FindTargetOrder(0, "FoundTarget", DAMAGEATTRIBUTE);	// remove target finding
		DelTriggerOrder("IdleToAlert");				// remove alert trigger
		SetNoCollision();					// remove bounding box so there are no collisions with corpse
		AnimateStop(DIE, DIEHOLD, "");		
		FadeOut(DIEFADE, 0); 					// fade out corpse
		switch(random(1,4)) // chose random script point to re-spawn to
	{
		case 1
	{
		TeleportToPoint("p2",0,0,0);
		NewPoint("p2");
		RotateToAlign("idle",500,false,"");
	}
		case 2
	{
		TeleportToPoint("p5",0,0,0);
		NewPoint("p5");
		RotateToAlign("idle",500,false,"");
	}
		case 3
	{
		TeleportToPoint("p11",0,0,0);
		NewPoint("p11");
		RotateToAlign("idle",500,false,"");
	}
		case 4
	{
		TeleportToPoint("p7",0,0,0);
		NewPoint("p7");
		RotateToAlign("idle",500,false,"");
	}

	}
		FadeIn(DIEFADE,255);
		AttributeOrder("enemy_health",100, "Death"); 
		NewOrder("LostTarget");

	}

User avatar
QuestOfDreams
Site Admin
Posts: 1520
Joined: Sun Jul 03, 2005 11:12 pm
Location: Austria
Contact:

Re: Really Need HELP - Respawn

Post by QuestOfDreams » Fri Nov 26, 2010 9:35 am

Code: Select all

SetNoCollision();               // remove bounding box so there are no collisions with corpse
You've turned off collision detection in the Death order. You have to turn it on again.

Post Reply