[SCRIPT] Another BACKPAIN script

White Dragon

New member
Use it in ondoattack event (ex. ondoattackscript   data/scripts/player_ondoattack.c):

Code:
#define gpp getplayerproperty
#define cpp changeplayerproperty
#define gep getentityproperty
#define cep changeentityproperty
#define ov  openborvariant
#define cv  changeopenborvariant
#define oc  openborconstant
#define clp changelayerproperty
#define glv getlocalvar
#define slv setlocalvar
#define sev setentityvar
#define gev getentityvar
#define sgv setglobalvar
#define ggv getglobalvar

void main() {
    void self = getlocalvar("self");
    int damage = getlocalvar("damage");
    int drop = getlocalvar("drop");
    void other = getlocalvar("other"); // When called on attacker, this recipient of attack. When called on defender, this is the attacker.
    int attacktype = getlocalvar("attacktype");
    void which = getlocalvar("which"); // 0 = Caller is defender. 1 = Caller is attacker.
    int attackid = getlocalvar("attackid");
    int pauseadd = getlocalvar("pauseadd");
    int guardcost = getlocalvar("guardcost");
    int jugglecost = getlocalvar("jugglecost");

    check_backpain(self,other,which,attacktype,drop,damage,pauseadd);
}

void check_backpain(void self, void other, void which, void attacktype, int drop, int damage, int pauseadd) {
    if ( !which && getentityproperty(other,"exists") ) { // other is the opp!!
        float x = getentityproperty(self,"x");
        int dir = getentityproperty(self,"direction");
        float ox = getentityproperty(other,"x");
        float threshold = 0;

        if ( (!dir && ox > x+threshold) || (dir && ox < x-threshold) ) {
            char REPLACED_ATK = "ATK_NORMAL";
            int health = getentityproperty(self,"health");
            //int blockback = getentityproperty(self,"blockback");

            // stai bloccando anche dietro
            //if ( getentityproperty(self,"aiflag","blocking") && (blockback || blockback == NULL()) ) return;
            if ( getentityproperty(self,"aiflag","blocking") ) return;

            changeopenborvariant("lasthitc",0); //nullify last hit collision!!

            if ( health-damage > 0 ) {
                if ( !drop ) {
                    if ( attacktype == openborconstant("ATK_NORMAL") || attacktype == openborconstant("ATK_NORMAL2") || attacktype == openborconstant("ATK_NORMAL3") || attacktype == openborconstant("ATK_NORMAL8") ) {
                        REPLACED_ATK = "ATK_NORMAL16";
                    } else if ( attacktype == openborconstant("ATK_NORMAL6") ) {
                        REPLACED_ATK = "ATK_NORMAL17";
                    } else if ( attacktype == openborconstant("ATK_NORMAL4") || attacktype == openborconstant("ATK_NORMAL5") ) {
                        REPLACED_ATK = "ATK_NORMAL11";
                    } else if ( attacktype == openborconstant("ATK_NORMAL9") ) {
                        REPLACED_ATK = "ATK_NORMAL50";
                        drop = 1;
                    }
                } else {
                    if ( attacktype == openborconstant("ATK_NORMAL") ) {
                        REPLACED_ATK = "ATK_NORMAL51";
                    } else if ( attacktype == openborconstant("ATK_NORMAL2") || attacktype == openborconstant("ATK_NORMAL9") ) {
                        REPLACED_ATK = "ATK_NORMAL50";
                    } else if ( attacktype == openborconstant("ATK_NORMAL3") ) {
                        REPLACED_ATK = "ATK_NORMAL52";
                    }
                }
            } else {
                if ( attacktype == openborconstant("ATK_NORMAL") ) {
                    REPLACED_ATK = "ATK_NORMAL52";
                } else if ( attacktype == openborconstant("ATK_NORMAL2") || attacktype == openborconstant("ATK_NORMAL3") || attacktype == openborconstant("ATK_NORMAL5") || attacktype == openborconstant("ATK_NORMAL9") || attacktype == openborconstant("ATK_NORMAL12") ) {
                    REPLACED_ATK = "ATK_NORMAL50";
                }
            }

            if ( !getentityproperty(self,"aiflag","blocking") ) {
                // Il flash è in mostra?? Se no allora eseguilo.
                if ( !getentityproperty(self,"flash","noattack") ) show_flash();
                playsample(loadsample("data/sounds/punch004.wav"));
            }
            /*if ( getentityproperty(other,"aiflag","attacking") && getentityproperty(self,"flash","block") ) {
                show_block_flash();
                playsample(loadsample("data/sounds/punch003.wav"));
            }*/

            damageentity(self,other,damage,drop,openborconstant(REPLACED_ATK));
            if ( dir ) changeentityproperty(self,"direction",1);
            else if ( !dir ) changeentityproperty(self,"direction",0);

            changeentityproperty(self,"freezetime",openborvariant("elapsed_time")+pauseadd);
            changeentityproperty(other,"freezetime",openborvariant("elapsed_time")+pauseadd);
            changeentityproperty(self,"frozen",1);
            changeentityproperty(other,"frozen",1);
        } // fine if backpain ok
    } // fine if defender and no blocking

    return;
}


void show_flash(char flash_name, void opp, int map, char sndfx) {
	void flash;

    if ( flash_name == NULL() ) flash_name = "cflash";

	flash = spawnsubentity(flash_name,openborvariant("lasthitx"),openborvariant("lasthitz"),openborvariant("lasthita"));
	if ( map != NULL() ) changeentityproperty(flash,"map",map);
	if ( sndfx != NULL() ) playsample(loadsample(sndfx));

	if ( getentityproperty(opp,"exists") && opp != NULL() ) {
        int odir = getentityproperty(opp,"direction");

        if ( odir ) changeentityproperty(flash,"direction",1);
        else changeentityproperty(flash,"direction",0);
	}
}

void show_block_flash(char flash_name, void opp, int map, char sndfx) {
	void flash;

	if ( flash_name == NULL() ) flash_name = "dflash";

	flash = spawnsubentity("dflash",openborvariant("lasthitx"),openborvariant("lasthitz"),openborvariant("lasthita"));
	if ( map != NULL() ) changeentityproperty(flash,"map",map);
	if ( sndfx != NULL() ) playsample(loadsample(sndfx));

	if ( getentityproperty(opp,"exists") && opp != NULL() ) {
        int odir = getentityproperty(opp,"direction");

        if ( odir ) changeentityproperty(flash,"direction",1);
        else changeentityproperty(flash,"direction",0);
	}
}

This is an attempt to make more efficient the backpain script and to use unordered attacks/pains maches.
Ps. The code is little sketchy
 
Back
Top Bottom