Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Question Using an item on an object?

Joined
Sep 25, 2017
Messages
5
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:
package com.rootbots.runecrafting.LavaRunes.leafs;

import com.runemate.game.api.hybrid.Environment;
import com.runemate.game.api.hybrid.entities.GameObject;
import com.runemate.game.api.hybrid.local.hud.interfaces.Inventory;
import com.runemate.game.api.hybrid.local.hud.interfaces.SpriteItem;
import com.runemate.game.api.hybrid.location.Coordinate;
import com.runemate.game.api.hybrid.region.GameObjects;
import com.runemate.game.api.osrs.local.hud.interfaces.Magic;
import com.runemate.game.api.script.framework.tree.LeafTask;

/**
* NOTES:
* if we arent at castle wars, and we have 26 essence, we are and the altar is visible
Use Magic Imbue and use Earth Rune on Altar
*/
public class CraftRune extends LeafTask {

    Coordinate altarRegion = new Coordinate(2583, 4840, 0);

    @Override
    public void execute() {
        Environment.getBot().getLogger().info("Starting craftRune.java");
        GameObject altar = GameObjects.getLoaded("Altar").nearest();
        if (altar.isVisible()) {
            Magic.Lunar.MAGIC_IMBUE.activate();
        }
        SpriteItem items = Inventory.getItems("Earth rune").first();
        if (items != null && altar != null) {
            Environment.getBot().getLogger().info("Found earth RUNE and ALTAR!!!!!!");
            items.interact("Use", Inventory.getSelectedItem() + "->" + altar);
        }
    }
}
 
Joined
May 24, 2016
Messages
1,113
I think all you missed are two spaces:

Code:
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.
 
cuppa.drink(java);
Joined
Mar 13, 2018
Messages
7,745
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.
 

amd

Joined
May 5, 2018
Messages
11
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.

what would the ideal solution look like? would he need a sleep after activating "Magic.Lunar.MAGIC_IMBUE.activate();"?
 
s̶c̶r̶i̶p̶t̶ bot*
Joined
Aug 23, 2015
Messages
2,232
what would the ideal solution look like? would he need a sleep after activating "Magic.Lunar.MAGIC_IMBUE.activate();"?
Definitely not.

The simplest solution would be:
Code:
    @Override
    public void execute() {
        Environment.getBot().getLogger().info("Starting craftRune.java");
        GameObject altar = GameObjects.getLoaded("Altar").nearest();
        if (altar.isVisible() && !Magic.Lunar.MAGIC_IMBUE.isActivated()) {
            Magic.Lunar.MAGIC_IMBUE.activate();
        } else {
            SpriteItem items = Inventory.getItems("Earth rune").first();
            if (items != null && altar != null) {
                Environment.getBot().getLogger().info("Found earth RUNE and ALTAR!!!!!!");
                items.interact("Use", Inventory.getSelectedItem() + "->" + altar);
            }
        }
    }

However, to stay true to the TreeBot philosophy, you should make a IsMagicImbueActive branch before you ever call this CraftRune leaf.
 

amd

Joined
May 5, 2018
Messages
11
Definitely not.

The simplest solution would be:
Code:
    @Override
    public void execute() {
        Environment.getBot().getLogger().info("Starting craftRune.java");
        GameObject altar = GameObjects.getLoaded("Altar").nearest();
        if (altar.isVisible() && !Magic.Lunar.MAGIC_IMBUE.isActivated()) {
            Magic.Lunar.MAGIC_IMBUE.activate();
        } else {
            SpriteItem items = Inventory.getItems("Earth rune").first();
            if (items != null && altar != null) {
                Environment.getBot().getLogger().info("Found earth RUNE and ALTAR!!!!!!");
                items.interact("Use", Inventory.getSelectedItem() + "->" + altar);
            }
        }
    }

However, to stay true to the TreeBot philosophy, you should make a IsMagicImbueActive branch before you ever call this CraftRune leaf.

all you did was else
 
cuppa.drink(java);
Joined
Mar 13, 2018
Messages
7,745
all you did was else
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

Joined
May 5, 2018
Messages
11
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.

I fully understand now. cheers
 
12 year old normie
Joined
Jan 8, 2015
Messages
2,768
Definitely not.

The simplest solution would be:
Code:
    @Override
    public void execute() {
        Environment.getBot().getLogger().info("Starting craftRune.java");
        GameObject altar = GameObjects.getLoaded("Altar").nearest();
        if (altar.isVisible() && !Magic.Lunar.MAGIC_IMBUE.isActivated()) {
            Magic.Lunar.MAGIC_IMBUE.activate();
        } else {
            SpriteItem items = Inventory.getItems("Earth rune").first();
            if (items != null && altar != null) {
                Environment.getBot().getLogger().info("Found earth RUNE and ALTAR!!!!!!");
                items.interact("Use", Inventory.getSelectedItem() + "->" + altar);
            }
        }
    }

However, to stay true to the TreeBot philosophy, you should make a IsMagicImbueActive branch before you ever call this CraftRune leaf.
Wouldn't calling altar.isVisible() in your first if statement cause potential null pointers?
 
Top