void main()
{
    int iPlIndex = getlocalvar("player"); //Get calling player
    void vSelf = getplayerproperty(iPlIndex , "entity"); //Get calling entity
    void vAniID = getentityproperty(vSelf,"animationID"); //Get current animation ID
//    void vAniPos = getentityproperty(vSelf, "animpos"); //Get current animation frame
    int iDir = getentityproperty(vSelf, "direction");  //Get current facing direction
    int iVx = getentityproperty(vSelf, "xdir");
//    int iVy = getentityproperty(vSelf, "tossv");

    void iUp = playerkeys(iPlIndex, 1, "moveup"); // New key status of "Up"
    void iDown = playerkeys(iPlIndex, 1, "movedown"); // New key status of "Down"
    void iLeft = playerkeys(iPlIndex, 1, "moveleft"); // New key status of "Left"
    void iRight = playerkeys(iPlIndex, 1, "moveright"); // New key status of "Right"
    void iJump = playerkeys(iPlIndex, 1, "jump"); //New key status of "Jump"
    void iSpecial = playerkeys(iPlIndex, 1, "Special"); //New key status of "Special"
    void iAttack = playerkeys(iPlIndex, 1, "attack"); //New key status of "Attack"
    void iAttack2 = playerkeys(iPlIndex, 1, "attack2"); // New key status of "Attack 2"
    void iAttack3 = playerkeys(iPlIndex, 1, "attack3"); // New key status of "Attack 3"
    void iAttack4 = playerkeys(iPlIndex, 1, "attack4"); // New key status of "Attack 4"

    void iUpR = playerkeys(iPlIndex, 2, "moveup"); // Release status of "Up"
    void iDownR = playerkeys(iPlIndex, 2, "movedown"); // Release status of "Down"
    void iLeftR = playerkeys(iPlIndex, 2, "moveleft"); // Release status of "Left"
    void iRightR = playerkeys(iPlIndex, 2, "moveright"); // Release status of "Right"
    void iAttackR = playerkeys(iPlIndex, 2, "attack"); //Release status of "Attack"

    void iDownH = playerkeys(iPlIndex, 0, "movedown");
    void iUpH = playerkeys(iPlIndex, 0, "moveup");
    void iLeftH = playerkeys(iPlIndex, 0, "moveleft");
    void iRightH = playerkeys(iPlIndex, 0, "moveright");

//Move while flying
    if(vAniID == openborconstant("ANI_FOLLOW1") ){ //In proper animations?
      if(iLeft && iDir==1 && iVx >= 2){ //Left pressed while facing right?
        changeentityproperty(vSelf, "velocity", iVx, 0, 0);
        performattack(vSelf, openborconstant("ANI_FOLLOW2"));
      } else if(iRight && iDir==0 && iVx <= -2){ //Right pressed while facing left?
        changeentityproperty(vSelf, "velocity", iVx, 0, 0);
        performattack(vSelf, openborconstant("ANI_FOLLOW2"));
      }

      if(iUpR || iDownR){ //Up or Down released?
        if(!iUpH && !iDownH){ //Up and Down not pressed?
          changeentityproperty(vSelf, "velocity", iVx, 0, 0);
        }
      } else if(iUp){ //Up pressed?
        if( (iDir==1 && iVx >= 2) || (iDir==0 && iVx <= -2) ){ //Enough speed?
          changeentityproperty(vSelf, "velocity", iVx, 0, 1.5);
          changeplayerproperty(vSelf, "playkeys", 0);
        }
      } else if(iDown){ //Down pressed?
        changeentityproperty(vSelf, "velocity", iVx, 0, -1.5);
        changeplayerproperty(vSelf, "playkeys", 0);
      }
    }
}