[SCRIPT] Charge Attack in Megaman style

White Dragon

New member
/*
* PARAMS:
* self = entity that performs a charge attack
* key = hold button for charge attack: "attack" or "special" etc..
* color1,2,3 = flashing colors. set it in RGB format like -> rgbcolor(0x43,0x00,0xDA)
* max_charge_time = time in frames of whole charge time (from min to max charge)
* atk_name1,2,3 = ATTACK NAME ex. "ANI_FREESPECIAL1" or "ANI_FOLLOW1" or what-you-want
* sound_fx = sound path+filename (OPTIONAL)
* sound_duration = sound duration time (OPTIONAL)
* flashing_ent = flashing entity (OPTIONAL)
* flash_frame_length = frames number of flashing entity animation (OPTIONAL)
* on_base_flag = if 1 you can perform a charge atk only on land else set it to 0 (OPTIONAL)
* first_atk_flag = if 0 you avoid the first attack. so only last 2 attacks are valid (OPTIONAL)
*/

Example (script event):
script  player_script.c
Code:
void main() {
  void self = getlocalvar("self");

  charge_attack(self,"attack",rgbcolor(0x00,0x26,0x88),rgbcolor(0x43,0x00,0xDA),rgbcolor(0x00,0xDA,0x0F),openborvariant("game_speed")*6,"ANI_FREESPECIAL17","ANI_FREESPECIAL21","ANI_FREESPECIAL13","data/sounds/frozen03.wav",openborvariant("game_speed")*0.2,"cflash",3,0,1);
}

this is the code:
Code:
int charge_attack(void self, char key, int color1, int color2, int color3, int max_charge_time, char atk_name1, char atk_name2, char atk_name3, char sound_fx, int sound_duration, char flashing_ent, int flash_frame_length, int on_base_flag, int first_atk_flag) {
    int time = openborvariant("elapsed_time");
    int p = getentityproperty(self,"playerindex");
    int CHARGE_ATK1 = openborconstant(atk_name1);
    int CHARGE_ATK2 = openborconstant(atk_name2);
    int CHARGE_ATK3 = openborconstant(atk_name3);

    if ( playerkeys(self,0,key) ) {
        if ( getlocalvar("charge_time") == NULL() ) { // unsetted time
            if ( time+max_charge_time >= openborconstant("MAX_INT") ) { // time protection
                changeopenborvariant("elapsed_time",0);
                time = openborvariant("elapsed_time");
            }
            setlocalvar("charge_time",time+max_charge_time);
        } else { // setted time
            int time_range = max_charge_time/3;
            int charge_time = time%max_charge_time;

            // FLASHING
            if ( time < getlocalvar("charge_time")-time_range*2 ) {
                flashing_color(self,color1,openborvariant("game_speed")/10,0);
                setlocalvar("charge_atk",0);
            } else if ( time < getlocalvar("charge_time")-time_range*1 ) {
                flashing_color(self,color2,openborvariant("game_speed")/15,0);
                setlocalvar("charge_atk",1);
            } else {
                flashing_color(self,color3,openborvariant("game_speed")/20,0);
                setlocalvar("charge_atk",2);
            }

            // SOUND
            if ( getlocalvar("charge_sound_time") == NULL() ) {
                if ( sound_fx == NULL() || sound_duration == NULL() ) return -1;
                if ( time+max_charge_time >= openborconstant("MAX_INT") ) { // time protection
                    changeopenborvariant("elapsed_time",0);
                    time = openborvariant("elapsed_time");
                }
                playsample(loadsample(sound_fx));
                setlocalvar("charge_sound_time",time+sound_duration);
            } else if ( time > getlocalvar("charge_sound_time") ) setlocalvar("charge_sound_time",NULL());

            // FLASH ENTITY
            if ( getlocalvar("charge_flash_ent") == NULL() ) {
                float x = getentityproperty(self,"x");
                float z = getentityproperty(self,"z");
                float y = getentityproperty(self,"y");
                float base = getentityproperty(self,"base");
                float dir = getentityproperty(self,"direction");
                float height = getentityproperty(self,"height");
                void subent;

                if ( flashing_ent == NULL() ) return -1;

                if ( height == NULL() ) height = 0;
                clearspawnentry();
                setspawnentry("name", flashing_ent);
                subent = spawn();
                changeentityproperty(subent, "no_adjust_base", 1);
                changeentityproperty(subent, "position", x, z, y+(height/2));
                changeentityproperty(subent, "base", y+(height/2));
                changeentityproperty(subent, "direction", dir);
                changeentityproperty(subent, "parent", self);
                setlocalvar("charge_flash_ent",subent);
            } else {
                void subent = getlocalvar("charge_flash_ent");

                if ( getentityproperty(subent,"exists") ) {
                    if ( getentityproperty(subent,"defaultmodel") == flashing_ent ) {
                        if ( flash_frame_length != NULL() ) {
                            if ( getentityproperty(subent,"animpos") >= flash_frame_length ) {
                                killentity(subent);
                                setlocalvar("charge_flash_ent",NULL());
                            }
                        }
                    } else setlocalvar("charge_flash_ent",NULL());
                } else setlocalvar("charge_flash_ent",NULL());
            }
        }
    } else {
        if ( getlocalvar("charge_time") != NULL() ) {
            float y = getentityproperty(self,"y");
            float base = getentityproperty(self,"base");

            if ( first_atk_flag == NULL() ) first_atk_flag = 0;

            // PERFORM AN ATTACK
            if ( getlocalvar("charge_atk") != NULL() ) {
                if ( on_base_flag != NULL() && on_base_flag > 0 && y > base ) return 0;

                if ( getlocalvar("charge_atk") == 0 ) {
                   if ( first_atk_flag ) performattack(self,CHARGE_ATK1,1);
                } else if ( getlocalvar("charge_atk") == 1 ) performattack(self,CHARGE_ATK2,1);
                else performattack(self,CHARGE_ATK3,1);
            }

            // RESET
            clear_flashing(self,0);
            setlocalvar("charge_sound_time",NULL());
            if ( getentityproperty(getlocalvar("charge_flash_ent"),"exists") && getentityproperty(getlocalvar("charge_flash_ent"),"defaultmodel") == flashing_ent ) killentity(getlocalvar("charge_flash_ent"));
            setlocalvar("charge_flash_ent",NULL());
            setlocalvar("charge_atk",NULL());
            setlocalvar("charge_time",NULL());
        }
    }
}

void flashing_color(void self, int colour, int frames, int reset_flag) {
    int time = openborvariant("elapsed_time");
    int flash_frames = frames;
    float time_range = flash_frames/2;
    int no_colour = rgbcolor(0x00,0x00,0x00);
    //int colour1 = rgbcolor(0xFF,0xFF,0x00);
    //int colour2 = rgbcolor(0xFF,0x00,0x00);

    if ( reset_flag == NULL() ) reset_flag = 0;

    time %= flash_frames;

    if ( time <= time_range ) {
        setlocalvar("next_flash_color",colour);
        setlocalvar("step_flash_color", 1);
    } else {
        setlocalvar("next_flash_color", no_colour);
        setlocalvar("step_flash_color", NULL());
    }

    changedrawmethod(self, "enabled", 1);
    if ( reset_flag ) changedrawmethod(self, "reset", 1);

    if ( getlocalvar("step_flash_color") == NULL() ) {
        changedrawmethod(self, "tintmode", 0);
        changedrawmethod(self, "tintcolor", 0);
        changedrawmethod(self, "fillcolor", 0);
    } else if ( getlocalvar("step_flash_color") == 1 ) {
        changedrawmethod(self, "tintmode", 6);
        changedrawmethod(self, "fillcolor", 0);
        changedrawmethod(self, "tintcolor", getlocalvar("next_flash_color"));
    }

    if ( reset_flag ) {
        changedrawmethod(NULL(), "enabled", 0);
        changedrawmethod(NULL(), "reset", 1);
    }
}

void clear_flashing(void self, int reset_flag) {
    setlocalvar("set_flash_time",NULL());
    setlocalvar("next_flash_color",NULL());
    setlocalvar("step_flash_color",NULL());

    if ( reset_flag == NULL() ) reset_flag = 0;

    changedrawmethod(self, "tintmode", 0);
    changedrawmethod(self, "tintcolor", 0);
    changedrawmethod(self, "fillcolor", 0);

    if ( reset_flag ) {
        changedrawmethod(self, "enabled", 0);
        changedrawmethod(self, "reset", 1);
        changedrawmethod(NULL(), "enabled", 0);
        changedrawmethod(NULL(), "reset", 1);
    }
}
 
O Ilusionista said:
"ANI_FREESPECIAL17","ANI_FREESPECIAL21","ANI_FREESPECIAL13" are the 3 levels, right?

Yes, it's an example.
ANI_FREESPECIAL17 is an attack that you perform without charge. if you dont want it, you can put a comment on performattack.
if max_charge_time == openborvariant("game_speed")*6 (6 secs) every charge continue for 2 secs (6/3) because I divided the charge time into 3 times.
So you can perform ANI_FREESPECIAL21 after 2 secs and ANI_FREESPECIAL13 after 4 secs.

wait....
ADDED another param in the code and improved flashing entity section.
To AVOID the first attack (without charge) use the last flag (first_atk_flag).
Set it to 0 if you want to avoid the first attack (ex. ANI_FREESPECIAL17).
Changed PARAMS order too...
 
now im looking for one variation of this script that keep  the character in one charge animation and unmovable while holding the button and when release the button it shots one of those freespecials based on how much time it was holding

white dragon is it too hard to adapt this code to my case?



hqdefault.jpg

takuma in his holding /charging animation player do a command to activate his freespecial and he enters in charging/ holding projectile animation then when player release one of the three projectile variations will be played based on time he was holding the button
 
yes set speed to 0 (i dont like it) or better perform a charge animation setted to 0.
Then use a function that freeze all nemies and objects like street fighter by using:
changeentityproperty(self,"freezetime",openborvariant("elapsed_time")+pauseadd);
changeentityproperty(self,"frozen",1);
 
thanks guys, i think i will dont need the freeze all enemies part.

i will just need a loop animation to the charging period like takuma holding his projectile and shaking, i alredy did it once using keyint based on crime buster athena once, i wil do some tests and try it here too

when you guys say set speed to 0  i dont know exacly where to change it
i will do some test to see if i figure it out eheh
 
There is a side effect that I noticed: when you set an enemy speed to 0 (on a grab move, for exemple) he won't walk anymore, because his speed is now 0.
 
Hey, I'm really beginner about Openbor.
I want to use this script but ... EROOR...

Property name 'y' is not supported by function getentityproperty.
Property name 'y' is not supported by function getentityproperty.
Property name 'tintmode' is not supported by drawmethod.
Property name 'tintcolor' is not supported by drawmethod.
Property name 'tintmode' is not supported by drawmethod.
Property name 'tintcolor' is not supported by drawmethod.
Property name 'tintmode' is not supported by drawmethod.
Property name 'tintcolor' is not supported by drawmethod.

If it's ok, Please tell me "How to use it". :)
 
Hi all! I hope this is not a too stupid question. Well, I've found the script CHARGE ATTACK MEGAMAN STYLE (http://www.chronocrash.com/forum/index.php?topic=1877.msg24343#msg24343) but I have no idea about scripting and I don't know how to make it work on my project. I have been experimenting on my own without success. The last question asking for help was made in 2018 without response, and avoiding necropost, etc, I prefer make here the question. Thank you so much.
 
Hi KaisseR_SK, did you take a look at betterbold's Megaman project? He uses charge attacks and it works flawlessly:
http://www.chronocrash.com/forum/index.php?topic=4259.msg62396#msg62396

If you don't manage to create something like this, I can help you to set this special attack.
 
kimono said:
Hi KaisseR_SK, did you take a look at betterbold's Megaman project? He uses charge attacks and it works flawlessly:
http://www.chronocrash.com/forum/index.php?topic=4259.msg62396#msg62396

If you don't manage to create something like this, I can help you to set this special attack.

HI! Tanks for thanks for answering. I've searched, downloaded and tested many Megaman's mods, but it seems to me that this I have not tried.
Thanks again!

EDIT:
In MMan mod, works perfectly, but when I try on mine: "There's an exception while executing script 'updateentityscript' data/chars/TestChar/TestChar.txt
 
Back
Top Bottom