Solved Hostile towards alias or name

Question that is answered or resolved.

PS_VITA

Active member
Can the Hostile option be used for a specific target with or without an alias?

For example change an enemy to only target and be hostile to Billy2.
 

DCurrent

Site Owner, OpenBOR Project Leader
Staff member
@PS_VITA,

The Hostile/Candamage/Projectilehit properties only work on types, but you can use the custom_target entity property to force an entity to target another specific entity. So if you wanted to target a player with the name "Bob", you'll need to set the Hostile and Candamage properties to include Player types, then get the entity pointer for "Bob" and place it into custom_target.

From there it's just a matter of putting in the logic to decide how you populate the property (alias, palette, whatever...).

HTH,
DC
 

PS_VITA

Active member
Thanks @DCurrent , I searched the forum for custom_target and I'm not finding many topics with examples so this might take me some time to figure out.

I'm pretty sure the question is solved but please give me some time before I change the status of the topic.
 

PS_VITA

Active member
I couldn't really use or come up with a script that made sense using custom_target. What ended up working for me is adjusting the stealth values for two enemies that ended up fighting each other.

I'm marking the topic as solved.
 

Kratus

OpenBOR Developer
Staff member
@PS_VITA

As an alternative, you can work with @Bloodbane's idea for "factions" script. This way you can have multiple cpu controlled entity types instead of having only enemy/npc as valid ones, plus you don't need to use aliases for that.

Note that you still need to put the entity type in the character's header to inherit the behavior, but once he spawns you can add a script to immediately change the type. As a suggestion you can create an "onspawn" script for that or put it on an inline script at the spawn animation.

For example, in SORX I have some npc entities that are used for decoration purposes. However, the cpu partners already are npcs too and the enemy are hostile to them.

To prevent enemies attacking decoration entitites, all of them have an "onspawn" script to change its type as soon as they spawn on the level. I don't change the stealth factor because I'm using it for "item detection" by enemies, so the factions script worked fine for my purpose.

C:
//START THE VARIABLE TO BE USED BY ANY SCRIPT, YOU CAN PUT ON A GLOBAL EVENT LIKE LEVEL.C, UPDATED.C, ETC...
setglobalvar("LEVEL_ENTITY", 65536);

//USE THE PREVIOUS CREATED VARIABLE TO CUSTOM TARGET'S HOSTILE/CANDAMAGE, YOU CAN PUT ON A ENTITY EVENT, LIKE ONSPAWN, ONDRAW, ETC...
changeentityproperty(self, "hostile", getglobalvar("LEVEL_ENTITY"));
changeentityproperty(self, "candamage", getglobalvar("LEVEL_ENTITY"));
 
Last edited:

PS_VITA

Active member
@PS_VITA

As an alternative, you can work with Bloodbane's idea for "factions" script. This way you can have multiple cpu controlled entity's types instead of having only enemy/npc as valid ones, plus you don't need to use aliases for that.

Note that you still need to put the entity type in the character's header to inherit the behavior, but once he spawns you can add a script to immediately change the type. As a suggestion you can create an "onspawn" script for that or put it on an inline script at the spawn animation.

For example, in SORX I have some npc entities that are used for decoration purposes. However, the cpu partners already are npcs too and the enemy are hostile to them.

To prevent enemies attacking decoration entitites, all of them have an "onspawn" script to change its type as soon as they spawn on the level. I don't change the stealth factor because I'm using it for "item detection" by enemies, so the factions script worked fine for my purpose.

C:
//START THE VARIABLE TO BE USED BY ANY SCRIPT, YOU CAN PUT ON A GLOBAL EVENT LIKE LEVEL.C, UPDATED.C, ETC...
setglobalvar("LEVEL_ENTITY", 65536);

//USE THE PREVIOUS CREATED VARIABLE TO CUSTOM TARGET'S HOSTILE/CANDAMAGE, YOU CAN PUT ON A ENTITY EVENT, LIKE ONSPAWN, ONDRAW, ETC...
changeentityproperty(self, "hostile", getglobalvar("LEVEL_ENTITY"));
changeentityproperty(self, "candamage", getglobalvar("LEVEL_ENTITY"));
@Kratus That's that pretty Interesting, I will do some more research and see how this recommendation works. Thank you!

And Thanks to @Bloodbane as well.
 

PS_VITA

Active member
Mmm.... :unsure:, what will that enemy do when there's no Billy2 at all?
That was a random example lol.
In actuality, I made an Enemy that is hostile towards the player but upon reaching a certain point of the screen and triggering a new enemy, both enemies target each other until one dies and than whatever enemy doesn't die goes after the players.
 

magggas

Active member
For this, when the new enemy appears, he just need an anmation script on his spawn animation that changes the hostile for both enemies. Then use the same script on the looser death animation to revert the winner's hostile setting back to normal. Here is an example of such script:

Code:
void candam(int Rx, int Rz)
{
    void self = getlocalvar("self");
    float x = getentityproperty(self, "x");
    float z = getentityproperty(self, "z");

    void vEntity;                                       //Target entity placeholder.
    int  iEntity;                                       //Entity enumeration holder.
    int  iName;                                         //Entity name.
    int  iMax      = openborvariant("ent_max");         //Entity count.

    float Tx;
    float Tz;
    float Disx;
    float Disz;

    //Enumerate and loop through entity collection.
    for(iEntity=0; iEntity<iMax; iEntity++){
      vEntity = getentity(iEntity);                 //Get target entity from current loop.
      iName   = getentityproperty(vEntity, "defaultname"); //Get target name

      if(iName == "ball3" || iName == "barel3" || iName == "box3" || iName == "boxx3" || iName == "rock3" || iName == "wood3"
        || iName == "ball" || iName == "barel" || iName == "box" || iName == "boxx" || iName == "rock" || iName == "wood"
        || iName == "knife2" || iName == "dynam2" || iName == "bomb" || iName == "bomb2" || iName == "boxx1" || iName == "boxx2"){
        Tx = getentityproperty(vEntity, "x");
        Tz = getentityproperty(vEntity, "z");
        Disx = Tx - x;
        Disz = Tz - z;

        if(Disx >= -Rx && Disx <= Rx && Disz >= -Rz && Disz <= Rz){
          changeentityproperty(vEntity, "hostile", openborconstant("TYPE_ENEMY"));
          changeentityproperty(vEntity, "candamage", openborconstant("TYPE_ENEMY"));
        }
      }
    }
}

This script checks for specific entities names, just edit those and remove the the rest names there. In my game there are tons of variations of this script, for example if you want it to check the entity type instead of the name, you get the idea.
Oh and one more thing i forgot, this script does not care if the entity uses alias, it checks and still indetifies an entity by its default name anyway.
 
Last edited:

PS_VITA

Active member
For this, when the new enemy appears, he just need an anmation script on his spawn animation that changes the hostile for both enemies. Then use the same script on the looser death animation to revert the winner's hostile setting back to normal. Here is an example of such script:

Code:
void candam(int Rx, int Rz)
{
    void self = getlocalvar("self");
    float x = getentityproperty(self, "x");
    float z = getentityproperty(self, "z");

    void vEntity;                                       //Target entity placeholder.
    int  iEntity;                                       //Entity enumeration holder.
    int  iName;                                         //Entity name.
    int  iMax      = openborvariant("ent_max");         //Entity count.

    float Tx;
    float Tz;
    float Disx;
    float Disz;

    //Enumerate and loop through entity collection.
    for(iEntity=0; iEntity<iMax; iEntity++){
      vEntity = getentity(iEntity);                 //Get target entity from current loop.
      iName   = getentityproperty(vEntity, "defaultname"); //Get target name

      if(iName == "ball3" || iName == "barel3" || iName == "box3" || iName == "boxx3" || iName == "rock3" || iName == "wood3"
        || iName == "ball" || iName == "barel" || iName == "box" || iName == "boxx" || iName == "rock" || iName == "wood"
        || iName == "knife2" || iName == "dynam2" || iName == "bomb" || iName == "bomb2" || iName == "boxx1" || iName == "boxx2"){
        Tx = getentityproperty(vEntity, "x");
        Tz = getentityproperty(vEntity, "z");
        Disx = Tx - x;
        Disz = Tz - z;

        if(Disx >= -Rx && Disx <= Rx && Disz >= -Rz && Disz <= Rz){
          changeentityproperty(vEntity, "hostile", openborconstant("TYPE_ENEMY"));
          changeentityproperty(vEntity, "candamage", openborconstant("TYPE_ENEMY"));
        }
      }
    }
}

This script checks for specific entities names, just edit those and remove the the rest names there. In my game there are tons of variations of this script, for example if you want it to check the entity type instead of the name, you get the idea.
Oh and one more thing i forgot, this script does not care if the entity uses alias, it checks and still indetifies an entity by its default name anyway.
@magggas
For this, when the new enemy appears, he just need an anmation script on his spawn animation that changes the hostile for both enemies. Then use the same script on the looser death animation to revert the winner's hostile setting back to normal. Here is an example of such script:

Code:
void candam(int Rx, int Rz)
{
    void self = getlocalvar("self");
    float x = getentityproperty(self, "x");
    float z = getentityproperty(self, "z");

    void vEntity;                                       //Target entity placeholder.
    int  iEntity;                                       //Entity enumeration holder.
    int  iName;                                         //Entity name.
    int  iMax      = openborvariant("ent_max");         //Entity count.

    float Tx;
    float Tz;
    float Disx;
    float Disz;

    //Enumerate and loop through entity collection.
    for(iEntity=0; iEntity<iMax; iEntity++){
      vEntity = getentity(iEntity);                 //Get target entity from current loop.
      iName   = getentityproperty(vEntity, "defaultname"); //Get target name

      if(iName == "ball3" || iName == "barel3" || iName == "box3" || iName == "boxx3" || iName == "rock3" || iName == "wood3"
        || iName == "ball" || iName == "barel" || iName == "box" || iName == "boxx" || iName == "rock" || iName == "wood"
        || iName == "knife2" || iName == "dynam2" || iName == "bomb" || iName == "bomb2" || iName == "boxx1" || iName == "boxx2"){
        Tx = getentityproperty(vEntity, "x");
        Tz = getentityproperty(vEntity, "z");
        Disx = Tx - x;
        Disz = Tz - z;

        if(Disx >= -Rx && Disx <= Rx && Disz >= -Rz && Disz <= Rz){
          changeentityproperty(vEntity, "hostile", openborconstant("TYPE_ENEMY"));
          changeentityproperty(vEntity, "candamage", openborconstant("TYPE_ENEMY"));
        }
      }
    }
}

This script checks for specific entities names, just edit those and remove the the rest names there. In my game there are tons of variations of this script, for example if you want it to check the entity type instead of the name, you get the idea.
Oh and one more thing i forgot, this script does not care if the entity uses alias, it checks and still indetifies an entity by its default name anyway.
@magggas thank you so much for this example as I've been learning of your double dragon game ever since I joined this forum and since you gave me permission to post the ps vita version double dragon back in the gbatemp website.

I have grown to admire your work even more as time has passed by.
 
Top Bottom