Welcome!

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

Sign up now!

First script attempt [MakeLeather]

Status
Not open for further replies.
Joined
Jan 8, 2015
Messages
1,427
Started with setting up IntelliJ by following the simple Setting up IntelliJ for RuneMate guide made by @Viewer.

f998dc51cc.gif


Source code so far: https://bitbucket.org/Erikdekamps/geashawscripts/

Code:
package com.runemate.geashawscripts.makeleather;

//Imports are all the classes that we are going to use methods from

import com.runemate.game.api.client.paint.PaintListener;
import com.runemate.game.api.hybrid.RuneScape;
import com.runemate.game.api.hybrid.input.Keyboard;
import com.runemate.game.api.hybrid.local.hud.interfaces.*;
import com.runemate.game.api.rs3.local.hud.interfaces.eoc.ActionBar;
import com.runemate.game.api.rs3.local.hud.interfaces.eoc.SlotAction;
import com.runemate.game.api.script.Execution;
import com.runemate.game.api.script.framework.LoopingScript;

import java.awt.*;

public class autotanner extends LoopingScript implements PaintListener {

    private final int MAKE_LEATHER_ID = 2150, FIRE_STAFF = 1387;
    final String HIDE = "Cowhide", TANNED_HIDE = "Leather";

    @Override
    public void onStart(String... args) {
        setLoopDelay(100, 200);
    }

    @Override
    public void onLoop() {
        // Check if the user is logged in.
        if (RuneScape.isLoggedIn()) {
            if (runesInInventory() && staffEquiped()) {

                // Checking which state of the script we're in.
                if (gotHides() && !gotLeather()) {
                    if (Bank.isOpen()) {
                        Bank.close();
                    } else {
                        if (interfaceIsVisible()) {
                            pressSpacebar();
                        } else {
                            if (spellSelected()) {
                                clickHide();
                            } else {
                                selectSpell();
                            }
                        }
                    }
                } else if (gotLeather() && !gotHides()) {
                    if (Bank.isOpen()) {
                        depositLeather();
                    } else {
                        if (Bank.open()) {
                            Execution.delayUntil(() -> Bank.isOpen(), 500);
                        }
                    }
                } else {
                    if (Bank.isOpen()) {
                        withdrawHides();
                    }
                }
            }
        }
    }

    /**
     * @return Whether or not you have a staff of fire equiped.
     */
    private boolean staffEquiped() {
        return Equipment.getItemIn(Equipment.Slot.WEAPON).getId() == FIRE_STAFF ? true : false;
    }

    /**
     * @return Whether or not you have the body & astral runes in your inventory.
     */
    private boolean runesInInventory() {
        return Inventory.containsAllOf("Body rune") && Inventory.containsAllOf("Astral rune") ? true : false;
    }

    /**
     * @return Whether or not the spell is selected.
     */
    public boolean spellSelected() {
        SlotAction action = ActionBar.getFirstAction(MAKE_LEATHER_ID);

        if (action != null) {
            if (action.isSelected()) {

                return true;
            } else {
                Execution.delayUntil(() -> action.isSelected(), 500);
            }
        }

        return false;
    }

    /**
     * @return Whether or not the interface with the "Tan" button is not null and visible.
     */
    public boolean interfaceIsVisible() {
        InterfaceComponent tanButton = Interfaces.getAt(1370, 38);

        if (tanButton != null) {
            if (tanButton.isVisible()) {

                return true;
            }
        }

        return false;
    }

    /**
     * @return Whether or not the inventory contains green dragon hides.
     */
    private boolean gotHides() {
        return (Inventory.contains(HIDE) && Inventory.getQuantity(HIDE) == 25);
    }

    /**
     * @return Whether or not the inventory contains green dragon leather.
     */
    private boolean gotLeather() {
        return (Inventory.contains(TANNED_HIDE) && Inventory.getQuantity(TANNED_HIDE) == 25);
    }

    /**
     * Used to select the Make Leather spell from the ability bar.
     */
    private boolean selectSpell() {
        SlotAction action = ActionBar.getFirstAction(MAKE_LEATHER_ID);

        if (action != null) {
            if (Keyboard.typeKey(action.getSlot().getKeyBind())) {
                if (!action.isSelected()) {
                    Execution.delayUntil(() -> action.isSelected(), 500);
                }
                debug("Selecting spell from ability bar.");
                return true;
            }
        }
        return false;
    }

    /**
     * Presses space bar.
     */
    private boolean pressSpacebar() {
        if (Keyboard.typeKey(" ")) {
            debug("Pressing spacebar to tan hides.");
            if (interfaceIsVisible()) {
                Execution.delayUntil(() -> !interfaceIsVisible(), 1000);
            }
            return true;
        }

        return false;
    }

    /**
     * Used to click the dragon hide in inventory
     * when the Make Leather spell is activated.
     */
    private boolean clickHide() {
        final SpriteItem hide = Inventory.getItems(HIDE).first();
        if (hide != null) {
            if (hide.interact("Cast")) {
                debug("Clicking Make Leather on the hide.");
                Execution.delayUntil(() -> interfaceIsVisible(), 1000, 2000);
            }
            return true;
        }
        return false;
    }

    /**
     * Used to deposit leather into bank.
     */
    private boolean depositLeather() {
        if (Bank.deposit(TANNED_HIDE, 0)) {
            debug("Depositing the tanned hides.");
            Execution.delayUntil(() -> !gotLeather(), 1000);
            return true;
        }

        return false;
    }

    /**
     * Used to withdraw hides from bank.
     */
    private boolean withdrawHides() {

        if (Bank.withdraw(HIDE, 25)) {
            debug("Withdrawing hides.");
            if (!gotHides()) {
                Execution.delayUntil(() -> gotHides(), 1000);
            }
            return true;
        }
        return false;
    }

    /**
     * Used to replace System.out.println(text);
     *
     * @param text The text to send to the console.
     */
    private void debug(String text) {
        System.out.println(text);
    }

    @Override
    public void onPaint(final Graphics2D g) {

    }
}
 
Last edited:
Joined
Nov 26, 2014
Messages
616
Its a decent start, but you should get items by name instead if id. I only had a quick look, but I'll look again when I get home.
 
The Pip Collector
Joined
Sep 14, 2014
Messages
445
Few suggestions:
- As our Supreme Leader suggested, use names instead of ID's :)
- Use TaskScript instead of a looping script since its easier to debug errors when things are done in tasks
Overall a good start :)
 
Joined
Jan 8, 2015
Messages
1,427
Yeah you should get everything by name; objects, npcs, interfaces, etc because everything is hard cached.

That's a great tip :)

Few suggestions:
- As our Supreme Leader suggested, use names instead of ID's :)
- Use TaskScript instead of a looping script since its easier to debug errors when things are done in tasks
Overall a good start :)

I was actually just setting up the main.java, will move to tasks this evening when I get home! Merci
 
Joined
Jan 8, 2015
Messages
1,427
Updated the script, since it's open source I'll just edit the OP.
 
Engineer
Joined
Jul 28, 2013
Messages
2,776
1. Don't check for the fire staff via id.
2. Don't find interfaces via absolute indices.
3. Some of your boolean functions can be shrunk.
4. You don't actually check whether or not your delayUntil accomplished what you had planned.
 
Joined
Jan 8, 2015
Messages
1,427
1. Don't check for the fire staff via id.

So then how would I get the string for example "Staff of fire"?

2. Don't find interfaces via absolute indices.

If not absolute, what will I filter on?

Some of your boolean functions can be shrunk.

Thanks, will do!

You don't actually check whether or not your delayUntil accomplished what you had planned.

So that means it should be;
Code:
if (Keyboard.typeKey(action.getSlot().getKeyBind())) {
    if (!action.isSelected()) {
        Execution.delayUntil(() -> action.isSelected(), 500);
    }
    return true;
}

return false;

Thanks for your feedback!
 
Discretion is advised
Joined
Jan 2, 2014
Messages
306
So then how would I get the string for example "Staff of fire"?

Code:
public SpriteItem getStaffOfFire() {
return Inventory.newQuery().filter(new Filter<SpriteItem>() {
@Overridepublic boolean accepts(SpriteItem spriteItem) {
final ItemDefinition itemDefinition = spriteItem.getDefinition(); if (itemDefinition != null) {
final String name = itemDefinition.getName().toLowerCase(); return name.contains("staff") && (name.contains("fire") || name.contains("lava"));}
return false;}
}).results().first();}

This code will return any staff that can be used to replace fire runes in your inventory, to check for a string that is not the specific name of the item, you can always cache the ItemDefinition and nullcheck it then getting the name from it, but if you want a specific item you can use its exact name like:

Code:
public SpriteItem getStaffOfFire() {
return Inventory.newQuery().names("Staff of Fire").results().first();
}
 
Engineer
Joined
Jul 28, 2013
Messages
2,776
So then how would I get the string for example "Staff of fire"?



If not absolute, what will I filter on?



Thanks, will do!



So that means it should be;
Code:
if (Keyboard.typeKey(action.getSlot().getKeyBind())) {
    if (!action.isSelected()) {
        Execution.delayUntil(() -> action.isSelected(), 500);
    }
    return true;
}

return false;

Thanks for your feedback!
From the items definition. An alternative way would be to do something like Equipment.newQuery().names(name).results()
You can filter based on text, names, colors, etc.
by that I mean you should return based on whether or not it successfully delayed until that condition was true without hitting the timeout. Try return Execution.delayUntil(()->action.isSelected(),500)
 
Joined
Dec 18, 2014
Messages
398
If not absolute, what will I filter on?
textureID, text/name, text color values, etc. Some interfaces have no text/name and a textureID of -1, but usually you can find other interfaces with the same parent that have a unique textureID/name/text/etc. and accomplish the same thing.
 
Status
Not open for further replies.
Top