[SCRIPT] Backpain

White Dragon

New member
Here the code to implement the backpains:

-takedamagescript event-
call this script funcs with: takedamagescript data/scripts/ontakedamage.c

ontakedamage.c:
Code:
void main() {
  	void self = getlocalvar("self");
  	void attacker = getlocalvar("attacker");

	setoppx_ondmg(self,attacker); // backpains
}

int setoppx_ondmg(void player, void attacker) {
    setentityvar(player, 6, getentityproperty(attacker, "x") );
}

Support Functions (in script event):
Add these funcs in main script of your chara:
call these funcs with: script data/scripts/backpain.c

backpain.c
Code:
void main() {
    check_backpain(self,0);
    setprevdir(self); // for backpains
    settimebp(self); // for backpains
}

int check_backpain(void player, float threshold) {
    void opp = getentityproperty(player, "opponent");
    int anim_id = getentityproperty(player, "animationid");

            // Se il nemico è davanti a noi (più a destra) ma noi siamo girati a sinistra allora backpain!!
            // Quindi valutiamo se stanno l'uno alle spalle dell'altro...
            if ( gettimebp(player) >= 0 && gettimebp(player) <= 1 ) {
                if ( (getprevdir(player) == 0 && getoppx(player) > getentityproperty(player, "x")+threshold)
                      || (getprevdir(player) == 1 && getoppx(player) < getentityproperty(player, "x")-threshold) ) {

                            if ( getentityproperty(player, "health") > 0 ) {
                                if ( anim_id == openborconstant("ANI_PAIN") ) {
                                    set_backdir(player,threshold);
                                    performattack(player, openborconstant("ANI_PAIN16"), 1); // backpain
                                    set_backdir(player,threshold);
                                } // you can add else if PAIN# then... ... ..
                            } else { // else health <= 0...
                                if ( anim_id == openborconstant("ANI_DIE")  || .. ... .. ) {
                                    set_backdir(player,threshold);
                                    changeentityproperty(player, "animation", openborconstant("ANI_DIE4") ); // backdeath
                                    set_backdir(player,threshold);
                                }
                            } // fine if health > 0

                            reset_oppx(player);
                } // fine if stanno alle spalle
            }
}

int set_backdir(void player, float threshold) {
    float oppx = getoppx(player);
    int prevdir = getprevdir(player);

    if ( oppx != NULL() && prevdir != NULL() ) {
        if ( prevdir == 0 && oppx > getentityproperty(player, "x")+threshold ) changeentityproperty(player,"direction",0);
        else if ( prevdir == 1 && oppx < getentityproperty(player, "x")-threshold ) changeentityproperty(player,"direction",1);
    }
}

int reset_oppx(void player) {
    setentityvar(player, 6, NULL() );
}

int settimebp(void player) {
    if ( (getentityproperty(player, "aiflag", "dead") != 0 || getentityproperty(player, "aiflag", "falling") != 0 || getentityproperty(player, "aiflag", "inpain") != 0)
        && getentityvar(player, 8) == NULL() && getentityproperty(player, "animpos") <= 0 ) {
        setentityvar(player, 8, openborvariant("elapsed_time"));
    }
    if ( getentityproperty(player, "aiflag", "dead") != 1 && getentityproperty(player, "aiflag", "falling") != 1 && getentityproperty(player, "aiflag", "inpain") != 1
        && getentityvar(player, 8) != NULL() ) {
        setentityvar(player, 8, NULL());
    }
}

int gettimebp(void player) {
    if ( getentityvar(player, 8) != NULL() ) return openborvariant("elapsed_time")-getentityvar(player, 8);
    else return NULL();
}

int getoppx(void player) {
    return getentityvar(player, 6);
}

int setprevdir(void player) {
    int anim_id = getentityproperty(player, "animationid");
    int dir = getentityproperty(player, "direction");

    if ( anim_id != getlocalvar("animationid_dir") || dir != getentityvar(player, 4) ) { // In questo modo s'imposta la dir al primo frame dell'animpos == 0
        if ( getentityproperty(player, "aiflag", "dead") != 1 && getentityproperty(player, "aiflag", "falling") != 1 && getentityproperty(player, "aiflag", "inpain") != 1 ) { //getentityproperty(player, "animpos") <= 0
            setentityvar(player, 4, getentityproperty(player, "direction") );
        } else if ( getentityvar(player, 4) == NULL() ) setentityvar(player, 4, getentityproperty(player, "direction") );
        setlocalvar("animationid_dir", anim_id);
    }
}

int getprevdir(void player) {
    return getentityvar(player, 4);
}
 
Nice!!
I like the fact possibility to have different reactions depending on position of enemy or attacker...
-Basically this is what I'll need for my "contextual" on-the-ground grapple moves.
-I'll certainly use it for back grabbing system too (if it work)
 
Back
Top Bottom