I suggest checking if the enemy is in the walk animation. I didn't understand the rangex/rangez formula but I made some changes according to what I understand about the behaviour you want to apply.I'm getting closer to an acceptable script, but it still has problems. The first half of the video looks fine, but the second half they start doing weird things. The most notable of them is just the last enemy, notice that I throw him into the air, and when he lines up right with the trap below, he is instantly tossed by the script. I guess I'll have to make the script from acting only if the character is in WALK and RUN animations.
C:
void main()
{
void self = getlocalvar("self");
void trap = findtarget(self);
void isfire = getentityproperty(trap, "defaultname");
if(isfire == "potfire" || isfire == "potfire2" || isfire == "potfire3")
{
void anim = getentityproperty(self, "animationID"); //GET THE CURRENT ANIMATION
int z1 = getentityproperty(self, "z"); //ENEMY
int z2 = getentityproperty(trap, "z"); //NPC TRAP
int rangeZBelow = (z1 - z2);
int rangeZAbove = (z2 - z1);
//CHECK IF THE ENEMY IS IN THE WALK ANIMATION
if(anim == openborconstant("ANI_WALK"))
{
//FIRE TRAP IS AT THE TOP OF THE Z BOUNDARY AND ENEMY IS BELOW (LESS THAN 45 PIXELS)
if(z1 > z2 && rangeZBelow < 45){ //CHECK RANGE
changeentityproperty(self, "animation", openborconstant("ANI_JUMP")); //CHANGE ANIMATION
tossentity(self, 2, 0, 2);
}
//FIRE TRAP IS AT THE TOP OF THE Z BOUNDARY AND ENEMY IS BELOW (BETWEEN 45 AND 60 PIXELS)
else if(z1 > z2 && rangeZBelow > 45 && rangeZBelow < 60){ //CHECK RANGE
changeentityproperty(self, "aimove", openborconstant("AIMOVE1_AVOID"));
}
//FIRE TRAP IS AT THE BOTTOM Z BOUNDARY AND ENEMY IS ABOVE (LESS THAN 45 PIXELS)
else if(z2 > z1 && rangeZAbove < 45){ //CHECK RANGE
changeentityproperty(self, "animation", openborconstant("ANI_JUMP")); //CHANGE ANIMATION
tossentity(self, 2, 0, -2);
}
//FIRE TRAP IS AT THE BOTTOM Z BOUNDARY AND ENEMY IS ABOVE (BETWEEN 45 AND 60 PIXELS)
else if(z2 > z1 && rangeZAbove > 45 && rangeZBelow < 60){ //CHECK RANGE
changeentityproperty(self, "aimove", openborconstant("AIMOVE1_AVOID"));
}
else
{
//ANY OTHER SITUATION BUT THE NEAREST TARGET IS THE FIRE TRAP
changeentityproperty(self, "aimove", openborconstant("AIMOVE1_NORMAL"));
}
}
}
else
{
//ANY OTHER SITUATION
changeentityproperty(self, "aimove", openborconstant("AIMOVE1_CHASE"));
}
}
