How to propely cancel into running animation

noob-MT

New member
I Frankenstein this script from sorx2.
I'm trying to make my character go into running animation when i double tap forwards. But the result is i lost control of the character and he just keep running indefinitely.
Could someone help me with this
Code:
void pressTwice()
{//Global registration when the player presses "Left or Right" directions twice before performs any running attack
 //This script will register the ">>" command as a single input to make some key script easier to develop
    void self      = getlocalvar("self");
    int iPIndex  = getentityproperty(self, "playerindex");
    int dir      = getentityproperty(self,"direction");
    float time     = openborvariant("elapsed_time");
    float delay     = 30;
    
    //STEP 1 - REGISTER "DIRECTIONAL" KEYS RELEASED
    if(playerkeys(iPIndex, 2, "moveleft") && dir == 0){
        setentityvar(self, "releaseLeft", time+delay);
    }
    if(playerkeys(iPIndex, 2, "moveright") && dir == 1){
        setentityvar(self, "releaseRight", time+delay);
    }

    //STEP 2 - CHECK IF THE CURRENTLY PRESSED KEY WAS RELEASED BEFORE WITH THE CORRECT DELAY AND REGISTER THE "DIRECTIONAL" KEYS PRESSED AGAIN
    if(playerkeys(iPIndex, 1, "moveleft") && dir == 0){
        if(getentityvar(self, "releaseLeft") > time){
            setentityvar(self, "pressLeft", time+delay);
            setentityvar(self, "releaseLeft", NULL());
        }
    }
    if(playerkeys(iPIndex, 1, "moveright") && dir == 1){
        if(getentityvar(self, "releaseRight") > time){
            setentityvar(self, "pressRight", time+delay);
            setentityvar(self, "releaseRight", NULL());
        }
    }
}

void runCancel()
{
    void self      = getlocalvar("self");
    void vAniID  = getentityproperty(self,"animationID");
    int iPIndex  = getentityproperty(self, "playerindex");
    float time     = openborvariant("elapsed_time");
    
    
    pressTwice();


    if(vAniID == openborconstant("ANI_ATTACK1")
        || vAniID == openborconstant("ANI_ATTACK3")
        || vAniID == openborconstant("ANI_ATTACK3"))
    {
        if(getentityvar(self, "pressLeft") > time
            || getentityvar(self, "pressRight") > time)
        {
        
                
                    
            //performattack(self, openborconstant("ANI_RUN"), 0);
            //changeentityproperty(self, "aiflag", "running", 1);

            //executeanimation(self, openborconstant("ANI_RUN"), 0);
            //changeentityproperty(self, "aiflag", "running", 1);

            changeentityproperty(self, "animation", openborconstant("ANI_RUN"));
            changeentityproperty(self, "aiflag", "running", 1);

            setentityvar(self, "pressLeft", NULL());
            setentityvar(self, "pressRight", NULL());                           
        }
    }
}
 
Back
Top Bottom