Pawn -stays in pain too much...

Topics regarding Scripting with Reality Factory
Post Reply
Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Pawn -stays in pain too much...

Post by Veleran » Tue Sep 13, 2011 7:33 am

This one patrols and when it passes through a fireball fire point,it stops when its hit by the fireball and before it can continue to patrol,stays there and takes more hits for several seconds and then it dies..to much pain maybe..dont know how to fix it yet...i already tried to reduce the master control for Pain percent,
in PAINPERCENT [20] // percentage of time pain is shown.
or it it a high self think value somewhere and he is thinking that slow he does nt have time to continue moveing to the scriptpoint?

Code: Select all

{

	 //   Generic  Monster 

	SCALE				[1]			// scale of actor
	GROUP				[Generic]	// name of monster group
	BOXWIDTH			[28]		// 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
	HEALTH			[120]		// initial amount of health
	SIGHTDIST			[400]		// max distance monster can see at idle
	ALERTSIGHTDIST		[600]		// max distance monster can see when alert
	FOV				[180]		// field of view in degrees
	YAWSPEED			[60]		// 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

	// idling and turning

	STAND				[Idle_standing]		// idle animation
	TURNL				[Turn_Left_1]		// turn left animation
	TURNR				[Turn_Right_1]		// turn right animation

	// when in pain

	PAIN				[Idle_standing]		// pain animations
	PAIN1				[Idle_standing]
	PAIN2				[Idle_standing]
	PAIN3				[Idle_standing]
	PAINPERCENT			[20]		// percentage of time pain is shown
	PAINSOUND			[PainHumanoid1.wav]	// sounds played when in pain
	PAINSOUND1			[PainHumanoid1.wav]
	PAINSOUND2			[PainHumanoid1.wav]
	PAINSOUND3			[PainHumanoid1.wav]

	// when dying

	DIE					[Orc_1_fall_back_1]		// dying animations
	DIE1				[Orc_1_fall_1]
	DIE2				[Orc_1_fall_back_1]
	DIE3				[Orc_1_fall_1]
	DIEHOLD				[15]		// time corpse still appears
	DIEFADE				[10]		// fadeout time of corpse
	DIESOUND			[die.wav]	// sounds played when dying
	DIESOUND1			[die.wav]
	DIESOUND2			[die.wav]
	DIESOUND3			[die.wav]

	// when running to attack

	RUN					[Run_3]		// running animation
	RUNSPEED			[80]		// average run speed
	RUNSOUNDDELAY		[15]			// delay between making sounds when running to attack
	RUNSOUND			[footstep-deep.wav]	// sound played while running to attack

	// when walking while patroling

	WALK				[Run_3]		// walking animation
	WALKSPEED			[100]		// average walking speed

	// the projectile attack mode

	MISSILEATTACK		[Shoot1]	// missile attacking animation
	MISSILEATTACK1		[Shoot]
	MISSILEATTACK2		[Shoot]
	FIREDELAY			[0.8]		// delay after animation starts before projectile launch
	FIREDELAY1			[0.8]
	FIREDELAY2			[0.8]
	MISSILESOUND		[weapon/swordslash1.wav]	// sounds played when shooting
	MISSILESOUND1		[weapon/swordslash1.wav]
	MISSILESOUND2		[weapon/swordslash1.wav]
	MISSILERANGE		[300]		// max distance to start missile attack
	PROJECTILE			[GL_Grenade]		// projectile name
	FIREBONE			[BIP01 SPINE2]	// projectile launch bone
	OFFSETX				[0]			// launch offsets
	OFFSETY				[0]
	OFFSETZ				[25]
	ATTACKDELAY			[2]			// time between shots
	SKILL				[5]			// skill level 1 to 10

	// the melee attack mode

	MELEEATTACK			[Slash_1]	// melee attacking animations
	MELEEATTACK1		[Slash_1]
	MELEEATTACK2		[Slash_1]
	MELEESOUND			[weapon/swordslash1.wav]	// sounds played when melee attacking
	MELEESOUND1			[weapon/swordslash1.wav]
	MELEESOUND2			[weapon/swordslash1.wav]
	MELEERANGE			[40]		// max distance to start melee attack
	MINMELEEDAMAGE		[1]		// minimum amount of damage per melee attack
	MAXMELEEDAMAGE		[4]		// maximum amount of damage per melee attack
	MELEEDELAY			[2]			// number of seconds between melee damages
	MELEEDAMAGESOUND	 [DING.wav]	// sound played when damage is done

	// search for enemy

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

	// obstacle avoidance forces for jumping

	FORCEUP				[8]		// obstacle avoidance jump speed
	FORCEFORWARD		[30]		// obstacle avoidance forward speed
	FORCESIDE			[30]		// 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]

	// spawn pawn and do setup work

	Spawn[ ()
	{
		Console(false);
		Scale(SCALE);	// scale the actor
		if(BOXWIDTH > 0)
		{
			BoxWidth(BOXWIDTH*SCALE);			// set bounding box width/depth
		}
		AttributeOrder(HEALTHATTRIBUTE, HEALTH, "Death");	// give monster health
            StepHeight(8);
		HostilePlayer(HOSTILEPLAYER);	// set who monster is hostile to
		HostileSame(HOSTILESAME);
		HostileDifferent(HOSTILEDIFFERENT);
		SetFOV(FOV);					// 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");
		AddTriggerOrder("IdleToAlert", ALERTTRIGGER, 0);	// go to alert when triggered 
		RotateToPoint(STAND, YAWSPEED, false, ""); // go to point if any specified
		MoveToPoint(WALK, WALKSPEED*SCALE, "");
		if(PATROL = false)
		{
			NewOrder("Idle");
		}
		else
		{
			NewOrder("Patrol");
		}
	} ]

	// avoid objects when doing a MoveToPoint

	Avoidance[ ()
	{
		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, "");
		if(random(1,10)>6)
		{
			if(random(1,10)>5)
			{
				Rotate(TURNL, 102, 0, 90, 0, "");
				PlayAnimation(STAND, true, "");
				Rotate(TURNR, 108, 0, -90, 0, "");
			}
			else
			{
				Rotate(TURNR, 108, 0, -90, 0, "");
				PlayAnimation(STAND, true, "");
				Rotate(TURNL, 102, 0, 90, 0, "");
			}
		}
		RestartOrder();
	} ]	

	// walk the beat from point to point

	Patrol[ ()
	{
		NextPoint();
		RotateToPoint("Run_3", 130, false, "");
		MoveToPoint("Run_3", 65, "");
		RestartOrder();
	} ]

	// show pain at idle then trigger to alert

	IdlePain[ ()
	{
		switch(random(1,4)) // chose between 4 animations
		{
			case 1
			{
				PlayAnimation(PAIN, true, "");
			}
			case 2
			{
				PlayAnimation(PAIN1, true, "");
			}
			case 3
			{
				PlayAnimation(PAIN2, true, "");
			}
			case 4
			{
				PlayAnimation(PAIN3, true, "");
			}
		}
		SetEventState(ALERTTRIGGER, true);	// set trigger to go to alert
		Return();
	} ]	

	// start shifting from idle to alert

	IdleToAlert[ ()
	{
		FindTargetOrder(ALERTSIGHTDIST, "FoundTarget", DAMAGEATTRIBUTE);	// increase viewing distance
		AddPainOrder("AlertPain", PAINPERCENT);			// show pain
		AddTimerOrder(1, 10, "AlertToIdle");			// go to idle after 10 secs
		SetEventState(ALERTTRIGGER, false);		// turn off alert trigger
		NewOrder("Alert");
	} ]

	// look around at alert looking for enemy

	Alert[ ()
	{
		if(random(1,10)>5)
		{
			Rotate(TURNL, 102, 0, 90, 0, "");
			Rotate(TURNL, 102, 0, 90, 0, "");
			Rotate(TURNL, 102, 0, 90, 0, "");
			Rotate(TURNL, 102, 0, 90, 0, "");
		}
		else
		{
			Rotate(TURNR, 108, 0, -90, 0, "");
			Rotate(TURNR, 108, 0, -90, 0, "");
			Rotate(TURNR, 108, 0, -90, 0, "");
			Rotate(TURNR, 108, 0, -90, 0, "");
		}
		RestartOrder();
	} ]	

	// show pain at alert

	AlertPain[ ()
	{
		switch(random(1,4)) // play one of 4 animations
		{
			case 1
			{
				PlayAnimation(PAIN, true, PAINSOUND);
			}
			case 2
			{
				PlayAnimation(PAIN1, true, PAINSOUND1);
			}
			case 3
			{
				PlayAnimation(PAIN2, true, PAINSOUND2);
			}
			case 4
			{
				PlayAnimation(PAIN3, true, PAINSOUND3);
			}
		}
		Return();
	} ]	

	// timed out at alert

	AlertToIdle[ ()
	{
		FindTargetOrder(SIGHTDIST, "FoundTarget", DAMAGEATTRIBUTE);	// decrease viewing distance
		AddTriggerOrder("IdleToAlert", ALERTTRIGGER, 0);	// go to alert when triggered
		AddPainOrder("IdlePain", 100);				// show pain 
		if(PATROL = false)
		{
			NewOrder("Idle");
		}
		else
		{
			RotateToPoint(STAND, YAWSPEED, false, "");
			MoveToPoint(WALK, WALKSPEED*SCALE, "");
			NewOrder("Patrol");
		}
	} ]

	// found a target to attack

	FoundTarget[ ()
	{
		DelTimerOrder(1);	// get rid of alert timer
		LowLevel(RUNFUNC);	// attack functions are low level
	} ]

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

	LostTarget[ ()
	{
		FindTargetOrder(SIGHTDIST, "FoundTarget", DAMAGEATTRIBUTE);	// seen a target to chase
		AddPainOrder("IdlePain", 100);				// show pain and trigger alert
		AddTriggerOrder("IdleToAlert", ALERTTRIGGER, 0);	// go to alert when triggered
		if(PATROL = false)
		{
			NewOrder("Idle");
		}
		else
		{
			RotateToPoint(STAND, YAWSPEED, false, "");
			MoveToPoint(WALK, WALKSPEED*SCALE, "");
			NewOrder("Patrol");
		}
	} ]

	// you died

	Death[ ()
	{
		DelTimerOrder(1);	// remove alert timer
		AddPainOrder("IdlePain", 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
		switch(random(1,4)) // chose between 4 death animations
		{
			case 1
			{
				AnimateStop(DIE, DIEHOLD, DIESOUND);
			}
			case 2
			{
				AnimateStop(DIE1, DIEHOLD, DIESOUND1);
			}
			case 3
			{
				AnimateStop(DIE2, DIEHOLD, DIESOUND2);
			}
			case 4
			{
				AnimateStop(DIE, DIEHOLD, DIESOUND3);
			}
		}
		if(DIEHOLD >= 0)
		{
			FadeOut(DIEFADE, 0); // fade out corpse
			Remove(true);	// remove actor
		}
	} ]

	// Low level attack routines

	// Start of run to attack

	monster_run_start[ ()
	{
		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.1;
		if(self.health<=0)
		{
			HighLevel("Death"); // 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[ ()
	{
		Animate(PAIN);
		SetHoldAtEnd(true);	// set to stop at animation end
		self.ThinkTime = 0.1;
		self.think = "monster_run_pain";
	} ]

	// wait for animation to stop

	monster_run_pain[ ()
	{
		self.ThinkTime = 0.1;
		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.1;
		if(lost_time<time)
		{
			HighLevel("LostTarget"); // timed out while looking
			return 0;
		}
		if(self.health<=0)
		{
			HighLevel("Death"); // died
			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)
		{
			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[ ()
	{
		Animate(RUN);
		SetHoldAtEnd(true);	// set to stop at end
		self.ThinkTime = 0.1;
		self.think = "monster_lost_pain";
	} ]

	// wait till animation is done

	monster_lost_pain[ ()
	{
		self.ThinkTime = 0.1;
		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;
		}
	} ]

	// 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
				missile_sound = MISSILESOUND;
			}
			case 2
			{
				Animate(MISSILEATTACK1);
				fire_delay = time + FIREDELAY1; // set firing delay
				missile_sound = MISSILESOUND1;
			}
			case 3
			{
				Animate(MISSILEATTACK2);
				fire_delay = time + FIREDELAY2; // set firing delay
				missile_sound = MISSILESOUND2;
			}
		}
		SetHoldAtEnd(true);
		self.ThinkTime = 0;
		self.think = "monster_missile";
		UpdateTarget();					// update target location
		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.1;
		if(self.health<=0)
		{
			SetHoldAtEnd(false);
			HighLevel("Death"); // dead
			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(enemy_range>MISSILERANGE)
		{
			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.1);
			ai_face();	// face enemy while attacking
		}

		if(fire_delay<time) // delay after animation starts before firing
		{
			FireProjectile(PROJECTILE, FIREBONE, (OFFSETX*SCALE), (OFFSETY*SCALE), (OFFSETZ*SCALE), DAMAGEATTRIBUTE);
			fire_delay = time + 1000; // set delay well ahead so it is ignored
			PlaySound(missile_sound);
		}

		// wait until animation is done before attacking again
		// hold animation at end until attack delay is over

		if(self.animate_at_end = true)
		{
			if(attack_delay < time)
			{
				self.think = "monster_missile_start"; // go back to missile attack
				SetHoldAtEnd(false);
				self.ThinkTime = 0.1;
			}
		} 
	} ]

	// start of showing pain

	monster_missile_pain_start[ ()
	{
		Animate(PAIN);	// play pain animation
		SetHoldAtEnd(true);	// set to stop at end
		self.ThinkTime = 0.1;
		self.think = "monster_missile_pain";
	} ]

	// wait until animation is done

	monster_missile_pain[ ()
	{
		self.ThinkTime = 0.1;
		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[ ()
	{
		Animate(MELEEATTACK);
		SetHoldAtEnd(true);	// set to stop at end
		self.ThinkTime = 0;
		self.think = "monster_melee";
	} ]

	// melee attack

	monster_melee[ ()
	{
		self.ThinkTime = 0.1;
		if(self.health<=0)
		{
			SetHoldAtEnd(false);
			HighLevel("Death"); // you died
			return 0;
		}
		if((self.in_pain = true) and (random(1,100)<PAINPERCENT))
		{
			SetHoldAtEnd(false);
			self.think = "monster_melee_pain_start"; // in pain
			return 0;
		}
		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);
					PlaySound(MELEESOUND);
				}
				case 2
				{
					Animate(MELEEATTACK1);
					PlaySound(MELEESOUND1);
				}	
				case 3
				{
					Animate(MELEEATTACK2);
					PlaySound(MELEESOUND2);
				}
			}
			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
			PlaySound(MELEEDAMAGESOUND);
		}
	} ]

	// start of showing pain

	monster_melee_pain_start[ ()
	{
		Animate(PAIN);	      // play pain animation
		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;
			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();
			return 0;
		}
		if (attack_state = AS_MISSILE) // do missile attack
		{
			ai_run_missile();
			return 0;
		}
		if (CheckAnyAttack()) // check if you can start the actual attack
		{
			return 0;
		}
		if(RUNSPEED > 0)
		{
			walk_movetogoal(dist); // else move toward the enemy
		}
	} ]

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

	// check if ready to do actual attacking

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

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

}
Last edited by paradoxnj on Wed Sep 21, 2011 1:08 am, edited 1 time in total.
Reason: Put script code inside code tags for easier reading - paradoxnj

Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Re: Pawn -stays in pain too much...

Post by Jay » Tue Sep 13, 2011 11:13 am

AddPainOrder("IdlePain", 100); // show pain and trigger alert

The pawn goes to the pain order everytime it's hit. Replace this with

AddPainOrder("IdlePain", PAINPERCENT); // show pain and trigger alert
and the PAINPERCENT value is taken into account.
Everyone can see the difficult, but only the wise can see the simple.
-----

Veleran
Posts: 891
Joined: Mon Aug 22, 2005 10:22 am
Location: Greece

Re: Pawn -stays in pain too much...

Post by Veleran » Tue Sep 13, 2011 8:02 pm

Thanks a lot-it works fine now.There were two,and seems i had edited the one and had missed the second one because i wanted a break for that moment.
I put idle pain 20 instead of 100 to the spawn order too,hope its ok,.

Post Reply