How to make an enemy chases a specific player

brikinhos

New member
Hi all, I would like to make a boss that seems like a doppleganger from Captain Commando. In this game, each dopple chases the player who is a copy of it. The question is: It's is possible to make an enemy chases a specific player? For example, dopple_1 chases player1. Thanks in advance.
 
Sure. It does requires some script to do that, but we can help out if you're not familiar.

Code:
changeentityproperty(<entity>, "aitarget", <target entity>)

DC

 
I used this line:  changeentityproperty(entity, "aitarget", target_entity); but game crashed before start. I opened log file and I see this: Property name 'aitarget' is not supported by function getentityproperty.

I never use getentityproperty with "aitarget", I'm sure about it 100%, and "aitarget" is not documented in OpenBOR Legacy Manual. :-\
 
How would that work?
This doesnt make self entity to chase batman, or this isnt the way to use it?

Code:
	@script
    void self = getlocalvar("self");			//Caller.
    if(frame ==1){
      void vEntity;                                       //Target entity placeholder.
      int  iEntity;                                       //Entity enumeration holder.
      char iName;                                         //Entity Name.
      int  iMax      = openborvariant("count_entities");         //Entity count.

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

        if( frame == 2 ){
  changeentityproperty(self, "custom_target", (iName == "batman") );
        }
    }
	    }
@end_script

--------
Ok this works , just get rid of text object
Code:
@script
    if(frame==1){
      void vEntity;                                     //Target entity placeholder.
      int  iEntity;                                     //Entity enumeration holder.
      int  iName;                                       //Entity type.
      int  iHP;                                         //Entity HP
      int  iMax      = openborvariant("ent_max");       //Entity count.
    void self = getlocalvar("self");
       //Enumerate and loop through entity collection.
      for(iEntity=0; iEntity<iMax; iEntity++){    
        vEntity = getentity(iEntity);                 //Get target entity from current loop.
        iName   = getentityproperty(vEntity, "name"); //Get target type.
        //Enemy type?
        if (iName == "BATMAN" ){
 settextobj(1, 450-openborvariant("xpos") , 380-openborvariant("ypos") , 0, -1, iName , openborvariant("elapsed_time")+200);
   changeentityproperty(self, "custom_target", vEntity );
      }
  }
    }
@end_script
 
Just a reminder: when you set a custom_target, the entity will only try to attack that target, no matter what, as far I can remember from DC's explanation.
Even if there is a valid target on range, the entity will ignore it and will try to attack the custom target instead.

I don't know what happens if the custom_target dies - what the entity will do?
 
Custom target does nothing more than override the routines AI uses to select a target. Nothing affects this property... only script. The engine never sets it, and never unsets it.

I haven't experimented with killing the target, but see above, the custom target value won't be affected in any way. So most likely the entity will stand doing nothing or just wander around as if there'snothing for it to fight.

DC
 
Good point, additional checks need to be made if target exists, nullifying custom taret will revert ai back to attacking others ? Or theres other property that needs to be changed to do that ?
 
All you need to do is set the custom target to null. The entity will immediately resume automated target selection and behave normally.

DC
 
Back
Top Bottom