1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. 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

Problem rendering new item in archer shop

Discussion in 'Modding Help' started by Blue_Tiger, Oct 15, 2016.

  1. Blue_Tiger

    Blue_Tiger Bison Rider Tester

    Messages:
    899
    Hi I'm making a more-arrows mod and I'm having trouble rendering arrows into the archer shop. I created a new image in BasicHelps.as called "$mat_heartarrows$". And then when I try to render it into an archershop, it works at first - but as soon as I buy one of them, it doesn't work anymore and instead renders mat_stone instead. Do I have to make a separate .as file for it to work, and if so, how would I do it? I couldn't find where $mat_arrows$ were created so I can't fit them in with them there.

    I'm pretty new to modding KAG but I can do basic programming without problems.

    BasicHelps.as:
    #include "Help.as"

    #define CLIENT_ONLY

    void onInit(CRules@ this)
    {
    // knight
    AddIconToken("$Bomb$", "Entities/Characters/Knight/KnightIcons.png", Vec2f(16, 32), 0);
    AddIconToken("$WaterBomb$", "Entities/Characters/Knight/KnightIcons.png", Vec2f(16, 32), 2);
    AddIconToken("$Satchel$", "Entities/Characters/Knight/KnightIcons.png", Vec2f(16, 32), 3);
    AddIconToken("$Keg$", "Entities/Characters/Knight/KnightIcons.png", Vec2f(16, 32), 4);
    AddIconToken("$Help_Bomb1$", "Entities/Common/GUI/HelpIcons.png", Vec2f(8, 16), 30);
    AddIconToken("$Help_Bomb2$", "Entities/Common/GUI/HelpIcons.png", Vec2f(8, 16), 31);
    AddIconToken("$Swap$", "Entities/Common/GUI/HelpIcons.png", Vec2f(16, 16), 7);
    AddIconToken("$Jab$", "Entities/Common/GUI/HelpIcons.png", Vec2f(16, 16), 20);
    AddIconToken("$Slash$", "Entities/Common/GUI/HelpIcons.png", Vec2f(16, 16), 21);
    AddIconToken("$Shield$", "Entities/Common/GUI/HelpIcons.png", Vec2f(16, 16), 22);
    // archer
    AddIconToken("$Arrow$", "Entities/Characters/Archer/ArcherIcons.png", Vec2f(16, 32), 0);
    AddIconToken("$WaterArrow$", "Entities/Characters/Archer/ArcherIcons.png", Vec2f(16, 32), 1);
    AddIconToken("$FireArrow$", "Entities/Characters/Archer/ArcherIcons.png", Vec2f(16, 32), 2);
    AddIconToken("$BombArrow$", "Entities/Characters/Archer/ArcherIcons.png", Vec2f(16, 32), 3);
    AddIconToken("$HeartArrow$", "Entities/Characters/Archer/ArcherIcons.png", Vec2f(16, 32), 4);
    AddIconToken("$PiercingArrow$", "Entities/Characters/Archer/ArcherIcons.png", Vec2f(16, 32), 5);
    AddIconToken("$Daggar$", "Entities/Common/GUI/HelpIcons.png", Vec2f(16, 16), 10);
    AddIconToken("$Help_Arrow1$", "Entities/Common/GUI/HelpIcons.png", Vec2f(8, 16), 28);
    AddIconToken("$Help_Arrow2$", "Entities/Common/GUI/HelpIcons.png", Vec2f(8, 16), 29);
    AddIconToken("$Swap$", "Entities/Common/GUI/HelpIcons.png", Vec2f(16, 16), 7);
    AddIconToken("$Grapple$", "Entities/Common/GUI/HelpIcons.png", Vec2f(16, 16), 16);
    // builder
    AddIconToken("$Build$", "Entities/Common/GUI/HelpIcons.png", Vec2f(16, 16), 11);
    AddIconToken("$Pick$", "Entities/Common/GUI/HelpIcons.png", Vec2f(16, 16), 12);
    AddIconToken("$Rotate$", "Entities/Common/GUI/HelpIcons.png", Vec2f(16, 16), 5);
    AddIconToken("$Help_Block1$", "Entities/Common/GUI/HelpIcons.png", Vec2f(8, 16), 12);
    AddIconToken("$Help_Block2$", "Entities/Common/GUI/HelpIcons.png", Vec2f(8, 16), 13);
    AddIconToken("$Swap$", "Entities/Common/GUI/HelpIcons.png", Vec2f(16, 16), 7);
    AddIconToken("$BlockStone$", "Sprites/world.png", Vec2f(8, 8), 96);

    AddIconToken("$workshop$", "Entities/Common/GUI/HelpIcons.png", Vec2f(16, 16), 2);

    AddIconToken("$mat_heartarrows$", "Entities/Characters/Archer/Materials.png", Vec2f(16, 16), 32);
    AddIconToken("$mat_piercingarrows$", "Entities/Characters/Archer/Materials.png", Vec2f(16, 16),
    33);
    }

    void onBlobCreated(CRules@ this, CBlob@ blob)
    {
    if (!u_showtutorial)
    return;

    const string name = blob.getName();

    if (blob.hasTag("seats") && !blob.hasTag("animal"))
    {
    SetHelp(blob, "help hop", "", " $down_arrow$ Hop inside $KEY_S$", "", 5);
    SetHelp(blob, "help hop out", "", " Get out $KEY_W$", "", 4);
    }
    if (blob.hasTag("trader"))
    {
    SetHelp(blob, "help use", "", "$trader$ Buy $KEY_E$", "", 3);
    }
    if (blob.hasTag("respawn"))
    {
    SetHelp(blob, "help use", "", "$CLASSCHANGE$ Change class $KEY_E$", "", 3);
    }
    if (blob.hasTag("door"))
    {
    SetHelp(blob, "help rotate", "", "$" + blob.getName() + "$" + " $Rotate$ Rotate $KEY_SPACE$", "", 3);
    }



    if (name == "hall")
    {
    SetHelp(blob, "help use", "", "$CLASSCHANGE$ Change class $KEY_E$", "", 5);
    }
    else if (name == "trap_block")
    {
    SetHelp(blob, "help show", "builder", "$trap_block$ Opens on enemy", "", 15);
    }
    else if (name == "spikes")
    {
    SetHelp(blob, "help show", "builder", "$spikes$ Retracts on enemy if on stone $STONE$", "", 20);
    }
    else if (name == "wooden_platform")
    {
    SetHelp(blob, "help rotate", "", "$wooden_platform$ $Rotate$ Rotate $KEY_SPACE$", "", 3);
    }
    else if (name == "ladder")
    {
    SetHelp(blob, "help rotate", "", "$ladder$ $Rotate$ Rotate $KEY_SPACE$", "", 3);
    }
    else if (name == "tdm_ruins")
    {
    SetHelp(blob, "help use", "", "Change class $KEY_E$", "", 5);
    }
    else if (name == "lantern")
    {
    SetHelp(blob, "help activate", "", "$lantern$ On/Off $KEY_SPACE$", "");
    SetHelp(blob, "help pickup", "", "$lantern$ Pick up $KEY_C$");
    }
    else if (name == "satchel")
    {
    SetHelp(blob, "help activate", "knight", "$satchel$ Light $KEY_SPACE$", "$satchel$ Only KNIGHT can light satchel", 3);
    SetHelp(blob, "help throw", "knight", "$satchel$ THROW! $KEY_SPACE$", "", 3);
    }
    else if (name == "log")
    {
    SetHelp(blob, "help action2", "builder", "$log$ Chop $mat_wood$ $RMB$", "", 3);
    }
    else if (name == "keg")
    {
    SetHelp(blob, "help pickup", "", "$keg$Pick up $KEY_C$", "", 3);
    SetHelp(blob, "help activate", "knight", "$keg$Light $KEY_SPACE$", "$keg$Only KNIGHT can light keg", 5);
    SetHelp(blob, "help throw", "", "$keg$THROW! $KEY_SPACE$", "", 3);
    }
    else if (name == "bomb")
    {
    SetHelp(blob, "help throw", "", "$mat_bombs$THROW! $KEY_SPACE$", "", 3);
    }
    else if (name == "crate")
    {
    SetHelp(blob, "help pickup", "", "$crate$Pick up $KEY_C$", "", 3);
    }
    else if (name == "workbench")
    {
    SetHelp(blob, "help use", "", "$workbench$ $KEY_TAP$$KEY_E$", "", 4);
    }
    else if (name == "catapult" || name == "ballista")
    {
    SetHelp(blob, "help DRIVER movement", "", "$" + blob.getName() + "$" + "Drive $KEY_A$ $KEY_S$ $KEY_D$", "", 3);
    SetHelp(blob, "help GUNNER action", "", "$" + blob.getName() + "$" + "FIRE $KEY_HOLD$$LMB$", "", 3);
    }
    else if (name == "mounted_bow")
    {
    SetHelp(blob, "help GUNNER action", "", "$" + blob.getName() + "$" + "FIRE $LMB$", "", 3);
    }
    else if (name == "food")
    {
    SetHelp(blob, "help switch", "", "$food$Take out food $KEY_HOLD$$KEY_F$", "", 3);
    }
    else if (name == "boulder")
    {
    SetHelp(blob, "help pickup", "", "$boulder$ Pick up $KEY_C$");
    }
    //else if (name == "tent")
    //{
    // SetHelp( blob, "help use", "", "Change class $KEY_E$", "", 5 );
    //}
    else if (name == "building")
    {
    SetHelp(blob, "help use", "", "$building$Construct $KEY_E$", "", 3);
    }
    else if (name == "archershop" || name == "boatshop" || name == "knightshop" || name == "buildershop" || name == "vehicleshop")
    {
    SetHelp(blob, "help use", "", "$building$Use $KEY_E$", "", 3);
    }
    //else if (name == "ctf_flag")
    //{
    // SetHelp( blob, "help use", "", "$$ctf_flag$ Bring enemy flag to capture", "", 3 );
    //}
    }

    Archershop.as:

    // ArcherShop.as

    #include "Requirements.as";
    #include "ShopCommon.as";
    #include "Descriptions.as";
    #include "CheckSpam.as";
    #include "CTFShopCommon.as";

    s32 cost_arrows = 15;
    s32 cost_waterarrows = 20;
    s32 cost_firearrows = 30;
    s32 cost_bombarrows = 50;
    s32 cost_heartarrows = 20;
    s32 cost_piercingarrows = 20;

    void onInit(CBlob@ this)
    {
    this.set_TileType("background tile", CMap::tile_wood_back);

    this.getSprite().SetZ(-50); //background
    this.getShape().getConsts().mapCollisions = false;

    //load config
    if (getRules().exists("ctf_costs_config"))
    {
    cost_config_file = getRules().get_string("ctf_costs_config");
    }

    ConfigFile cfg = ConfigFile();
    cfg.loadFile(cost_config_file);

    cost_arrows = cfg.read_s32("cost_arrows", cost_arrows);
    cost_waterarrows = cfg.read_s32("cost_waterarrows", cost_waterarrows);
    cost_firearrows = cfg.read_s32("cost_firearrows", cost_firearrows);
    cost_bombarrows = cfg.read_s32("cost_bombarrows", cost_bombarrows);
    cost_heartarrows = cfg.read_s32("cost_heartarrows", cost_heartarrows);
    cost_piercingarrows = cfg.read_s32("cost_piercingarrows", cost_piercingarrows);

    // SHOP
    this.set_Vec2f("shop offset", Vec2f_zero);
    this.set_Vec2f("shop menu size", Vec2f(6, 1));
    this.set_string("shop description", "Buy");
    this.set_u8("shop icon", 25);

    // CLASS
    this.set_Vec2f("class offset", Vec2f(-6, 0));
    this.set_string("required class", "archer");

    {
    ShopItem@ s = addShopItem(this, "Arrows", "$mat_arrows$", "mat_arrows", descriptions[2], true);
    AddRequirement(s.requirements, "coin", "", "Coins", cost_arrows);
    }
    {
    ShopItem@ s = addShopItem(this, "Water Arrows", "$mat_waterarrows$", "mat_waterarrows", descriptions[50], true);
    AddRequirement(s.requirements, "coin", "", "Coins", cost_waterarrows);
    }
    {
    ShopItem@ s = addShopItem(this, "Fire Arrows", "$mat_firearrows$", "mat_firearrows", descriptions[32], true);
    AddRequirement(s.requirements, "coin", "", "Coins", cost_firearrows);
    }
    {
    ShopItem@ s = addShopItem(this, "Bomb Arrows", "$mat_bombarrows$", "mat_bombarrows", descriptions[51], true);
    AddRequirement(s.requirements, "coin", "", "Coins", cost_bombarrows);
    }
    {
    ShopItem@ s = addShopItem(this, "Heart Arrows", "$mat_heartarrows$", "mat_heartarrows", descriptions[61], true);
    AddRequirement(s.requirements, "coin", "", "Coins", cost_heartarrows);
    }
    {
    ShopItem@ s = addShopItem(this, "Piercing Arrows", "$mat_piercingarrows$", "mat_piercingarrows", descriptions[62], true);
    AddRequirement(s.requirements, "coin", "", "Coins", cost_piercingarrows);
    }

    }

    void GetButtonsFor(CBlob@ this, CBlob@ caller)
    {
    if(caller.getConfig() == this.get_string("required class"))
    {
    this.set_Vec2f("shop offset", Vec2f_zero);
    }
    else
    {
    this.set_Vec2f("shop offset", Vec2f(6, 0));
    }
    this.set_bool("shop available", this.isOverlapping(caller));
    }

    void onCommand(CBlob@ this, u8 cmd, CBitStream @params)
    {
    if(cmd == this.getCommandID("shop made item"))
    {
    this.getSprite().PlaySound("/ChaChing.ogg");
    }
    }

    Video of what happens:
     
  2. blackjoker77777

    blackjoker77777 Haxor Tester
    1. Zen Laboratories

    Messages:
    441
    Try adding this
    Code:
    AddIconToken("$mat_heartarrows$", "Entities/Characters/Archer/Materials.png", Vec2f(16, 16), 32);
    AddIconToken("$mat_piercingarrows$", "Entities/Characters/Archer/Materials.png", Vec2f(16, 16), 33);
    To the "ArcherShop.as", under the onInit(CBlob@ this) hook.
    It should become something similar to this:
    upload_2016-10-15_16-36-36.png
    And voila, your issue's supposed to be solved.
    Have a nice day.
     
  3. Blue_Tiger

    Blue_Tiger Bison Rider Tester

    Messages:
    899
    Okay, thanks a lot.

    Nevermind, it didn't work. Now it just always shows up as stone/wood.
     
    Last edited: Oct 15, 2016
  4. blackjoker77777

    blackjoker77777 Haxor Tester
    1. Zen Laboratories

    Messages:
    441
    Then you must have specified a wrong path to the sprite.
    change that "Materials.png" to the right png, or just change "32" | "33" to their right order if the arrows sprites exist inside 'Materials.png', good luck.
    @E: you can post the png you used (and it's path) over here, and I might manage to help you further in case you didn't manage to fix it.
     
  5. Blue_Tiger

    Blue_Tiger Bison Rider Tester

    Messages:
    899
    Okay, actually it does the same thing as before. For some reason I had another version of ArcherShop.as open but if I do it in the right version, it shows up correctly, then changes to stone/wood after one purchase.

    I was using the Materials.png image from the path I included - I extended it downwards so it looks like this:
    [​IMG]

    but after I also tried making a separate "Materials2.png" file in my mod:

    [​IMG]

    And used 0 / 1 for it instead of 32 / 33. It still doesn't work and still goes back to stone and wood.

    It's definitely finding the file otherwise it wouldn't render the heart/piercing arrow the first time, it's just doing some weird shit after and I'm really confuse about it.
    [​IMG]
     
  6. blackjoker77777

    blackjoker77777 Haxor Tester
    1. Zen Laboratories

    Messages:
    441
    hmm, interesting.
    Could you please upload the whole mod? (or send it via PM if you don't want it publicly accessible)
    That could help figuring out what actually went wrong.
     
  7. Blue_Tiger

    Blue_Tiger Bison Rider Tester

    Messages:
    899
    Okay, one sec.
     
  8. blackjoker77777

    blackjoker77777 Haxor Tester
    1. Zen Laboratories

    Messages:
    441
    The problem is apparently solved, please have a look on the PM.
    I'll post the details over here in case anyone else faces the same issue at some point.
    The solution was about putting the arrows sprites in a new 32X16 png, with a different name ("NewArrowsThingy.png" in this example).
    Later on, adding the icon tokens of the new arrows with new names (different names than those predeclared in the "BasicHelp.as") under the onInit() hook in the "ArcherShop.as" script.
    upload_2016-10-15_22-11-11.png
    I still consider this issue some sort of odd behavior, I mean I find no logical explanation on why the sprite rolled back to the mat_stone/mat_wood ones, maybe someone else could actually answer that..
    I simply think the game had a hard time switching from the mat_heartarrow declared in the "BasicHelp.as" and the one declared under the "ArcherShop.as" (due to having the same name)? but why doesn't it seem to work when the sprites exist in the "Materials.png"?
    The bright side, we found a way to bypass the issue.
    The downside, I have zero idea on why that actually occurred that way..
    @makmoud98 any thoughts? :huh?:
     
    Last edited: Oct 15, 2016
  9. Frikman

    Frikman Bison Rider

    Messages:
    162
    It's an odd bug indeed, but what blackjoker suggested should work fine. I've found myself editing more DefaultGUI.as to work around the issue of icons, adding lines for each new thing and such