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);
}
getentityproperty(self, "animationID") == openborconstant(ani)
target != NULL() && getentityproperty(target, "animationID") == openborconstant(ani)
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);
}
}
}
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
}
}
}
magggas said:but the whole method is still somehow unstable with more enemies on screen![]()