1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Question Using an item on an object?

Discussion in 'Developer Support' started by TheChuck, May 31, 2018.

  1. TheChuck

    Joined:
    Sep 25, 2017
    Messages:
    5
    Likes Received:
    2
    Alright so, I'm trying to use an earth rune on the fire altar in order to make lava runes. I've tried a few different methods and i cant seem to get the bot to even select the Earth rune. Yet alone use it on the altar.

    I'm extremely new to Java, so any help would be greatly appreciated. I'm sure i'm not doing everything the cleanest way possible, at this point i'm just trying to limp through it then work out the kinks later.

    Code (Text):
    1. package com.rootbots.runecrafting.LavaRunes.leafs;
    2.  
    3. import com.runemate.game.api.hybrid.Environment;
    4. import com.runemate.game.api.hybrid.entities.GameObject;
    5. import com.runemate.game.api.hybrid.local.hud.interfaces.Inventory;
    6. import com.runemate.game.api.hybrid.local.hud.interfaces.SpriteItem;
    7. import com.runemate.game.api.hybrid.location.Coordinate;
    8. import com.runemate.game.api.hybrid.region.GameObjects;
    9. import com.runemate.game.api.osrs.local.hud.interfaces.Magic;
    10. import com.runemate.game.api.script.framework.tree.LeafTask;
    11.  
    12. /**
    13. * NOTES:
    14. * if we arent at castle wars, and we have 26 essence, we are and the altar is visible
    15. Use Magic Imbue and use Earth Rune on Altar
    16. */
    17. public class CraftRune extends LeafTask {
    18.  
    19.     Coordinate altarRegion = new Coordinate(2583, 4840, 0);
    20.  
    21.     @Override
    22.     public void execute() {
    23.         Environment.getBot().getLogger().info("Starting craftRune.java");
    24.         GameObject altar = GameObjects.getLoaded("Altar").nearest();
    25.         if (altar.isVisible()) {
    26.             Magic.Lunar.MAGIC_IMBUE.activate();
    27.         }
    28.         SpriteItem items = Inventory.getItems("Earth rune").first();
    29.         if (items != null && altar != null) {
    30.             Environment.getBot().getLogger().info("Found earth RUNE and ALTAR!!!!!!");
    31.             items.interact("Use", Inventory.getSelectedItem() + "->" + altar);
    32.         }
    33.     }
    34. }
     
  2. auxi

    Joined:
    May 24, 2016
    Messages:
    1,113
    Likes Received:
    990
    I think all you missed are two spaces:

    Code (Text):
    1. items.interact("Use", Inventory.getSelectedItem() + " -> " + altar);
    Also you need to interact with the talisman first before executing that code.

    I would join Slack if I were you, easier to help in there.
     
  3. CuppaJava

    CuppaJava cuppa.drink(java);

    Joined:
    Mar 13, 2018
    Messages:
    6,173
    Likes Received:
    1,387
    In addition to what Auxi said, also make sure you're only executing one action per iteration of the loop. Currently your bot will attempt to both activate magic imbue and use an earth rune in the same loop/tick essentially.
     
  4. AMD

    AMD

    Joined:
    May 5, 2018
    Messages:
    11
    Likes Received:
    3
    what would the ideal solution look like? would he need a sleep after activating "Magic.Lunar.MAGIC_IMBUE.activate();"?
     
  5. proxi

    proxi s̶c̶r̶i̶p̶t̶ bot*

    Joined:
    Aug 23, 2015
    Messages:
    2,223
    Likes Received:
    501
    Definitely not.

    The simplest solution would be:
    Code (Text):
    1.     @Override
    2.     public void execute() {
    3.         Environment.getBot().getLogger().info("Starting craftRune.java");
    4.         GameObject altar = GameObjects.getLoaded("Altar").nearest();
    5.         if (altar.isVisible() && !Magic.Lunar.MAGIC_IMBUE.isActivated()) {
    6.             Magic.Lunar.MAGIC_IMBUE.activate();
    7.         } else {
    8.             SpriteItem items = Inventory.getItems("Earth rune").first();
    9.             if (items != null && altar != null) {
    10.                 Environment.getBot().getLogger().info("Found earth RUNE and ALTAR!!!!!!");
    11.                 items.interact("Use", Inventory.getSelectedItem() + "->" + altar);
    12.             }
    13.         }
    14.     }
    However, to stay true to the TreeBot philosophy, you should make a IsMagicImbueActive branch before you ever call this CraftRune leaf.
     
    AMD likes this.
  6. AMD

    AMD

    Joined:
    May 5, 2018
    Messages:
    11
    Likes Received:
    3
    all you did was else
     
  7. CuppaJava

    CuppaJava cuppa.drink(java);

    Joined:
    Mar 13, 2018
    Messages:
    6,173
    Likes Received:
    1,387
    Yeah, that's how it works. Basically what's happening here is like: we want to do action 1 followed by action 2.

    if(action1.hasBeenCompleted){
    action2.do();
    }else{
    action1.do();
    }

    You should probably start with extremely modular TreeBots until you fully understand this. There's a good video on YouTube about an hour long to walk you through a mining treebot structure.
     
    AMD and proxi like this.
  8. AMD

    AMD

    Joined:
    May 5, 2018
    Messages:
    11
    Likes Received:
    3
    I fully understand now. cheers
     
    CuppaJava likes this.
  9. Derk

    Derk 12 year old normie

    Joined:
    Jan 8, 2015
    Messages:
    2,766
    Likes Received:
    1,339
    Wouldn't calling altar.isVisible() in your first if statement cause potential null pointers?
     

Share This Page

Loading...