enemy target nearest enemy

hi every one

big ben has a move in street of rage 3 that he targets nearest galsia and walked to him then grab galsia and throw him over player
if i can target nearest enemy i can get his pos X and pos Z and then force big ben to move toward him and start his move.

can someone tell me how i can target nearest enemy to big ben?

ty
 
Solution
ty for your replay
but enemie only targeting the player it does not target other enemies i tried it .it isn't working
By default enemies will target players, but you can change it by setting the "hostile" property using an animation script as soon as the enemy starts a defined animation.

Code:
void changeHostile(void type)
{
        void self = getlocalvar("self");
        changeentityproperty(self, "hostile", type);
}

Code:
anim attack5 #GRAB
    range 20 60
    rangea 0 100
    rangeb 0 100
    fastattack 1
    jugglecost 0
    forcedirection 0
    otg 1
    loop    0
    delay    12
    offset    144 175
    bbox     126 102 36 75
    @cmd hitfx "None.wav"
    @cmd sound "HighAttack.wav"
    @cmd changeHostile "type_enemy"...
ty for your replay
but enemie only targeting the player it does not target other enemies i tried it .it isn't working
By default enemies will target players, but you can change it by setting the "hostile" property using an animation script as soon as the enemy starts a defined animation.

Code:
void changeHostile(void type)
{
        void self = getlocalvar("self");
        changeentityproperty(self, "hostile", type);
}

Code:
anim attack5 #GRAB
    range 20 60
    rangea 0 100
    rangeb 0 100
    fastattack 1
    jugglecost 0
    forcedirection 0
    otg 1
    loop    0
    delay    12
    offset    144 175
    bbox     126 102 36 75
    @cmd hitfx "None.wav"
    @cmd sound "HighAttack.wav"
    @cmd changeHostile "type_enemy"
    frame    data/chars/enemies/bongo/a100.gif
    frame    data/chars/enemies/bongo/a101.gif
    attack 148 110 46 18 0 0 1 0 0 12
    frame    data/chars/enemies/bongo/a102.gif
    attack 0 0 0 0 0 0 0 0 0 0
    frame    data/chars/enemies/bongo/a103.gif

At this point you have two options:

1) Add a target script and forces the bigben to move by changing your animation and velocity property
Code:
void target(float Velx, float Velz)
{//Targetting opponent before leaping or dashing (REDUCED TARGET SCRIPT)
 //Check subtype and player minZ to avoid targeting decoration enemies, like Shiva/Mr.X waiting to fight in the last stage
    void self       = getlocalvar("self");
    void found      = findtarget(self);
    void subType    = getentityproperty(found, "subtype");
    int dir         = getentityproperty(self, "direction");
    float x         = getentityproperty(self, "x");
    float z         = getentityproperty(self, "z");
    float fZ        = getentityproperty(found, "z");
    float minZ      = openborvariant("player_min_z");
    
    if(subType != openborconstant("SUBTYPE_NOTGRAB")){
        if(fZ >= minZ){
            setlocalvar("target"+self, found); //PUT FOUND TARGET IN LOCAL VARIABLE
        }
    }
    //IS THERE A TARGET?
    if(getlocalvar("target"+self) != NULL()){
        void target = getlocalvar("target"+self);
        float Tx    = getentityproperty(target, "x");
        float Tz    = getentityproperty(target, "z");
        float Disx  = Tx - x; //GET X DISTANCE
        float Disz  = Tz - z; //GET Z DISTANCE
        
        if(Disx < 0){ //NEGATIVE DISX?
            Disx = -Disx; //TURN IT TO POSITIVE
            changeentityproperty(self, "direction", 0); //FACE LEFT
        }
        else
        {
            changeentityproperty(self, "direction", 1); //FACE RIGHT
        }
        if(Disz < 0){ //NEGATIVE DISZ?
            Disz = -Disz; //TURN IT TO POSITIVE
        }
        if(Disz < Disx){ //DISX BIGGER THAN DISZ?
            if(Tx < x){ //PLAYER IS BEHIND ENEMY?
                setlocalvar("x"+self, -Velx); //TURN VX TO NEGATIVE
            }
            else
            {
                setlocalvar("x"+self, Velx);  //USE DEFINED VX
            }
            setlocalvar("z"+self, Velx*(Tz-z)/Disx); //CALCULATE VZ THEN STORE VALUE IN LOCAL VARIABLE
        }
        else
        { //DISZ BIGGER THAN DISX!
            if(Tz < z){ //PLAYER IS BEHIND ENEMY?
                setlocalvar("z"+self, -Velz); //TURN VZ TO NEGATIVE
            }
            else
            {
                setlocalvar("z"+self, Velz); //USE DEFINED VZ
            }
            setlocalvar("x"+self, Velz*(Tx-x)/Disz); //CALCULATE VX THEN STORE VALUE IN LOCAL VARIABLE
        }
    }
    else //NO TARGET AT ALL!
    {
        setlocalvar("z"+self, 0); // ZERO VELOCITY
        if(dir == 0){ //FACING LEFT?
            setlocalvar("x"+self, -Velx); //NEGATIVE VELOCITY
        }
        else
        {
            setlocalvar("x"+self, Velx); //POSITIVE VELOCITY
        }
    }
}

void dashTarget()
{//Dash with previously attained speed by target script!
    void self   = getlocalvar("self");
    float Vx    = getlocalvar("x"+self);
    float Vz    = getlocalvar("z"+self);
    
    if(Vx != NULL() && Vz != NULL()){changeentityproperty(self, "velocity", Vx, Vz);}
}

Code:
anim attack5 #GRAB
    range 20 60
    rangea 0 100
    rangeb 0 100
    fastattack 1
    jugglecost 0
    forcedirection 0
    otg 1
    loop    0
    delay    12
    offset    144 175
    bbox     126 102 36 75
    @cmd hitfx "None.wav"
    @cmd sound "HighAttack.wav"
    @cmd changeHostile "type_enemy" #CHANGE HOSTILE
    frame    data/chars/enemies/bongo/a100.gif
    @cmd target 2 2 #GET THE NEAREST TARGET AND DEFINE THE DESIRED VELOCITY
    frame    data/chars/enemies/bongo/a101.gif
    @cmd dashTarget #MOVE TO THE PREVIOUS DEFINED TARGET
    frame    data/chars/enemies/bongo/a102.gif
    attack 0 0 0 0 0 0 0 0 0 0
    frame    data/chars/enemies/bongo/a103.gif

2) Increase the aggression and change your aimove to type "chase", and then bigben will automatically pursue the nearest enemy

Code:
changeentityproperty(self, "aimove", openborconstant("AIMOVE1_CHASE"));
changeentityproperty(self, "aggression", 200);

Remember that you will need to choose an animation to revert the "hostile" property to "type_player" again. As an suggestion you can do it when the bigben get any nearest Galsia and change your current animation to any other.
 
Solution
ty so much
you are a real genius to solve my problem with this strange solution
It will never cross my mind that i can change enemy hostility to make him target other enemies
big like for you
By default enemies will target players, but you can change it by setting the "hostile" property using an animation script as soon as the enemy starts a defined animation.

Code:
void changeHostile(void type)
{
        void self = getlocalvar("self");
        changeentityproperty(self, "hostile", type);
}

Code:
anim attack5 #GRAB
    range 20 60
    rangea 0 100
    rangeb 0 100
    fastattack 1
    jugglecost 0
    forcedirection 0
    otg 1
    loop    0
    delay    12
    offset    144 175
    bbox     126 102 36 75
    @cmd hitfx "None.wav"
    @cmd sound "HighAttack.wav"
    @cmd changeHostile "type_enemy"
    frame    data/chars/enemies/bongo/a100.gif
    frame    data/chars/enemies/bongo/a101.gif
    attack 148 110 46 18 0 0 1 0 0 12
    frame    data/chars/enemies/bongo/a102.gif
    attack 0 0 0 0 0 0 0 0 0 0
    frame    data/chars/enemies/bongo/a103.gif

At this point you have two options:

1) Add a target script and forces the bigben to move by changing your animation and velocity property
Code:
void target(float Velx, float Velz)
{//Targetting opponent before leaping or dashing (REDUCED TARGET SCRIPT)
 //Check subtype and player minZ to avoid targeting decoration enemies, like Shiva/Mr.X waiting to fight in the last stage
    void self       = getlocalvar("self");
    void found      = findtarget(self);
    void subType    = getentityproperty(found, "subtype");
    int dir         = getentityproperty(self, "direction");
    float x         = getentityproperty(self, "x");
    float z         = getentityproperty(self, "z");
    float fZ        = getentityproperty(found, "z");
    float minZ      = openborvariant("player_min_z");
   
    if(subType != openborconstant("SUBTYPE_NOTGRAB")){
        if(fZ >= minZ){
            setlocalvar("target"+self, found); //PUT FOUND TARGET IN LOCAL VARIABLE
        }
    }
    //IS THERE A TARGET?
    if(getlocalvar("target"+self) != NULL()){
        void target = getlocalvar("target"+self);
        float Tx    = getentityproperty(target, "x");
        float Tz    = getentityproperty(target, "z");
        float Disx  = Tx - x; //GET X DISTANCE
        float Disz  = Tz - z; //GET Z DISTANCE
       
        if(Disx < 0){ //NEGATIVE DISX?
            Disx = -Disx; //TURN IT TO POSITIVE
            changeentityproperty(self, "direction", 0); //FACE LEFT
        }
        else
        {
            changeentityproperty(self, "direction", 1); //FACE RIGHT
        }
        if(Disz < 0){ //NEGATIVE DISZ?
            Disz = -Disz; //TURN IT TO POSITIVE
        }
        if(Disz < Disx){ //DISX BIGGER THAN DISZ?
            if(Tx < x){ //PLAYER IS BEHIND ENEMY?
                setlocalvar("x"+self, -Velx); //TURN VX TO NEGATIVE
            }
            else
            {
                setlocalvar("x"+self, Velx);  //USE DEFINED VX
            }
            setlocalvar("z"+self, Velx*(Tz-z)/Disx); //CALCULATE VZ THEN STORE VALUE IN LOCAL VARIABLE
        }
        else
        { //DISZ BIGGER THAN DISX!
            if(Tz < z){ //PLAYER IS BEHIND ENEMY?
                setlocalvar("z"+self, -Velz); //TURN VZ TO NEGATIVE
            }
            else
            {
                setlocalvar("z"+self, Velz); //USE DEFINED VZ
            }
            setlocalvar("x"+self, Velz*(Tx-x)/Disz); //CALCULATE VX THEN STORE VALUE IN LOCAL VARIABLE
        }
    }
    else //NO TARGET AT ALL!
    {
        setlocalvar("z"+self, 0); // ZERO VELOCITY
        if(dir == 0){ //FACING LEFT?
            setlocalvar("x"+self, -Velx); //NEGATIVE VELOCITY
        }
        else
        {
            setlocalvar("x"+self, Velx); //POSITIVE VELOCITY
        }
    }
}

void dashTarget()
{//Dash with previously attained speed by target script!
    void self   = getlocalvar("self");
    float Vx    = getlocalvar("x"+self);
    float Vz    = getlocalvar("z"+self);
   
    if(Vx != NULL() && Vz != NULL()){changeentityproperty(self, "velocity", Vx, Vz);}
}

Code:
anim attack5 #GRAB
    range 20 60
    rangea 0 100
    rangeb 0 100
    fastattack 1
    jugglecost 0
    forcedirection 0
    otg 1
    loop    0
    delay    12
    offset    144 175
    bbox     126 102 36 75
    @cmd hitfx "None.wav"
    @cmd sound "HighAttack.wav"
    @cmd changeHostile "type_enemy" #CHANGE HOSTILE
    frame    data/chars/enemies/bongo/a100.gif
    @cmd target 2 2 #GET THE NEAREST TARGET AND DEFINE THE DESIRED VELOCITY
    frame    data/chars/enemies/bongo/a101.gif
    @cmd dashTarget #MOVE TO THE PREVIOUS DEFINED TARGET
    frame    data/chars/enemies/bongo/a102.gif
    attack 0 0 0 0 0 0 0 0 0 0
    frame    data/chars/enemies/bongo/a103.gif

2) Increase the aggression and change your aimove to type "chase", and then bigben will automatically pursue the nearest enemy

Code:
changeentityproperty(self, "aimove", openborconstant("AIMOVE1_CHASE"));
changeentityproperty(self, "aggression", 200);

Remember that you will need to choose an animation to revert the "hostile" property to "type_player" again. As an suggestion you can do it when the bigben get any nearest Galsia and change your current animation to any other.
 
Back
Top Bottom