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

    if(target!=NULL()){
      float Tx = getentityproperty(target, "x");
      float Tz = getentityproperty(target, "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);
        }
        changeentityproperty(self, "animation", openborconstant(Ani)); //Change the animation
      }
    }
}








