Page 1 of 1

help with pawn scripts

Posted: Tue Feb 27, 2007 10:03 pm
by whatwhat89
How do you make enemy pawns melee?

Posted: Wed Feb 28, 2007 8:55 am
by Juutis
It depends on the script you are using.

You will probably have to add some orders for the melee attack. Then make the pawn check if it is close enough to melee, and if it is, move to the melee order.
In the melee order(s) you would play the melee animation, check if the pawn is facing its enemy and, in the end, damage the enemy.

Posted: Wed Feb 28, 2007 11:07 am
by QuestOfDreams
You may have a look at the genericmelee script in the script\sample folder of your RF installation.

Posted: Thu Mar 01, 2007 5:24 pm
by whatwhat89
The genericmelee.s only uses one melee animation. How do I get it to use 3.

Posted: Thu Mar 01, 2007 5:51 pm
by Juutis
For example:

Code: Select all

switch(random(0,3))
{
     case 0
     {
          Animate(MELEEATTACK1);
     }
     case 1
     {
          Animate(MELEEATTACK2);
     }
     case 2
     {
          Animate(MELEEATTACK3);
     }
     case 3
     {
          Animate(MELEEATTACK1);
     }
}

Posted: Thu Mar 01, 2007 6:18 pm
by whatwhat89
here's my script. when i put it in a level the pawn dosen't even show up.

{
GROUP [bunny] // name of monster group
BOXWIDTH [60] // 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 [100] // initial amount of health
SIGHTDIST [450] // max distance monster can see at idle
ALERTSIGHTDIST [600] // max distance monster can see when alert
FOV [180] // field of view in degrees
YAWSPEED [120] // speed of rotation in deg/sec
DAMAGEATTRIBUTE [health] // attribute damaged by attack
ALERTTRIGGER [Alert] // triggername used to go to alert mode


STAND [idle]
TURNL [walk]
TURNR [walk]

PAIN [pain_head]
PAIN [pain_stomach]
PAINPERCENT [25]

DIE [die_spin]
DIE1 [die_backwards]
DIEHOLD [10]
DIEFADE [5]

RUN [run]
RUNSPEED [120]

MELEEATTACK [punches]
MELEERANGE [90]
MINMELEEDAMAGE [25]
MAXMELEEDAMAGE [30]
MELEEDELAY [2]

RUNFUNC [monster_run_start]
MELEEFUNC [monster_melee_start]
LOSTFUNC [monster_lost_target_start]

AS_NONE [0]
AS_MELEE [2]
AS_STRAIGHT [3]
melee_time [0]
lost_time [0]
back_up [false]
back_time [0]
left_time [0]
back_flag [false]
attack_state [0]


Spawn[ ()
{
Console(true);
BoxWidth(BOXWIDTH); // 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(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
AddTriggerOrder("IdleToAlert", ALERTTRIGGER, 0); // go to alert when triggered
NewOrder("Idle");
} ]

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

IdlePain[ ()
{
switch(random(1,2))
{
case1
{
PlayAnimation(PAIN, true, "");
}
case2
{
PlayAnimation(PAIN1, true, "");
}
}
SetEventState(ALERTTRIGGER, true);
Return();
}]

IdleToAlert[ ()
{
FindTargetOrder(ALERTSIGHTDIST, "FoundTarget", DAMAGEATTRIBUTE);
AddPainOrder("AlertPain", PAINPERCENT);
AddTimerOrder(1, 10, "AlerToIdle");
SetEventStateventState(ALERTTRIGGER, false);
NewOrder("Alert");
}]

Alert[ ()
{
PlayAnimation(STAND, true, "");
if(random(1,10)>3) // turn around once in awhile
{
if(random(1,10)>5) // turn around to left
{
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 // turn around to right
{
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();
}]

AlertPain[ ()
{
switch(random(1,2))
{
case1
{
PlayAnimation(PAIN, true, "");
}
case2
{
PlayAnimation(PAIN1, true, "");
}
}
Return();
}]

AlertToIdle[ ()
{
DelTimerOrder(1);
LowLevel1(RUNFUNC);
}]

LostTarget{ ()
{
FindTargetOrder(SIGHTDIST, "FoundTarget", DAMAGEATTRIBUTE);
AddPainOrder("IdlePain", 100);
AddTriggerOrder("IdleToAlert", ALERTTRIGGER, 0);
NewOrder("Idle");
}
}]

DeadTarget[ ()
{
FindTargetOrder(SIGHTDIST, "FoundTarget", DAMAGEATTRIBUTE);
AddPainOrder("IdlePain", 100);
AddTriggerOrder("IdleToAlert", ALERTTRIGGER, 0);
NewOrder("Idle");
}
}]

Death[ ()
{
DelTimerOrder(1);
AddPainOrder("IdlePain", 0);
FindTargetOrder(0, "FoundTarget", DAMAGEATTRIBUTE);
DelTriggerOrder("IdleToAlert");
SetNoCollision();
switch(random(1,2))
{
case1
{
AnimateStop(DIE, DIEHOLD, "")
}
case2
{
AnimateStop(DIE1, DIEHOLD, "")
}
}
FadeOut(DIEFADE, 0);
Remove(true);
}]

monster_run_start[()
{
Animate(RUN);
self.ThinkTime = 0;
self.think = "monster_run";
self.ideal_yaw = elsenemy_yaw;
attack_state state = AS_NONE
self.yaw_speed = YAWSPEED;
melee_time = time;
back_up = false;
}]

monster_run[ ()
{
self.ThinkTime = 0.1;
if(self.health<=0)
{
HighLevel("Death");
return 0 ;
}
if((self.in_pain = true) and (random(1,100)<PAINPERCENT))
{
self.think = "monster_run_pain_start";
return 0 ;
}
if(EnemyExist(DAMAGEATTRIBUTE) < 3)
{
HighLevel("LostTarget");
return 0;
}
if(enemy_vis = false)
{
self.think = LOSTFUNC;
lost_time = time + LOSTTIME;
return 0;
}
ai_run(random(RUNSPEED-2,RUNSPEED+2));

}]

monster_run_pain_start[()
{
Animate(PAIN);
SetHoldAtEnd(true);
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)
{
self.think = "monster_run_start";
SetHoldAtEnd(false);
self.ThinkTime = 0;
}
} ]



monster_lost_target_start[ ()
{
Animate(RUN);
self.ThinkTime = 0;
self.think = "monster_lost_target";
} ]



monster_lost_target[ ()
{
self.ThinkTime = 0.1;
if(lost_time<time)
{
HighLevel("LostTarget");
return 0;
}
if(self.health<=0)
{
HighLevel("Death");
return 0;
}
if((self.in_pain = true) and (random(1,100)<PAINPERCENT))
{
self.think = "monster_lost_pain_start";
return 0;
}
if(EnemyExist(DAMAGEATTRIBUTE) < 3)
{
HighLevel("LostTarget");
return 0;
}
if(enemy_vis = true)
{
self.think = "monster_run_start";
return 0;
}
if(enemy_range>POINTRADIUS)
{
walk_movetogoal(random(RUNSPEED-2,RUNSPEED+2));
}
else
{
HighLevel("LostTarget");
return 0;
}
} ]



monster_lost_pain_start[ ()
{
Animate(PAIN);
SetHoldAtEnd(true);
self.ThinkTime = 0.1;
self.think = "monster_lost_pain";
} ]



monster_lost_pain[ ()
{
self.ThinkTime = 0.1;
if(self.animate_at_end = true)
{
self.think = "monster_lost_target_start";
SetHoldAtEnd(false);
self.ThinkTime = 0;
}
} ]



monster_melee_start[ ()
{
Animate(MELEEATTACK);
self.ThinkTime = 0;
self.think = "monster_melee";
} ]



monster_melee[ ()
{
self.ThinkTime = 0.1;
if(self.health<=0)
{
HighLevel("Death");
return 0;
}
if((self.in_pain = true) and (random(1,100)<PAINPERCENT))
{
self.think = "monster_melee_pain_start";
return 0;
}
exist = EnemyExist(DAMAGEATTRIBUTE);
if(exist < 2)
{
HighLevel("LostTarget");
return 0;
}
if(exist = 2)
{
HighLevel("DeadTarget");
return 0;
}
if(enemy_vis = false)
{
self.think = LOSTFUNC;
lost_time = time + LOSTTIME;
return 0;
}
if(enemy_range>MELEERANGE)
{
self.think = RUNFUNC;
return 0;
}
ai_face();
if(time>melee_time)
{
damage = random(MINMELEEDAMAGE, MAXMELEEDAMAGE);
Damage(damage, DAMAGEATTRIBUTE);
melee_time = time + MELEEDELAY;
}
} ]



monster_melee_pain_start[ ()
{
Animate(PAIN);
SetHoldAtEnd(true);
self.ThinkTime = 0.1;
self.think = "monster_melee_pain";
} ]



monster_melee_pain[ ()
{
self.ThinkTime = 0.1;
if(self.animate_at_end = true)
{
self.think = "monster_melee_start";
SetHoldAtEnd(false);
self.ThinkTime = 0;
melee_time = time + MELEEDELAY;
}
} ]





ai_run[ (dist)
{
if (attack_state = AS_MELEE)
{
ai_run_melee();
return 0;
}
if (CheckAnyAttack())
{
return 0;
}
walk_movetogoal(dist);
} ]



ai_run_melee[ ()
{
ai_face();
if(FacingIdeal())
{
self.think = MELEEFUNC;
self.attack_state = AS_STRAIGHT;
}
} ]



ai_face[ ()
{
self.ideal_yaw = enemy_yaw;
ChangeYaw();
} ]



walk_movetogoal[ (dist)
{
if(IsFalling = true)
{
return 0;
}
if(back_up = false)
{
ai_face();
if(FacingIdeal())
{
if(walkmove(self.current_yaw, dist) = true)
{
return 0;
}
else // blocked
{
if(random(1,10)<3)
{
back_up = true;
back_time = time + 0.5;
back_flag = false;
return 0;
}
else
{
ForceUp(30);
ForceForward(30);
if(random(1,10)<6)
{
ForceRight(30);
}
else
{
ForceLeft(30);
}
}
}
}
}
else
{
if(back_flag = false)
{
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)
{
walkmove((self.current_yaw-(90*0.0174532925199433)), dist);
return 0;
}
back_up = false;
}
} ]



FacingIdeal[ ()
{
selfangle = self.current_yaw/0.0174532925199433;
idealangle = self.ideal_yaw/0.0174532925199433;
delta = selfangle - idealangle;
if (delta > -20 and delta < 20)
{
return true;
}
return false;
} ]


CheckAnyAttack[ ()
{
if(enemy_range<MELEERANGE)
{
attack_state = AS_MELEE;
return true;
}
return false;
} ]

}