Welcome!

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

Sign up now!

Resource Trade API

Joined
Nov 17, 2013
Messages
63
I made a simple trade API for who ever wants to use it. Legacy on RS3 only

Java:
import com.runemate.game.api.hybrid.input.Keyboard;
import com.runemate.game.api.hybrid.local.hud.interfaces.InterfaceComponent;
import com.runemate.game.api.hybrid.local.hud.interfaces.Interfaces;
import com.runemate.game.api.hybrid.util.Filter;
import com.runemate.game.api.script.Execution;

import java.util.concurrent.Callable;


public class Trade {
    final static public int INTERFACE_FIRST_TRADE = 335;
    final static public int INTERFACE_FIRST_TRADE_GET_TRADING_WITH = 23; // text = name
    final static public int INTERFACE_FIRST_TRADE_EXIT = 11;
    final static public int INTERFACE_ADD_FROM_POUCH = 38;
    final static public int INTERFACE_FIRST_TRADE_ACCEPT = 60;
    final static public int INTERFACE_FIRST_TRADE_DECLINE = 66;
    final static public int INTERFACE_FIRST_TRADE_THEIR_OFFER_CONTAINER = 27; // Child 0 first item. Name on menu not on text
    final static public int INTERFACE_FIRST_TRADE_OUR_OFFER_CONTAINER = 24;
    final static public int INTERFACE_FIRST_TRADE_WEALTH_TRANSFER_VALUE = 47; // text = 1,500 coins
    final static public int INTERFACE_FIRST_TRADE_OTHER_PLAYER_ACCEPTED = 31; // text = Other player has accepted.
    final static public int INTERFACE_SECOND_TRADE = 334;
    final static public int INTERFACE_SECOND_TRADE_OTHER_PLAYER_ACCEPTED = 14; // text = Other player has accepted.
    final static public int INTERFACE_SECOND_TRADE_GET_TRADING_WITH = 21; // text = name
    final static public int INTERFACE_SECOND_TRADE_ACCEPT = 47; // action = Accept
    final static public int INTERFACE_SECOND_TRADE_DECLINE = 52; // action = Decline

    final static public int INTERFACE_MONEY_POUCH_CHAT_BOX = 1469;
    final static public int INTERFACE_MONEY_POUCH_CHAT_BOX_ADD_HOW_MANY_COINS = 2; // text = Add how many coins to your offer?
    final static public int INTERFACE_MONEY_POUCH_CHAT_QUERY_ENTRY = 3;

    public static boolean isTrading() {
        if ((Interfaces.getAt(INTERFACE_FIRST_TRADE, 0) != null && Interfaces.getAt(INTERFACE_FIRST_TRADE, 0).isVisible()) || (Interfaces.getAt(INTERFACE_SECOND_TRADE, 0) != null && Interfaces.getAt(INTERFACE_SECOND_TRADE, 0).isVisible())) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean isInFirstTradeWindow() {
        if ((Interfaces.getAt(INTERFACE_FIRST_TRADE, 0) != null && Interfaces.getAt(INTERFACE_FIRST_TRADE, 0).isVisible()) && (Interfaces.getAt(INTERFACE_SECOND_TRADE, 0) == null || !Interfaces.getAt(INTERFACE_SECOND_TRADE, 0).isVisible())) {
            return true;
        } else {
            return false;
        }

    }

    public static boolean isInSecondTradeWindow() {
        if ((Interfaces.getAt(INTERFACE_FIRST_TRADE, 0) == null || !Interfaces.getAt(INTERFACE_FIRST_TRADE, 0).isVisible()) && (Interfaces.getAt(INTERFACE_SECOND_TRADE, 0) != null && Interfaces.getAt(INTERFACE_SECOND_TRADE, 0).isVisible())) {
            return true;
        } else {
            return false;
        }
    }

    public static String getTradingWith() {
        if (isTrading()) {
            if (isInFirstTradeWindow()) {
                return Interfaces.getAt(INTERFACE_FIRST_TRADE, INTERFACE_FIRST_TRADE_GET_TRADING_WITH).getText();
            } else if (isInSecondTradeWindow()) {
                return Interfaces.getAt(INTERFACE_SECOND_TRADE, INTERFACE_SECOND_TRADE_GET_TRADING_WITH).getText();
            }
        } else {
            return "";
        }
        return "";
    }

    public static boolean hasOtherPlayerAccepted() {
        if (isTrading()) {
            if (isInFirstTradeWindow()) {
                return Interfaces.getAt(INTERFACE_FIRST_TRADE, INTERFACE_FIRST_TRADE_OTHER_PLAYER_ACCEPTED).getText().equals("Other player has accepted.");
            } else if (isInSecondTradeWindow()) {
                return Interfaces.getAt(INTERFACE_SECOND_TRADE, INTERFACE_SECOND_TRADE_OTHER_PLAYER_ACCEPTED).getText().equals("Other player has accepted.");
            }
        } else {
            return false;
        }
        return false;
    }

    public static boolean haveYouAccepted() {
        if (isTrading()) {
            if (isInFirstTradeWindow()) {
                return Interfaces.getAt(INTERFACE_FIRST_TRADE, INTERFACE_FIRST_TRADE_OTHER_PLAYER_ACCEPTED).getText().contains("Waiting");
            } else if (isInSecondTradeWindow()) {
                return Interfaces.getAt(INTERFACE_SECOND_TRADE, INTERFACE_SECOND_TRADE_OTHER_PLAYER_ACCEPTED).getText().equals("Waiting");
            }
        } else {
            return false;
        }
        return false;
    }

    public static void sendMoneyPouchMoney(int amount) {
        if (isInFirstTradeWindow()) {
            if (Interfaces.getAt(INTERFACE_MONEY_POUCH_CHAT_BOX, INTERFACE_MONEY_POUCH_CHAT_BOX_ADD_HOW_MANY_COINS) == null) {
                Interfaces.getAt(INTERFACE_FIRST_TRADE, INTERFACE_ADD_FROM_POUCH).click();
                Execution.delayUntil(new Callable<Boolean>() {
                    @Override
                    public Boolean call() throws Exception {
                        if(Interfaces.getAt(INTERFACE_MONEY_POUCH_CHAT_BOX, INTERFACE_MONEY_POUCH_CHAT_BOX_ADD_HOW_MANY_COINS) == null){
                            return false;
                        }
                        return Interfaces.getAt(INTERFACE_MONEY_POUCH_CHAT_BOX, INTERFACE_MONEY_POUCH_CHAT_BOX_ADD_HOW_MANY_COINS).isVisible();
                    }
                }, 3000, 10000);
            }
            if (Interfaces.getAt(INTERFACE_MONEY_POUCH_CHAT_BOX, INTERFACE_MONEY_POUCH_CHAT_BOX_ADD_HOW_MANY_COINS) != null) {
                Keyboard.type(Integer.toString(amount), true);
                Execution.delayUntil(new Callable<Boolean>() {
                    @Override
                    public Boolean call() throws Exception {
                        if(Interfaces.getAt(INTERFACE_MONEY_POUCH_CHAT_BOX, INTERFACE_MONEY_POUCH_CHAT_BOX_ADD_HOW_MANY_COINS) == null){
                            return true;
                        }
                        return !Interfaces.getAt(INTERFACE_MONEY_POUCH_CHAT_BOX, INTERFACE_MONEY_POUCH_CHAT_BOX_ADD_HOW_MANY_COINS).isVisible();
                    }
                }, 3000, 10000);
            }
        }
    }

    public static boolean Accept() {
        if (isInFirstTradeWindow()) {
            if (Interfaces.getAt(INTERFACE_FIRST_TRADE, INTERFACE_FIRST_TRADE_ACCEPT).interact("Accept")) {
                return true;
            } else {
                return false;
            }
        } else if (isInSecondTradeWindow()) {
            if (Interfaces.getAt(INTERFACE_SECOND_TRADE, INTERFACE_SECOND_TRADE_ACCEPT).interact("Accept")) {
                return true;
            } else {
                return false;
            }
        }
        return false;
    }

    public static boolean Decline() {
        if (isInFirstTradeWindow()) {
            if (Interfaces.getAt(INTERFACE_FIRST_TRADE, INTERFACE_FIRST_TRADE_DECLINE).interact("Decline")) {
                return true;
            } else {
                return false;
            }
        } else if (isInSecondTradeWindow()) {
            if (Interfaces.getAt(INTERFACE_SECOND_TRADE, INTERFACE_SECOND_TRADE_DECLINE).interact("Decline")) {
                return true;
            } else {
                return false;
            }
        }
        return false;
    }

    public static int getWealthTransferValue() {
        if (isInFirstTradeWindow()) {
            String wealth = Interfaces.getAt(INTERFACE_FIRST_TRADE, INTERFACE_FIRST_TRADE_WEALTH_TRANSFER_VALUE).getText();
            wealth = wealth.replace(" coins", "").replace(",", "");
            System.out.println(wealth);
            if(wealth.contains(">")){
            wealth = wealth.substring(wealth.indexOf(">")+1,wealth.lastIndexOf("<"));
            }
            return Integer.parseInt(wealth);
        } else {
            return -1;
        }
    }


    public static boolean isTheirItemOffered(final String Itemname) {

        InterfaceComponent tmp = Interfaces.getFirstAt(INTERFACE_FIRST_TRADE, INTERFACE_FIRST_TRADE_THEIR_OFFER_CONTAINER, new Filter<InterfaceComponent>() {
            @Override
            public boolean accepts(InterfaceComponent ic) {
                if(ic.getName() == null ){
                    return false;
                }
                return ic.getName().equals(Itemname);
            }
        });
        return tmp == null ? false : true;
    }



    public static boolean isOurItemOffered(final String Itemname) {

       InterfaceComponent tmp = Interfaces.getFirstAt(INTERFACE_FIRST_TRADE, INTERFACE_FIRST_TRADE_OUR_OFFER_CONTAINER, new Filter<InterfaceComponent>() {
            @Override
            public boolean accepts(InterfaceComponent ic) {
                if(ic.getName() == null){
                    return false;
                }
                return ic.getName().equals(Itemname);
            }
        });
        return tmp == null ? false : true;
    }

}
 
Last edited by a moderator:
Discretion is advised
Joined
Jan 2, 2014
Messages
306
Hey bro long time since I saw you, last time was on Hexbot I guess? XD
 
Joined
Jan 8, 2015
Messages
1,427
What do you recommend, querying for each one?

I believe something that is on the first screen that you can identify by;

bab6616b62.png
 
Top