void key2ani(char ani, int sp, char key1, char key2)
{//msmalik681 change animation based on key press or combination
//key inputs: "moveup" "movedown" "moveforward" "moveback" "attack" "attack2" "attack3" "attack4" "jump"
//press: 3=holding 1=press 2=release default holding.
void self = getlocalvar("self");
int current_sp = getentityvar(self,"sp");
int dir = getentityproperty(self, "direction"); //Get current facing direction
if(key1=="moveforward"){key1 = dir==0?"moveleft":"moveright";}
if(key1=="moveback"){key1 = dir==0?"moveright":"moveleft";}
if(key2=="moveforward"){key2 = dir==0?"moveleft":"moveright";}
if(key2=="moveback"){key2 = dir==0?"moveright":"moveleft";}
if(key2){// check combination key press
if ( playerkeys(getentityproperty(self,"playerindex"), 3, key1) && playerkeys(getentityproperty(self,"playerindex"), 3, key2) ) {
if( sp && current_sp >= sp ){
setentityvar(self,"sp",sp - current_sp);
} else if ( sp && current_sp < sp ){ return 0; }
changeentityproperty(self, "velocity", 0, 0, 0); //Stop moving!
performattack (self, openborconstant("ani_" + ani)); //Change the animation.
}
} else {// check single key press
if ( playerkeys(getentityproperty(self,"playerindex"), 3, key1) ) {
if( sp && current_sp >= sp ){
setentityvar(self,"sp",sp - current_sp);
} else if ( sp && current_sp < sp ){ return 0; }
changeentityproperty(self, "velocity", 0, 0, 0); //Stop moving!
performattack (self, openborconstant("ani_" + ani)); //Change the animation.
}
}
}