Script to make enemies change anim when player in range

aL BeasTie

Well-known member
It seems I get worse at scripting rather than better :p

This is what I'm trying to do -

I'm trying to make an enemy that spawns and stays motionless until player approaches it (gets within range)

So the idea is too give the enemy a SPAWN anim that is looped so they don't move,
image.png


then @script  or animationscript in this animation to check if player is in range then change to ANI_FOLLOW2
image.png


This is my basic script but, I've tried numerous ways but this is basically what I have.

Code:
void alert()
{
void self = getlocalvar("self");
int player = getlocalvar("player");
int anim = getentityproperty(self, "animationid");
if(checkrange(self, player))
	{
	changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW2"), 1);
	}
}

Obviously this is very wrong...

Can someone please show me the proper way to do this?
 
Thanks!!
now I need to figure how to spawn that Williams on the net instead that on the floor, or just to hardcode and make the offset trick...

[attachment deleted by admin]
 
Okay, I almost got this working.

So I would like to have my enemy spawn in idle and wait for player to near then begin to attack.

I copied this into my stage.txt

spawn    zack
@script void main() {
  performattack(getlocalvar("self"), openborconstant("ANI_FOLLOW10"));
} @end_script
noatk_duration 100
map      1
alias    Ralph
health  80
coords  -30 240 2
at -20

I copied this into my enemy.txt

anim  spawn
@script
    void self = getlocalvar("self");
    int Enter = getentityvar(self, 6);

    if(frame==1){
      if(Enter==1){
        setentityvar(self, 6, NULL());
        changeentityproperty(self, "animation", openborconstant

("ANI_FOLLOW5"));
      } else if(Enter==2){
        setentityvar(self, 6, NULL());
        changeentityproperty(self, "animation", openborconstant

("ANI_FOLLOW6"));
      } else if(Enter==3){
        setentityvar(self, 6, NULL());
        changeentityproperty(self, "animation", openborconstant

("ANI_FOLLOW7"));
      }
    }
    if(frame==3){
      changeentityproperty(self, "Subject_to_Wall", 1);
    }
@end_script
loop 1
delay 15
offset 21 73
bbox 7 2 34 72
frame data/chars/zack/idle1.gif
frame data/chars/zack/idle2.gif

so what happens now is that the enemy spawns and does absolutely nothing no matter how close player goes near.

Please guide me how to accomplish this. What do I need to do or change?
I am fresh learning how to use the openbor scripts so please explain clearly.

Thank You
Dmolina007


 
For my mod Streets of Rage the Final Fight.



I would also like to have enemies spawn in different animations depending on the circumstance and proceed into combative move only when player nears.

Right now I placed enemies posted by the staircase in idle and would like them to follow and attack when player nears. They are stuck in idle and only snap out of it when they get attacked by player.

Once I can figure this out I could use the same concept to create some spawns as doors that bust open with enemy running out when player nears.

I am unsure what I need to change or do to get this working.

Do I have to add something to the Script.txt in the data folder?
 
Oh, you copied the wrong example.

This script:
@script void main() {
  performattack(getlocalvar("self"), openborconstant("ANI_FOLLOW10"));
} @end_script

is enough for changing starting animation for spawned entity.

To make enemies wait, setting looping SPAWN (or other starting) animation is enough but you need animationscript with attack1 function I've posted in first page to end the waiting status
Are you familiar with animationscript?
 
Back
Top Bottom