Solved How do you implement a critical hit?

Question that is answered or resolved.

kimduck

Member
For example, I want to use the same command, but have it trigger anim freespecial2 with about a 90% chance and anim freespecial3 with a 10% chance.
I would appreciate it if you could tell me how to implement this.
 
Solution
For example, I want to use the same command, but have it trigger anim freespecial2 with about a 90% chance and anim freespecial3 with a 10% chance.
I would appreciate it if you could tell me how to implement this.
I suggest using keyscripts + follow animations for this feature. This is because, unlike freespecials, there's no event that may trigger follow animations accidentally, unless you force them with scripts or via "followanim/followcond".

That said, just create any .c file in your scripts folder and call it in your character header, like this:

keyscript data/scripts/critical.c

After that, put a script like the example below:

Code:
void main()
{
    void self = getlocalvar("self");
    int pIndex =...
For example, I want to use the same command, but have it trigger anim freespecial2 with about a 90% chance and anim freespecial3 with a 10% chance.
I would appreciate it if you could tell me how to implement this.
I suggest using keyscripts + follow animations for this feature. This is because, unlike freespecials, there's no event that may trigger follow animations accidentally, unless you force them with scripts or via "followanim/followcond".

That said, just create any .c file in your scripts folder and call it in your character header, like this:

keyscript data/scripts/critical.c

After that, put a script like the example below:

Code:
void main()
{
    void self = getlocalvar("self");
    int pIndex = getlocalvar("player");
    int attack2 = playerkeys(pIndex, 1, "attack2");

    if(attack2)
    {
        int iR = rand()%50+50; //RANDOM CHANCE

        if(iR >= 0 && iR < 90)
        {
            performattack(self, openborconstant("ANI_FOLLOW1"), 0); //90% CHANCE
        }
        else
        {
            performattack(self, openborconstant("ANI_FOLLOW2"), 0); //10% CHANCE
        }
    }
}

In this example, if you press the attack2 button, it will randomly perform follow1 or follow2 animations based on the defined chance.
Just rename both freespecial2/freespecial3 to follow1/follow2 and it will work fine. In case you need a "mp" cost (like energycost), you will need some additional lines, but I suggest trying this example first.
 
Solution
I suggest using keyscripts + follow animations for this feature. This is because, unlike freespecials, there's no event that may trigger follow animations accidentally, unless you force them with scripts or via "followanim/followcond".

That said, just create any .c file in your scripts folder and call it in your character header, like this:



After that, put a script like the example below:

Code:
void main()
{
    void self = getlocalvar("self");
    int pIndex = getlocalvar("player");
    int attack2 = playerkeys(pIndex, 1, "attack2");

    if(attack2)
    {
        int iR = rand()%50+50; //RANDOM CHANCE

        if(iR >= 0 && iR < 90)
        {
            performattack(self, openborconstant("ANI_FOLLOW1"), 0); //90% CHANCE
        }
        else
        {
            performattack(self, openborconstant("ANI_FOLLOW2"), 0); //10% CHANCE
        }
    }
}

In this example, if you press the attack2 button, it will randomly perform follow1 or follow2 animations based on the defined chance.
Just rename both freespecial2/freespecial3 to follow1/follow2 and it will work fine. In case you need a "mp" cost (like energycost), you will need some additional lines, but I suggest trying this example first.
Thank you for the reply. I researched a different method and managed to solve it.
anim freespecial45
offset 238 177
@script
void self = getlocalvar("self");
int r;

if(frame == 0)
{
r = rand() % 10; // 0–9

if(r == 0) // 1 / 10 = 10%
{
changeentityproperty(
self,
"animation",
openborconstant("ANI_freespecial44")
);
}
}
@end_script
loop 0


I solved it this way.
 
Back
Top Bottom