void regdora2(int Rx, int Rz, float Velx, float Velz)
{// Riseattack with range check + targetting
    void self = getlocalvar("self");
    void target = findtarget(self); //Get nearest player
     void parent = getentityproperty(self, "parent");
    float x = getentityproperty(self, "x");
    float z = getentityproperty(self, "z");






        int  iEntity; 
        void vEntity;
        int  iMax        = openborvariant("ent_max");   
       
        


        for(iEntity=0; iEntity<iMax; iEntity++)
            {        
           vEntity = getentity(iEntity);

                if( getentityproperty(vEntity, "model")=="Doras3")
                   
                  {
        

      
      float Tx = getentityproperty(vEntity, "x");
      float Tz = getentityproperty(vEntity, "z");
      float Disx = Tx - x;
      float Disz = Tz - z;

      if(Disx < 0){
        Disx = -Disx;
      }
      if(Disz < 0){
        Disz = -Disz;
      }

      if( Disx <= Rx && Disz <= Rz ) // Target within range?
      {
        if(Tx < x){
          changeentityproperty(self, "direction", 0);
        } else {
          changeentityproperty(self, "direction", 1);
        }

        if(Disz < Disx)
        {
          if(Tx < x){
            setlocalvar("x"+self, -Velx);
          } else { setlocalvar("x"+self, Velx); }

          setlocalvar("z"+self, Velx*(Tz-z)/Disx);
        } else {
          if(Tz < z){
            setlocalvar("z"+self, -Velz);
          } else { setlocalvar("z"+self, Velz); }

          setlocalvar("x"+self, Velz*(Tx-x)/Disz);
        }
        
      }
    }

}
}








