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

Help Combining TentLogic.as, KnightShop.as and ArcherShop.as

Discussion in 'Modding Help' started by Shadowblitz16, Mar 26, 2017.

Thread Status:
Not open for further replies.
  1. Shadowblitz16

    Shadowblitz16 Ballista Bolt Thrower

    Messages:
    158
    can someone help me combine TentLogic.as, KnightShop.as and ArcherShop.as

    basically I want to make the tent allow knights and archers to buy stuff.
    these are function that I found that break eachother.
    Code:
    // TentLogic.as
    void GetButtonsFor(CBlob@ this, CBlob@ caller)
    {
        // button for runner
        // create menu for class change
        if (canChangeClass(this, caller) && caller.getTeamNum() == this.getTeamNum())
        {
            CBitStream params;
            params.write_u16(caller.getNetworkID());
            caller.CreateGenericButton("$change_class$", Vec2f(0, 0), this, SpawnCmd::buildMenu, "Swap Class", params);
        }
    }
    
    void onCommand(CBlob@ this, u8 cmd, CBitStream @params)
    {
        onRespawnCommand(this, cmd, params);
    }
    
    
    // KnightShop.as
    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");
        }
    }
    
    and this a script I'm putting together to apply to my tent.cfg
    Code:
    
    // Knight Constants 
    s32 cost_bomb = 25;
    s32 cost_waterbomb = 30;
    s32 cost_keg = 120;
    s32 cost_mine = 60;
    
    void onInit(CBlob@ this)
    {
        if (getRules().exists("ctf_costs_config"))
        {
            cost_config_file = getRules().get_string("ctf_costs_config");
        }
       
        ConfigFile cfg = ConfigFile();
        cfg.loadFile(cost_config_file);
    
        cost_bomb = cfg.read_s32("cost_bomb_plain", cost_bomb);
        cost_waterbomb = cfg.read_s32("cost_bomb_water", cost_waterbomb);
        cost_mine = cfg.read_s32("cost_mine", cost_mine);
        cost_keg = cfg.read_s32("cost_keg", cost_keg);
    
        // SHOP
        this.set_Vec2f("shop offset", Vec2f_zero);
        this.set_Vec2f("shop menu size", Vec2f(4, 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", "knight");
    
        {
            ShopItem@ s = addShopItem(this, "Bomb", "$bomb$", "mat_bombs", descriptions[1], true);
            AddRequirement(s.requirements, "coin", "", "Coins", cost_bomb);
        }
        {
            ShopItem@ s = addShopItem(this, "Water Bomb", "$waterbomb$", "mat_waterbombs", descriptions[52], true);
            AddRequirement(s.requirements, "coin", "", "Coins", cost_waterbomb);
        }
        {
            ShopItem@ s = addShopItem(this, "Mine", "$mine$", "mine", descriptions[20], false);
            AddRequirement(s.requirements, "coin", "", "Coins", cost_mine);
        }
        {
            ShopItem@ s = addShopItem(this, "Keg", "$keg$", "keg", descriptions[4], false);
            AddRequirement(s.requirements, "coin", "", "Coins", cost_keg);
        }
    
     
  2. makmoud98

    makmoud98 You are already DEAD Forum Moderator Staff Alumni Tester

    Messages:
    586
    i dont understand what you mean. like do u want 2 buttons; 1 for switching classes and 1 for buying stuff?
    you cant just copy/paste shit from another script and then put it into another that makes no sense.
    you obviously have no idea what you are doing or how the code works at all. if anything, this should be in mod requests because you cant help someone who has no idea. at the same time, you did not even define a clear explanation of what you are trying to accomplish. you cant just "combine" 3 scripts together.

    ranting aside, i will start with some actual advice/tips. first of all, you cannot have multiple of the same hook in the same script. ex:
    Code:
    void onTick(CBlob@ this){
    print("hi");
    }
    
    void onTick(CBlob@ this){
    print("hello");
    }
    the compiler has no way of knowing which function to call.
    honestly, there are far more issues that require too many walls of words that probably wont get read (or even understood). so i have to recommend you to learn some c++ to get a general idea of how the code even works. you could spend many many many hours of guesswork and maybe get something close to what you wanted, but it is far more productive and helpful to just learn.
    i recommend http://www.learncpp.com/ this is where many people advised me to start, and you should do the same.
     
  3. Shadowblitz16

    Shadowblitz16 Ballista Bolt Thrower

    Messages:
    158
    I would post a request but they seem to never get accepted so I just tried to do it on my own.
    I do have some experience with c++ but kag mods do not use c++ they use anglescript and a ton of weird syntax.

    I did look up angle script but I couldn't find anything on the weird symbols like # and @
    there is also things that look like string flags for setting certain properies.

    I can understand a little bit, but there is no indepth video tutorial on kag modding and text tutorials on kag modding are very limited and don't cover every topic.
     
  4. makmoud98

    makmoud98 You are already DEAD Forum Moderator Staff Alumni Tester

    Messages:
    586
    c++ and angelscript are very similar. # are used the same way in c++ as in angelscript. @ is the symbol for handles, you can read up on it here
     
  5. Shadowblitz16

    Shadowblitz16 Ballista Bolt Thrower

    Messages:
    158
    thankyou.
    however I still have a ton of unanswered questions hopefully you will be able to provide them.

    ok first question what is the most basic code for creating a button and a hook for it?
    second question can you explain what these sections of code do? I commented them to the best of my knowledge.
    Code:
    // Knight Workshop
    
    #include "Requirements.as"
    #include "ShopCommon.as";
    #include "Descriptions.as";
    #include "WARCosts.as";
    #include "CheckSpam.as";
    #include "CTFShopCommon.as";
    
    //default costs?
    s32 cost_bomb = 25;
    s32 cost_waterbomb = 30;
    s32 cost_keg = 120;
    s32 cost_mine = 60;
    
    void onInit(CBlob@ this)
    {
        //set the shop blob background
        this.set_TileType("background tile", CMap::tile_wood_back);
       
        //set the z position?
        this.getSprite().SetZ(-50); //background
        //make it nonsolid?
        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_bomb = cfg.read_s32("cost_bomb_plain", cost_bomb);
        cost_waterbomb = cfg.read_s32("cost_bomb_water", cost_waterbomb);
        cost_mine = cfg.read_s32("cost_mine", cost_mine);
        cost_keg = cfg.read_s32("cost_keg", cost_keg);
    
        // SHOP
        //I know the second parameter is the value but what is the first?
        this.set_Vec2f("shop offset", Vec2f_zero);
        this.set_Vec2f("shop menu size", Vec2f(4, 1));
        this.set_string("shop description", "Buy");
        this.set_u8("shop icon", 25);
    
        // CLASS
        // same with this I'm guessing the first paramater is a string command?
        this.set_Vec2f("class offset", Vec2f(-6, 0));
        this.set_string("required class", "knight");
    
        {
            //adds shop item
            ShopItem@ s = addShopItem(this, "Bomb", "$bomb$", "mat_bombs", descriptions[1], true);
            //???
            AddRequirement(s.requirements, "coin", "", "Coins", cost_bomb);
        }
        {
            //adds shop item
            ShopItem@ s = addShopItem(this, "Water Bomb", "$waterbomb$", "mat_waterbombs", descriptions[52], true);
            //???
            AddRequirement(s.requirements, "coin", "", "Coins", cost_waterbomb);
        }
        {
            //adds shop item
            ShopItem@ s = addShopItem(this, "Mine", "$mine$", "mine", descriptions[20], false);
            //???
            AddRequirement(s.requirements, "coin", "", "Coins", cost_mine);
        }
        {
            //adds shop item
            ShopItem@ s = addShopItem(this, "Keg", "$keg$", "keg", descriptions[4], false);
            //???
            AddRequirement(s.requirements, "coin", "", "Coins", cost_keg);
        }
    }
    
    //these come from Production.as. not sure why this is redeclared.
    void GetButtonsFor(CBlob@ this, CBlob@ caller)
    {
        if(caller.getConfig() == this.get_string("required class"))
        {
            this.set_Vec2f("shop offset", Vec2f_zero); // posiably setting it offscreen but looking at the if statement it looks like its checking if the required class DOES equal the players class.
        }
        else
        {
            this.set_Vec2f("shop offset", Vec2f(6, 0)); //I'm guessing this is setting the button offscreen of behind another button? where is the other button?
        }
        this.set_bool("shop available", this.isOverlapping(caller)); //Not sure possibly checking if the button is pressed?
    }
    //these come from Production.as. not sure why this is redeclared.
    void onCommand(CBlob@ this, u8 cmd, CBitStream @params)
    {
        if (cmd == this.getCommandID("shop made item")) //looks like they are string commands. however I'm not sure where its telling it what item to give.
        {
            this.getSprite().PlaySound("/ChaChing.ogg"); //playing sound
        }
    }
    
     
  6. Verrazano

    Verrazano Flat Chested Haggy Old Souless Witchy Witch Witch THD Team Global Moderator Forum Moderator Tester
    1. Practitioners of War Extreme Revolution - POWER

    Messages:
    477
Thread Status:
Not open for further replies.