[SCRIPT] Multiple Buttons Combo

White Dragon

New member
This is my library for keyall.c

With this script you can use multiple buttons for Keys/combo like:
"attack+attack2"
"attack+jump+special"
"down, down+forward+attack"
"attack+attack2, attack+jump+special"
etc..


DOWNLOAD:
http://www.mediafire.com/download/mmv7qb8zpmsl7jv/key_lib.zip

USAGE:

int combo(int p, char combo_id, int ETA, int hold_btn_combo_flag, char btn1, char btn2, char btn3, ...)
- Use it for combo like down, forward, attack+jump or down, forward+attack+jump
- returns 1 is the combo is completed, else returns 0

PARAMS:
int p: Player Index
char combo_id: Combo ID (string)
int ETA: time between two buttons pression (buffer window): 0 or NULL() is default. default is 0.5
int hold_btn_combo_flag: hold button flag (the same of playerkeys())
char btn1, char btn2, char btn3, ...: buttons

ACCEPTED BUTTONS:
forward, backward, up, down, attack,
attack2, attack3, attack4, jump,
special, start, esc, screenshot


and the function accepts multiple buttons like
"attack+attack2" or "attack+jump+special"

Example:
Code:
    if ( getentityproperty(getplayerproperty(p,"entity"),"exists") ) {
        void player = getplayerproperty(p,"entity");

        if( combo(p,"combo01",0,1,"forward","up","attack+attack2") ) {
            char anim = "ANI_FOLLOW42";

            if ( ready_to_attack(player,1,0,NULL()) ) {
                changeentityproperty(player,"velocity",0,0,0);
                performattack(player,openborconstant(anim),1);
            }
        }
    }

other functions:

int playerkeys_multi(int p, int hold_flag, char key_string)
- return 1 if all buttons are pressed, 2 if button are partially pressed and 0 if buttons aren't pressed. it works like playerkeys()
  ex. playerkeys_multi(0, 0, "attack+jump") returns 1 if player 1 hold
        attack+jump+special together
        and it returns 2 is player 1 hold only attack or jump. It accepts also more
        then two buttons like: "attack+jump+special"

int get_hold_time(int p, char key)
- returns the hold button time.
  ex. get_hold_time(0, "attack") returns the hold button time for player 1.

int is_multi_hold_pressed(int p, char btn1, char btn2, char btn3, ...)
- returns 1 if more than one button is pressed, it returns 0 else.
  ex. is_multi_hold_pressed(0,"attack","jump") returns 1 if the player 1 holds attack and jump button togheter


...and a function to retrieve an impulse every a CUSTOM ETA while you hold a button (use it in a script or ondrawscript event and not keyall.c):

Code:
/* PARAMS:
 * player_index: player index (ex 0,1,2,3)
 * key: pressed key string (ex. "moveleft", "move right", etc..)
 * time_range: time between 2 key impulses
 * start_press_flag: 1 == press the first time too, 0 == no first time key press
 * start_time_eta: wait time after the first key press (time between 1st and 2nd impulse)
 */
int hold_key_press(int player_index, char key, float time_range, int start_press_flag, float start_time_eta) {

    if ( playerkeys(player_index,0,key) ) {
        int time = openborvariant("elapsed_time");
        int game_speed = openborvariant("game_speed");

        //drawstring(0,20,0,"TEST KEY: "+playerkeys(player_index,0,key));
        if ( time_range == NULL() ) time_range = 0;
        if ( start_time_eta == NULL() ) start_time_eta = 0;
        time_range *= game_speed;
        start_time_eta *= game_speed;
        if ( getlocalvar("hold_time"+key+player_index) == NULL() ) {
            setlocalvar("hold_time"+key+player_index,time);

            if ( start_press_flag > 0 && getlocalvar("first_keypress"+key+player_index) == NULL() ) {
                setlocalvar("first_keypress"+key+player_index,1);
                return playerkeys(player_index,0,key);
            }
        } else if ( time-getlocalvar("hold_time"+key+player_index) >= time_range ) {
            //drawstring(0,30,0,"OK!");
            if ( start_time_eta > 0 && getlocalvar("second_keypress"+key+player_index) == NULL() ) {
                if ( time-getlocalvar("hold_time"+key+player_index) < start_time_eta ) return 0;
            }

            // simulate hold press
            if ( getlocalvar("second_keypress"+key+player_index) == NULL() ) setlocalvar("second_keypress"+key+player_index,1);
            setlocalvar("hold_time"+key+player_index,NULL());
            return playerkeys(player_index,0,key);
        }
    } else {
        if ( getlocalvar("hold_time"+key+player_index) ) setlocalvar("hold_time"+key+player_index,NULL());
        if ( getlocalvar("first_keypress"+key+player_index) ) setlocalvar("first_keypress"+key+player_index,NULL());
        if ( getlocalvar("second_keypress"+key+player_index) ) setlocalvar("second_keypress"+key+player_index,NULL());
    }

    return 0;
}

example:
if ( hold_key_press(player_index,"moveright",0.08,1,0.2) == openborconstant("FLAG_MOVERIGHT") ) {
...
}
 
How do i use this script in my character flag? is there some exemple? what mod are using this script?
 
I feel like I could some how use this to break/cancel attack animations with the press of the "ATTACK" button to have a character perform an additional attack before finishing the default attack animation and IF the player doesn't press the "ATTACK" button during specific character frames, the default attack animation plays.

The only way I KNOW how to do this is with "CANCEL" but that breaks the default "ATTACK ANIMATION" if the animation is not the final "KNOCK DOWN" attack animation.

EXAMPLE:

If my character's attack pattern is at1, at2, at3, at4

During at3, player presses "FORWARD+ATTACK" to have character perform an additional "NON KNOCKDOWN" attack within specific frames in at3 and then player press ATTACK once more to go to at4 for final attack. BUT if player DOESN'T press "FORWARD+ATTACK" during specific frames in at3 but does press attack, character uses normal 4 hit combo but IF NOT...character finishes full ATTACK3 animation and returns to idle.

This is also saying that if the player doesn't press attack during specific frames in at3, character won't do at4 and character will return to idle animation "SMOOTHLY" without jumping frames.

Im trying to make it more realistic so that animations transition smoothly depending on what the player does. There are times that characters defeat enemies with at2 and at2 is not always a straight punch. Sometimes at2 could be a kick with a full animation cycle but if the character has to keep attacking the opponent, at2 doesn't play the full animation cycle if "ATTACK" is pressed during specific frames that lead to at3...but if "ATTACK" isn't pressed, at2 plays full cycle animation   
 
Back
Top Bottom