Solved lose momentum

Question that is answered or resolved.

msmalik681

OpenBOR Developer
Staff member
I am trying to make a script to avoid losing momentum when using cancel with the "J" and "S" buttons.  I was thinking if I record the X and A velocity in a jump animation into a local variable then in the new animation I have cancelled into have a script load up the X and A variables and apply them to current animation.  This is not working it keeps crashing with error:

Script compile error in 'animationscript': Data line 36, column 4

********** An Error Occurred **********
*            Shutting Down            *

Can't compile script 'animationscript' data/chars/1asuka/asuka.txt


code for capturing velocity:

@script
{
void self = getlocalvar("self");
int x = getentityproperty(self, "velocity", x);
int a = getentityproperty(self, "velocity", a);
if (Data > 0)
{
setlocalvar("velx" + self, x);
setlocalvar("vela" + self, a);
}
}
@end_script


Code to apply velocity:

@script
{
void self = getlocalvar("self");
int x = getlocalvar("velx" + self);
int a = getlocalvar("vela" + self);
if (Data == 1)
{
changeentityproperty(self, "velocity", x, 0, a);
}
}
@end_script
 
You need to define where you get Data from

Also you should use keyscript for air cancel without losing momentum
 
"data" is what frame as this script is written straight onto frames files !

tried keyscripts and I dont like the way if you hold jump you cancel right into the air attack where as with cancel command you have to retap the jump button !
 
thanks for the help bloodbane you were right about the "data" it should have been "frame".

This has been driving me crazy for so long just fixed it if this code will help anyone else I decided to share!

here is the animation script:

void tossx(int rec)
{//keep momentum when canceling jumps with "J" and "S"
void self = getlocalvar("self");
int x = getlocalvar("tossx" + self);//make a local flag to set x speed
int dir = getentityproperty(self,"direction");//get direction
int id = getentityproperty(self, "animationid");//find what animation is being canceled

if ( rec != NULL() ){
if ( id == openborconstant("ANI_JUMP")){
setlocalvar("tossx" + self, 0);}
else if ( id == openborconstant("ANI_FORWARDJUMP")){
setlocalvar("tossx" + self, 1);}
else if ( id == openborconstant("ANI_RUNJUMP")){
setlocalvar("tossx" + self, 3);}
}
else{
    if(dir==0){ // Facing left?
      x = -x ;}
  {
tossentity(self, 0, x, 0);//set recorded x speed
  }
}
}


now before the 1st frame of your characters animations "Jump", "Forwardjump" and "Runjump" add this line:

@cmd tossx 0

now before the 1st frame of the animation you want to cancel in to using "J" or "S" add this line:

@cmd tossx

hope this helps someone !
 
malik4ever said:
tried keyscripts and I dont like the way if you hold jump you cancel right into the air attack where as with cancel command you have to retap the jump button !

You should set keyscript to detect "pressing key" event not "holding key" event. That's nice thing about using keyscript, you can detect all 3 including "release key" event
 
What "exactly" is this doing? Is this a double jump script of float script?
 
@Bloodbane thanks I will look into that !  do you know of any tutorials for this ?

@Itsuchi KS when you use "J" or "S" button as a cancel from any jump animation the player stops dead in mid air then drops to floor !  think this was for full screen air supers and double jumps but I want to use "J" as a normal attack button !
 
Ah I thought so. The one you used from Crime Buster v2.5 is animation script not keyscript.

This is example of keyscript:

Code:
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

    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 of "Attack 2"
    void iAttack3 = playerkeys(iPlIndex, 1, "attack3"); // New key of "Attack 3"
    void iAttack4 = playerkeys(iPlIndex, 1, "attack4"); // New key of "Attack 4"

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

//Double jump
    if(vAniID == openborconstant("ANI_JUMP") ){ //Jumping?
      if(iJump){ //Left pressed?
        changeentityproperty(vSelf, "animation", openborconstant("ANI_FREESPECIAL"));
        if(iLeftH){ //Left held?
          changeentityproperty(vSelf, "direction", 0);
          tossentity(vSelf, 3, -1, 0);
        } else if(iRightH){ //Right held?
          changeentityproperty(vSelf, "direction", 1);
          tossentity(vSelf, 3, 1, 0);
        } else { //Nothing
          tossentity(vSelf, 3, 0, 0);
        }
      }
    }
}

This is example of keyscript, it is for double jump. Save this to say, double.c in scripts folder.

To use this, declare this in character's header:

keyscript data/scripts/double.c

As mentioned before, with this set, pressing jump while character is jumping will change character's animation to FREESPECIAL. There's extra scripts to toss character to left, right or just straight up if left or right is held.

If you need help modifying this, just ask :)
 
@Ilu: I don't know. I never tried that

@malik: you set that in this function:

playerkeys(iPlIndex, X, "moveup")

X = 0 means held
X = 1 means pressed
X = 2 means released

You could see in example above that I have 2nd set which detects held key events for Up, Left and Right.
 
Back
Top Bottom