Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

So I really hate to keep bothering you, but I've got another one. I can't seem to figure out how to add more animations. Say for example I want to add an extra keyframe to the sword attack animation; I create a new macro for that keyframe, add that keyframe to the skelani_init_all_keyframes script, and then add the macro for that keyframe to the array for the skani_ATTACK_SWORD in the skelani_init_all_animations script. This doesn't seem to do anything however, as the attack animation continues to only show the two original frames.

The attack animation in psm_melee uses skelani_set_animation to explicitly set the animation frame instead of playing it automatically, this is why you don't see the new frame at the end play out. Since all the default attack animations have 2 frames, the hardcoded 0 and 1 will work, but one thing you could do if you want more intricate animations is to use global.skelani_animation_length[argument0] instead of 1 when setting the animation, and for the line that goes

skelani_set_animation(atkanimation,(statecntr-atkwarmup)/atkduration)

you'd instead use

skelani_set_animation(atkanimation,global.skelani_animation_length[argument0]*(statecntr-atkwarmup)/atkduration)

(which means you interpolate between all the frames instead of just the first two)

Since indexing starts at 0 you might need to use (global.skelani_animation_length[argument0]-1) instead of just global.skelani_animation_length[argument0] to prevent the animation from looping back to the first keyframe at the end, I don't remember if the length is inclusive or not.

I seem to just be getting this error upon trying this: 


___________________________________________

############################################################################################

FATAL ERROR in

action number 1

of  Step Event0

for object obj_player:

DoConv :1: illegal undefined/null use

 at gml_Script_psm_melee (line 19) -     skelani_set_animation(atkanimation,global.skelani_animation_length[argument0]*(statecntr-atkwarmup)/atkduration)

############################################################################################

--------------------------------------------------------------------------------------------

stack frame is

gml_Script_psm_melee (line 19)

called from - gml_Object_obj_player_Step_0 (line 81) -     script_execute(state)

Oh wait, I'm stupid... you should use atkanimation instead of argument0 when reading the animation length (I was looking at skelani_set_animation when giving you advice for psm_melee). psm_melee has no arguments so argument0 is undefined when it's run, the attack animation in use is in the atkanimation variable.

(So replace the global.skelani_animation_length[argument0] with global.skelani_animation_length[atkanimation] everywhere in psm_melee and it should work)

So I reverted psm_melee back to how it originally was, so it looks like this:


statecntr++

if(statecntr < atkwarmup){

    skelani_set_animation(atkanimation,0)

}

else if(statecntr < atkwarmup + atkduration){

    skelani_set_animation(atkanimation,(statecntr-atkwarmup)/atkduration)

}

else if(statecntr == atkwarmup + atkduration){

    skelani_set_animation(atkanimation,1)

    n = instance_create(x,y,atkhitboxobj)

    n.image_xscale = skelani_xscale

    n.sprite_index = atkhitboxspr

    with(n){

        player_weapon_get_stat_block_current()

        

        //Heavy attacks are 30% stronger, but only for melee weaposn, so this code is only here.

        if(other.atk_isheavy){

            rpg_adjust_atk_stat_block_uniformly(1.3,0)

        }

        

        //When winded, lower power of attack

        if(other.atk_winded){

            rpg_adjust_atk_stat_block_uniformly(0.7,0)

        }

        

        //When wielding a weapon without proper stats, power is reduced greatly.

        var str, dex, int, fth;

        str = db_read_stat(itemtype_WEAPON,other.atk_weapon,wd_REQUIREMENT_STR)

        dex = db_read_stat(itemtype_WEAPON,other.atk_weapon,wd_REQUIREMENT_DEX)

        int = db_read_stat(itemtype_WEAPON,other.atk_weapon,wd_REQUIREMENT_INT)

        fth = db_read_stat(itemtype_WEAPON,other.atk_weapon,wd_REQUIREMENT_FTH)

        if(!player_meets_requirements(str,dex,int,fth)){

            rpg_adjust_atk_stat_block_uniformly(0.1,0)

        }

    }

    n.lifetime      = atkduration

    n.blockbreaker  = player_weapon_get_stat(wd_BLOCKBREAKER)

}

else if(statecntr < atkwarmup + atkduration + atkcooldown){

    skelani_set_animation(atkanimation,1)

}

else{

    state = psm_ordinary

}


So from there, where should I be making these changes? Trying to go back through your instructions from the previous comment and then altering them with the new information doesn't seem to be working, unless I'm just putting something in the wrong place :/

Okay, to recap in a bit more structured way: the skelani_set_animation(atkanimation,(statecntr-atkwarmup)/atkduration) line should be multiplied with the number of frames in the animation, and any skelani_set_animation(atkanimation,1) should instead set it to the final frame.

It might be easier to do these changes if you add this line right below "statecntr++" to read out the length to a variable:

var anilen = global.skelani_animation_length[atkanimation];

Then use anilen as the length in the code:

skelani_set_animation(atkanimation,anilen) //Originally ended in "1"
skelani_set_animation(atkanimation,anilen*(statecntr-atkwarmup)/atkduration) //The interpolating one

If it acts weird, try setting anilen to global.skelani_animation_length[atkanimation] - 1 instead.

even after all of this stuff, it still seems to only want to use two frames and interpolate between them. It now just recognizes the first and the last frame, skipping any frames between them.

I tried out the changes myself and it works for me, with the one small change I mentioned:

var anilen = global.skelani_animation_length[atkanimation] - 1;

(It's a bit tricky to see since the animation is only 5 frames long, but you can press "Home" to lower the framerate to 10/s)


So the full, working script looks like this:

/// @description psm_melee()
function psm_melee() {
    var anilen = global.skelani_animation_length[atkanimation] - 1;
    //Physics
    if(onground){
        player_naturalfriction()
    }
    player_controls_jump() //Can jump-cancel
    player_inertia_x()
    player_inertia_y()
    player_boundaryclamp()
    //Animate, spawn attack
    statecntr++
    if(statecntr < atkwarmup){
        skelani_set_animation(atkanimation,0)
    }
    else if(statecntr < atkwarmup + atkduration){
        skelani_set_animation(atkanimation,anilen*(statecntr-atkwarmup)/atkduration)
    }
    else if(statecntr == atkwarmup + atkduration){
        skelani_set_animation(atkanimation,anilen)
        n = instance_create(x,y,atkhitboxobj)
        n.image_xscale = skelani_xscale
        n.sprite_index = atkhitboxspr
        with(n){
            player_weapon_get_stat_block_current()
        
            //Heavy attacks are 30% stronger, but only for melee weaposn, so this code is only here.
            if(other.atk_isheavy){
                rpg_adjust_atk_stat_block_uniformly(1.3,0)
            }
        
            //When winded, lower power of attack
            if(other.atk_winded){
                rpg_adjust_atk_stat_block_uniformly(0.7,0)
            }
        
            //When wielding a weapon without proper stats, power is reduced greatly.
            var str, dex, int, fth;
            str = db_read_stat(itemtype_WEAPON,other.atk_weapon,wd_REQUIREMENT_STR)
            dex = db_read_stat(itemtype_WEAPON,other.atk_weapon,wd_REQUIREMENT_DEX)
            int = db_read_stat(itemtype_WEAPON,other.atk_weapon,wd_REQUIREMENT_INT)
            fth = db_read_stat(itemtype_WEAPON,other.atk_weapon,wd_REQUIREMENT_FTH)
            if(!player_meets_requirements(str,dex,int,fth)){
                rpg_adjust_atk_stat_block_uniformly(0.1,0)
            }
        }
        n.lifetime      = atkduration
        n.blockbreaker  = player_weapon_get_stat(wd_BLOCKBREAKER)
    }
    else if(statecntr < atkwarmup + atkduration + atkcooldown){
        skelani_set_animation(atkanimation,anilen)
    }
    else{
        state = psm_ordinary
    }
    //Handle animation with correct hand
    player_animate_offhandswap()
    //Kneel down when crouching
    if(crouching){
        skelani_override_crouch()
    }
}