void targetentity(float xx, float zz, float dx, float dz, void type, char ent_name)
{ //@cmd targetentity 2 1 0 0 "ITEM" "horse-e"
float Velx=xx, Velz=zz, dx=0, dz=0;
void self = getlocalvar("self");
int dir = getentityproperty(self, "direction");
float x = getentityproperty(self, "x");
float z = getentityproperty(self, "z");
if (dir == 0) { dx = -dx; }else{}
void target = getlocalvar("Target" + self);
void i=0,found=0;
for(i=0; i<openborvariant("ent_max"); i++) {
void target = getentityproperty(self, "opponent");
void ent = getentity(i);
if((getentityproperty(ent,"exists"))
&& (!getentityproperty(ent,"dead"))
&& (getentityproperty(ent,"TYPE") == openborconstant("TYPE_"+type))
&& (getentityproperty(ent,"model") == ent_name))
{
setlocalvar("T"+self,ent);
if(ent==NULL())
{
setlocalvar("Target" + self, ent);
}
if(ent!=NULL())
{
float Tx = getentityproperty(ent, "x");
float Tz = getentityproperty(ent, "z");
if(Tx < x){
changeentityproperty(self, "direction", 0);
} else {
changeentityproperty(self, "direction", 1);
}
x = x+dx;
z = z+dz;
float Disx = Tx - x;
float Disz = Tz - z;
if(Disx < 0){ Disx = -Disx; }
if(Disz < 0){ Disz = -Disz; }
if(Disz < Disx) {
if(Tx < x){
found=1;
setlocalvar("x"+self, -Velx);
} else {
found=1;
setlocalvar("x"+self, Velx);
}
setlocalvar("z"+self, Velx*(Tz-z)/Disx);
} else {
if(Tz < z){
found=1;
setlocalvar("z"+self, -Velz);
} else {
found=1;
setlocalvar("z"+self, Velz);
}
setlocalvar("x"+self, Velz*(Tx-x)/Disz);
}
} else {
setlocalvar("z"+self, 0);
if(dir==0){
setlocalvar("x"+self, -Velx);
} else { setlocalvar("x"+self, Velx); }
}
float Vvx = getlocalvar("x"+self);
float Vvz = getlocalvar("z"+self);
if( Vvx!=NULL() && Vvz!=NULL() ) {
changeentityproperty(self, "velocity", Vvx, Vvz);
found=1;
}
}
}
if(!found){
changeentityproperty(self, "velocity", 0, 0, 0);
setidle(self);
}
}