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

About shared classes

Discussion in 'Modding Help' started by long_wood_bow, Mar 25, 2020.

  1. long_wood_bow

    long_wood_bow Bison Rider

    Messages:
    84
    Now I trying to make new classes, the Assassin.
    So, I made shared class, AssassinInfo in AssassinCommon.as and set it in onInit.
    But, it can't be changed value by script. So the script doesn't work fine.
    In AssassinCommon.as
    shared class AssassinInfo
    {
    bool time_to_use_left_knife;
    AssassinInfo()
    {
    time_to_use_left_knife = false;
    }
    };

    In AssassinLogic.as
    void onInit(CBlob@ this)
    {
    AssassinInfo assassin;
    this.set("assassinInfo", @assassin);
    ...
    }

    In AssassinAnim.as
    void onTick(CSprite@ this)
    {
    ...
    AssassinInfo@ assassin;
    if (!blob.get("assassinInfo", @assassin))
    {
    return;
    }
    ...
    else if(this.isAnimation("stab") && !this.isAnimationEnded())
    {
    this.SetAnimation("stab");
    }
    else if(this.isAnimation("stab_left") && !this.isAnimationEnded())
    {
    this.SetAnimation("stab_left");
    }
    else if(blob.isKeyPressed(key_action1))
    {
    this.SetAnimation(assassin.time_to_use_left_knife ? "stab_left" : "stab");
    assassin.time_to_use_left_knife = !assassin.time_to_use_left_knife;
    }
    ...
    }
    I want to make alternating stab animation, but does not work.
    Does anyone know about it?
     
  2. Vamist

    Vamist THD Team THD Team Tester

    Messages:
    544
    Look at the class .cfg file, thats where animations get set, if you need an example go look at builder, knights or even look at this mod here;
    https://forum.thd.vg/resources/templateclass.355/

    You need to tell the .cfg what sprites are used for what animation, and then you can set it in script like you are doing with this.SetAnimation("name")

    Also come join the kag discord (discord.gg/kag) as you'll get a quicker response in the #modding area
     
  3. long_wood_bow

    long_wood_bow Bison Rider

    Messages:
    84
    # stab_mid
    $sprite_animation_shoot_name = stab_mid
    u16 sprite_animation_shoot_time = 3
    u8_sprite_animation_shoot_loop = 1
    @u16 sprite_animation_shoot_frames = 19; 20; 21; 22;
    # stab_mid_left
    $sprite_animation_shoot_name = stab_mid_left
    u16 sprite_animation_shoot_time = 3
    u8_sprite_animation_shoot_loop = 1
    @u16 sprite_animation_shoot_frames = 19; 29; 31; 22;

    Also, this script doesn't work, only one sound is played.
    But if I merge AssassinCommon and AssassinLogic, it's work.
    In AssassinLogic.as
    AssassinInfo@ assassin;
    if (!this.get("assassinInfo", @assassin))
    {
    return;
    }
    if (assassin.time_to_use_left_knife)
    {
    this.getSprite().PlaySound("KnifeStab.ogg");
    assassin.time_to_use_left_knife = false;
    }
    else
    {
    this.getSprite().PlaySound("SwordSlash.ogg");
    assassin.time_to_use_left_knife = true;
    }