void main() {
void self = getlocalvar("self");
attack_grabbed_player(self,-80,80,-40,40,"ANI_FOLLOW20",12);
}
void attack_grabbed_player(void self, float rangex_min, float rangex_max, float rangez_min, float rangez_max, char atk_anim_name, int t_dist) {
void target = findtarget(self); // locked opponent
float x = getentityproperty(self, "x");
float z = getentityproperty(self, "z");
int dir = getentityproperty(self,"direction");
if( target != NULL() && getentityproperty(target,"exists") ){
int anim_id = getentityproperty(self,"animationid");
float speed = getentityproperty(self,"speed");
int tdir = getentityproperty(target,"direction");
float tx = getentityproperty(target, "x");
float tz = getentityproperty(target, "z");
int tanim_id = getentityproperty(target,"animationid");
int xfact = 1, zfact = 1;
if ( t_dist == NULL() ) t_dist = 12;
// to fix the direction range
if ( x < tx ) xfact *= -1;
else {
float tmp;
tmp = rangex_min;
rangex_min = rangex_max;
rangex_max = tmp;
}
if ( z < tz ) zfact *= -1;
else {
float tmp;
tmp = rangez_min;
rangez_min = rangez_max;
rangez_max = tmp;
}
if( tanim_id == openborconstant("ANI_GRABBED") ) {
if ( x >= tx+xfact*rangex_max && x <= tx+xfact*rangex_min && z >= tz+zfact*rangez_max && z <= tx+zfact*rangez_min ) {
if ( tdir && x < tx+t_dist ) {
if ( anim_id != openborconstant("ANI_WALK") ) changeentityproperty(self,"animation",openborconstant("ANI_WALK"));
changeentityproperty(self,"velocity",speed,NULL(),NULL());
} else if ( !tdir && x > tx+t_dist ) {
if ( anim_id != openborconstant("ANI_WALK") ) changeentityproperty(self,"animation",openborconstant("ANI_WALK"));
changeentityproperty(self,"velocity",-1*speed,NULL(),NULL());
} else {
changeentityproperty(self,"direction",!tdir);
performattack(self,openborconstant(atk_anim_name),1);
}
}
}
}
}