1. Hey Guest, is it this your first time on the forums?

    Visit the Beginner's Box

    Introduce yourself, read some of the ins and outs of the community, access to useful links and information.

    Dismiss Notice

Getting a custom front arm anim for archer

Discussion in 'Modding Help' started by 8x, May 27, 2016.

  1. 8x

    8x Elimination Et Choix Traduisant la Realité Forum Moderator Staff Alumni Tester
    1. The Young Blood Collective - [YB]

    Messages:
    1,325
    So I'm trying to make the bow animation different for a character that shoots. The vanilla one has 3 frames for "Charge" and 1 frame for "Fired" (plus 1 for no arrow but it's not important here). So I modified FighterAnim.as (it's based on archer) to have a separate png for the front arm anim when shooting/charging:
    Code:
    void LoadSprites(CSprite@ this)
    {
        string texname = this.getBlob().getSexNum() == 0 ?
                         "Entities/Characters/Fighter/FighterMale.png" :
                         "Entities/Characters/Fighter/FighterMale.png";
        this.ReloadSprite(texname, this.getConsts().frameWidth, this.getConsts().frameHeight,
                          this.getBlob().getTeamNum(), this.getBlob().getSkinNum());
        this.RemoveSpriteLayer("frontarm");
        CSpriteLayer@ frontarm = this.addSpriteLayer("frontarm", "Arm_Fire.png" , 32, 16, this.getBlob().getTeamNum(), this.getBlob().getSkinNum());
    // copied the way FUN implements longbow into its character "Hunter" for an external png arm fire anim
        if (frontarm !is null)
        {
            Animation@ animcharge = frontarm.addAnimation("charge", 0, false);
            animcharge.AddFrame(5);
            Animation@ animshoot = frontarm.addAnimation("fired", 0, false);
            animshoot.AddFrame(0);
            animshoot.AddFrame(1);
            animshoot.AddFrame(2);
            animshoot.AddFrame(3);
            animshoot.AddFrame(4);
            Animation@ animnoarrow = frontarm.addAnimation("no_arrow", 0, false);
            animnoarrow.AddFrame(5);
            frontarm.SetOffset(Vec2f(-1.0f, 5.0f) + config_offset);
            frontarm.SetAnimation("fired");
            frontarm.SetVisible(false);
        }
    and this is how the additional PNG looks like:
    arm harlp.png

    The problem is that the "Fired" still only casts 1 frame step (the frame 0 above), and "Charging" still casts 3 steps I believe (frame 5 above).

    Where else do I have to change or add code? Keep in mind I won't easily understand all of it, and hardly will be able to put complex code in the files.
     
  2. Geti

    Geti Please avoid PMing me (poke a mod instead) THD Team Administrator Global Moderator

    Messages:
    3,730
    You're going to have to change where/how these are activated - and you're going to want to change the framerate on the animations too.
    Code:
    Animation@ addAnimation(name, frametime, looping);
    You're going to want to change the frametime from 0 - 0 wont animate at all (used for manually specifying frames from code).

    If you're basing your code directly off the archer code - the stuff you want is in ArcherAnim.as:DrawBow, around line 393 in the vanilla script (yours might have changed line numbers).
     
    8x likes this.
  3. 8x

    8x Elimination Et Choix Traduisant la Realité Forum Moderator Staff Alumni Tester
    1. The Young Blood Collective - [YB]

    Messages:
    1,325
    This is the part you mean I believe, inside void DrawWeapon, or it's at least the part in which "fired" appears inside it. I tried changing something there, but I simply don't understand it :U and can't see how the frames work there.

    Code:
    if (!fighter.has_arrow || fighter.charge_state == FighterParams::no_arrows || fighter.charge_state == FighterParams::legolas_charging)
        {
            string animname = "no_arrow";
    
            if (fighter.charge_time == FighterParams::ready_time)
            {
                animname = "fired";
            }
    
            u16 frontframe = 0;
            f32 temp = Maths::Min(fighter.charge_time, FighterParams::ready_time);
            f32 ready_tween = temp / FighterParams::ready_time;
            armangle = armangle * ready_tween;
            armOffset = Vec2f(-1.0f, 4.0f + 2.0f * (1.0f - ready_tween)) + config_offset;
            setArmValues(frontarm, true, armangle, 0.1f, animname, Vec2f(-4.0f * sign, 0.0f), armOffset);
            frontarm.animation.frame = frontframe;
    
            setArmValues(arrow, false, 0, 0, "default", Vec2f(), Vec2f());
        }
    A brief explanation on this part? I'll head on to IRC to push this further too.
     
  4. Geti

    Geti Please avoid PMing me (poke a mod instead) THD Team Administrator Global Moderator

    Messages:
    3,730
    er I'm still away but noticed you were having trouble with this

    see the part where it says "frontarm.animation.frame =" ? thats where it's setting the frame index for the animation; you can change what frame it sets there, or remove it and just use the normal animation system - changing the frame is used for the string pull stuff iirc.