teletarget script help

Not tested it but this should do the trick.

Code:
void teleportIf(int dx, int dy, int dz, char ani, int rX, int rZ, int rA){
	void self = getlocalvar("self");
	int dir = getentityproperty(self,"direction");
	float x = getentityproperty(self, "x");
	float z = getentityproperty(self, "z");
	float a = getentityproperty(self, "a");
	void target = findtarget(self);
	
	if(target != NULL() && getentityproperty(target, "animationID") == openborconstant(ani) && isInRange(self,dir,target,rX,rZ,rA,x,z,a, 1)){
		teletarget(dx, dy, dz);
	}
}


int isBetweenRange(void self,int dir,void target,int rxMin, int rxMax, int rzMin, int rzMax, int raMin, int raMax, float x,float z,float a){
	float Tx = getentityproperty(target, "x");
	float Tz = getentityproperty(target, "z");
	float Ta = getentityproperty(target, "a");
	float Disx;
	float Disz = Tz - z;
	float Disa = Ta - a;

	if (dir==0){
		Disx = x - Tx;
	}else{
		Disx = Tx - x;
	}
	

	if(Disz < 0){
		Disz = -Disz;
	}
	if(Disa < 0){
		Disa = -Disa;
	}
	
	
	//log("\nTa = " + Ta + " ; Disa = " + Disa);
	//log("\nTx = " + Tx + " ; Disx = " + Disx);
	
	if(rxMax < rxMin){ // Is out of range
		
		if( (Disx >= rxMin || Disx < rxMax) && Disz <= rzMax && Disz >= rzMin && Disa<=raMax && Disa >= raMin) return 1;
		else return 0;
		
	} else if( Disx <= rxMax && Disx > rxMin && Disz <= rzMax && Disz >= rzMin && Disa<=raMax && Disa >= raMin){
		return 1;
	}else{
		return 0;
	}
	
}

int isInRange(void self,int dir,void target,int Rx, int Rz,int Ra,float x,float z,float a, int searchBack){
	if(searchBack) return isBetweenRange(self, dir, target, -Rx, Rx, -Rz, Rz, 0, Ra, x, z, a);
	else return isBetweenRange(self, dir, target, 0, Rx, 0, Rz, 0, Ra, x, z, a);
}
 
Well it's missing the teletarget function you included in your first post. The call is wrapped in teleportIf.

I'll test it myself to see if it works, but anyway I misunderstood the animation condition so it won't work like this.

Code:
getentityproperty(self, "animationID") == openborconstant(ani)


needs to be :
Code:
target != NULL() && getentityproperty(target, "animationID") == openborconstant(ani)

Edit : tested, works for me.
 
ive also made one...?!?
getentityproperty(target, "animationID") above made it work...

ive used the @cmd attack 1 script
void targetani(int RxMin, int RxMax, int Rz, void Ani)
{// Attack interruption with range check
    void self = getlocalvar("self");
    void target = findtarget(self); //Get nearest player
    float x = getentityproperty(self, "x");
    float z = getentityproperty(self, "z");
    int dir = getentityproperty(self, "direction");

setlocalvar("T"+self, findtarget(self)); //Get nearest player


    if( getlocalvar("T"+self) != NULL()){
      void target = getlocalvar("T"+self);
      float Tx = getentityproperty(target, "x");
      float Tz = getentityproperty(target, "z");
      float Disx = Tx - x;
      float Disz = Tz - z;

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


      if( getentityproperty(target, "animationID") == openborconstant(Ani) && Disx >= RxMin && Disx <= RxMax && Disz <= Rz && dir == 1)
      {
        changeentityproperty(self, "position", Tx, Tz, 0);


      } else if( getentityproperty(target, "animationID") == openborconstant(Ani) && Disx >= -RxMax && Disx <= -RxMin && Disz <= Rz && dir == 0) // Target within range on left facing?
      {
        changeentityproperty(self, "position", Tx, Tz, 0);
      }
    }
}


@cmd targetani 10 150 30 "ANI_WALK"


 
haa is for a ground attack ?
I think is best not to use it with the target script it has ranges that go for all enemies

ive made this one its very simple to use
its from the @cmd attack1

it checks the enemie offset coordinates
range X min / range X max
range A min / range A max
range Z
ive added a range A (altitude) this is because if the enemie is on fall animation he could be flying in the air so its best to chack the altitude like min 0 pixel max 1 pixel altitude - when the enemy is on 1 pixel altitude or 0 the player makes the attack

ive also added a direction for enemy (DIR2) it means the player must be facing the same direction the enemy is... if he is he makes the attack
void attackgrd(int RxMin, int RxMax, int RaMin, int RaMax, int Rz, void Ani, void Ani2)
{// Attack interruption with range check
    void self = getlocalvar("self");
    void target = findtarget(self); //Get nearest player
    float x = getentityproperty(self, "x");
    float a = getentityproperty(self, "a");
    float z = getentityproperty(self, "z");
    int dir = getentityproperty(self, "direction");

    if(target!=NULL()){
      float Tx = getentityproperty(target, "x");
      float Ta = getentityproperty(target, "a");
      float Tz = getentityproperty(target, "z");
      float dir2 = getentityproperty(target, "direction");

      float Disx = Tx - x;
      float Disa = Ta - a;
      float Disz = Tz - z;

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

      if( getentityproperty(target, "animationID") == openborconstant(Ani2) && Disx >= RxMin && Disx <= RxMax && Disa >= RaMin && Disa <= RaMax && Disz <= Rz && dir == 1 && dir2 == 0) // Target within range on right facing in animation "Ani2"
      {
        performattack(self, openborconstant(Ani)); //Change player animation


      } else if( getentityproperty(target, "animationID") == openborconstant(Ani2) && Disx >= -RxMax && Disx <= -RxMin && Disa >= RaMin && Disa <= RaMax && Disz <= Rz && dir == 0 && dir2 == 1) // Target within range on left facing in animation "Ani2"
      {
        performattack(self, openborconstant(Ani)); //Change player animation
      }
    }
}

you can use it in player attack 1 or walk animation
@cmd attackgrd -60 60 0 1 15 "ANI_FOLLOW6" "ANI_FALL"


-ani_follow6 makes the player attack
-ani_fall is the enemy animation
0 and 1 is altitude min 0 and max 1

in my player ive set the jumpattack to staydown 50000 300
when it hits the enemy he stays down in last frame fall 4 50000 delay

you could try diferent staydown times for the player attacks
for example when billy headbutts the opponent he stays down more time then ussually
 
magggas said:
but the whole method is still somehow unstable with more enemies on screen  :(

Yes the main problem here is that findtarget just return the nearest target, which is not necessarily the enemy you just knocked down. What you can do to solve this is :

- store the target you hit in didhitscript as an entityvar.
- in teleportIf function, retrieve that target. If it's still alive, use it as target reference, otherwise cancel the move or find another target with findtarget.
 
You can also get your current opponent. It will always be who you just knocked down until you interact with someone else.

Code:
void ent = getlocalvar("self");

void target = getentityproperty(ent, "opponent");

DC
 
Getting "opponent" property as target is a better choice.

But just pasting the lines won't work because self variable is called ent.

Code:
 void target = getentityproperty(self, "opponent");
 
Back
Top Bottom