real platformer jump

ABK

Well-known member
Hi, i had this old keyall script which emulated mario jump ( when you tap the button character makes small jump and when you hold button longer then character makes long jump + you can jump first then move left or right and you can move in midair) but that script didnt worked all the time, sometimes it made long regular jump even when i tapped the button fast.
Is there any new method to achieve platformer style jump ? With some kind of time release or something so it always knows that i just tap the button and makes small jump.
Here the script :
Code:
void main(){
    
	/*
    Damon Vaughn Caskey
    06/25/2009
    Capture keystrokes and perform actions accordingly.
    */

    int     iPlIndex    = getlocalvar("player");                                    //Player index.
    void    vSelf       = getplayerproperty(iPlIndex, "entity");                    //Get calling entity.
    int     iFIdl       = getentityproperty(vSelf, "aiflag", "idling");             //Self idling?
    int     iFAtk       = getentityproperty(vSelf, "aiflag", "attacking");          //Self attacking (freespecial, jumpattack, follow, or attack)?
    int     iFJmp       = getentityproperty(vSelf, "aiflag", "jumping");            //Self jumping?
    int     iXDir       = getentityproperty(vSelf, "xdir");                         //X velocity.
    int     iTime       = openborvariant("elapsed_time");                           //Current time.    
    int     iAni;                                                                   //Current animation.
    int     iFrame;                                                                 //Current animation frame.
    float   fTossV;                                                                 //Vertical speed.
    float   fXDir;                                                                  //Horizontal speed.
    float   fZDir;                                                                  //Z axis speed.
    void    vTarget;                                                                //Opponent.

/*  int     iKUpH       = playerkeys(iPlIndex, 0, "moveup");                        //Hold "Up".
    int     iKDnH       = playerkeys(iPlIndex, 0, "movedown");                      //Hold "Down".
    int     iKLtH       = playerkeys(iPlIndex, 0, "moveleft");                      //Hold "Left".    
    int     iKRtH       = playerkeys(iPlIndex, 0, "moveright");                     //Hold "Right".
    int     iKAtkH      = playerkeys(iPlIndex, 0, "attack");                        //Hold "Attack".
    int     iKAtk2H     = playerkeys(iPlIndex, 0, "attack2");                       //Hold "Attack2".
    int     iKAtk3H     = playerkeys(iPlIndex, 0, "attack3");                       //Hold "Attack3".
    int     iKAtk4H     = playerkeys(iPlIndex, 0, "attack4");                       //Hold "Attack4".
    int     iKJmpH      = playerkeys(iPlIndex, 0, "jump");                          //Hold "Jump".
    int     iKSpH       = playerkeys(iPlIndex, 0, "special");                       //Hold "Special".
    int     iKStH       = playerkeys(iPlIndex, 0, "start");                         //Hold "Start".
    int     iKEscH      = playerkeys(iPlIndex, 0, "escape");                        //Hold "Escape".
    int     iKSsH       = playerkeys(iPlIndex, 0, "SCREENSHOT");                    //Hold "Screenshot".
    int     iKAnyH      = playerkeys(iPlIndex, 0, "ANYBUTTON");                     //Hold any key.
   
    int     iKUp        = playerkeys(iPlIndex, 1, "moveup");                        //Press "Up".
    int     iKDn        = playerkeys(iPlIndex, 1, "movedown");                      //Press "Down".    
*/  int     iKLt        = playerkeys(iPlIndex, 1, "moveleft");                      //Press "Left".    
    int     iKRt        = playerkeys(iPlIndex, 1, "moveright");                     //Press "Right".    
/*  int     iKAtk       = playerkeys(iPlIndex, 1, "attack");                        //Press "Attack".
    int     iKAtk2      = playerkeys(iPlIndex, 1, "attack2");                       //Press "Attack2".
    int     iKAtk3      = playerkeys(iPlIndex, 1, "attack3");                       //Press "Attack3".
    int     iKAtk4      = playerkeys(iPlIndex, 1, "attack4");                       //Press "Attack4".
    int     iKJmp       = playerkeys(iPlIndex, 1, "jump");                          //Press "Jump".
    int     iKSp        = playerkeys(iPlIndex, 1, "special");                       //Press "Special".
    int     iKSt        = playerkeys(iPlIndex, 1, "start");                         //Press "Start".
    int     iKEsc       = playerkeys(iPlIndex, 1, "escape");                        //Press "Escape".
    int     iKSs        = playerkeys(iPlIndex, 1, "SCREENSHOT");                    //Press "Screenshot".
    int     iKAny       = playerkeys(iPlIndex, 1, "ANYBUTTON");                     //Press any key.
    
    int     iKUpR       = playerkeys(iPlIndex, 2, "moveup");                        //Release "Up".
    int     iKDnR       = playerkeys(iPlIndex, 2, "movedown");                      //Release "Down".    
*/  int     iKLtR       = playerkeys(iPlIndex, 2, "moveleft");                      //Release "Left".    
    int     iKRtR       = playerkeys(iPlIndex, 2, "moveright");                     //Release "Right".
/*  int     iKAtkR      = playerkeys(iPlIndex, 2, "attack");                        //Release "Attack".
    int     iKAtk2R     = playerkeys(iPlIndex, 2, "attack2");                       //Release "Attack2".
    int     iKAtk3R     = playerkeys(iPlIndex, 2, "attack3");                       //Release "Attack3".
    int     iKAtk4R     = playerkeys(iPlIndex, 2, "attack4");                       //Release "Attack4".
*/  int     iKJmpR      = playerkeys(iPlIndex, 2, "jump");                          //Release "Jump".
/*  int     iKSpR       = playerkeys(iPlIndex, 2, "special");                       //Release "Special".
    int     iKStR       = playerkeys(iPlIndex, 2, "start");                         //Release "Start".
    int     iKEscR      = playerkeys(iPlIndex, 2, "escape");                        //Release "Escape".
    int     iKSsR       = playerkeys(iPlIndex, 2, "SCREENSHOT");                    //Release "Screenshot".
    int     iKAnyR      = playerkeys(iPlIndex, 2, "ANYBUTTON");                     //Release any key.   
  

    if (iKSp)
    {
        setentityvar(vSelf, KEY1SP, iTime);                                         //Store last press of special key.        
    }
	else if(iKAtk)
    {
        setentityvar(vSelf, KEY1AT, iTime);                                         //Store last press of Attack key.        
    }
*/
    if (iFIdl)                                                                      //Idle?
    {
        
    }    
    else if (iFJmp)                                                                 //Jumping?
    {   
        fTossV  = getentityproperty(vSelf, "tossv");                                //Get Y velocity.
        fXDir   = getentityproperty(vSelf, "xdir");                                 //Get X velocity.
        fZDir   = getentityproperty(vSelf, "zdir");                                 //Get Z velocity.

        //Mario style jumpheight control.
        if (iKJmpR)                                                                 //Jump key release?
        {            
            if (fTossV > 0)                                                         //Not falling already?
            {			
                fTossV /= 2;                                                        //Cut Y velcoity to 50%.                
            }
            changeplayerproperty(vSelf, "playkeys", 0);                             //Clear key event.
        }                
    
        if(iKLtR || iKRtR)                                                          //Left or Right released?
        {
            fXDir /= 2;                                                             //Cut X velocity by 50%.
            changeplayerproperty(vSelf, "playkeys", 0);                             //Clear key event.
        }                       
        else if(iKLt)                                                               //Left pressed?
        {            
            fXDir = -1;                                                             //Set velocity left.
            changeentityproperty(vSelf, "direction", 0);                            //Set facing left.
            changeplayerproperty(vSelf, "playkeys", 0);                             //Clear key event.
        }
        else if(iKRt)                                                               //Right pressed?
        {
            fXDir = 1;                                                              //Set velocity right.
            changeentityproperty(vSelf, "direction", 1);                            //Set facing right.                       
            changeplayerproperty(vSelf, "playkeys", 0);                             //Clear key event.
        }        
        
        changeentityproperty(vSelf, "velocity", fXDir, fZDir, fTossV);              //Apply velocity        

    }
    else if (iFAtk)                                                                 //Attacking?
    {        
        
    }
}
 
The reason that sometimes failed wasn't so much a flaw in the script as a flaw in when it got executed. If the entity had a JUMPDELAY animation, or for whatever reason spent any time time at all before leaving the "ground", it was possible for the player to have let go of the Jump key before liftoff. That in turn meant the Keyup event (which triggered the stop upward momentum part of the script) had already occurred before the entity ever actually jumped. As a result there was nothing to stop the entity from reaching its full height (except another press/release of the Jump key).

Anyway, I do have another way of doing this now; it always works and is fully completely compatible with any animation layout. It's more or less the same thing, just moved to the onmoveascript with some minor modifications. I'll post it shortly.

DC

*Edit:* See here. I've used this method since 2010. Just cleaned it up a little using the very latest script features of OpenBOR, but only a couple of lines were changed; you could easily back port it to older engine iterations if needed.

 
thanks but
Code:
Script error: data/scripts/jump0005.h, line 33: Invalid function call or expression '?' (in production 'postfix_expr2')

    vEnt = vEnt ? VEnt : getlocalvar("self")
 
Oops. That latest version in Downloads does not include Plombo's additions that make that line possible. I only ever bother to compile the Windows versions. Give me a few moments to compile the others and I'll upload the latest myself.

DC

*Edit:*
Done. Get build 3818 here.
 
Now i got this
Code:
Script error: data/scripts/jump0005.h, line 36: Invalid function call or expression 'iType' (in production 'postfix_expr2')

    iType   = getentityproperty(vEnt, "type");                                              //Get entity type.
    ^


********** An Error Occurred **********
*            Shutting Down 
 
Does this still work on latest build?  Perhaps I am just doing it wrong....

I've tried to get this working but I get an error. 
Script compile error in 'data/scripts/com/jump0005.h': T_PLAYER line 41, column 17

I have the scripts that are posted at http://www.caskeys.com/dc/?p=5160
jump0005.h and constants.h

This is my onmoveascript

Code:
#include    "data/scripts/vars/constants.h" //http://www.caskeys.com/dc/?p=5059
#import     "data/scripts/com/jump0005.h"   //http://www.caskeys.com/dc/?p=5160
 
void main()
{
    jump0005(ENT_SELF, CONF_JUMPCON_X, CONF_JUMPCON_Y, CONF_JUMPCON_Z);
}



At the moment I'm still using the old keyall.c method

 
You're missing a constant (T_PLAYER). It's an easy fix, but if you can wait until later today I'll try to make an updated version that's self contained. I need to finish up something here at work first though.

DC
 
for gameplay mechanics like mario you also need to modify walking animation so when you stop pressing forward and press back then character will still walk for awhile and slide a bit, then he will move back, a bit like walking on ice.
 
Back
Top Bottom