Resource Trade API

Discussion in 'Tutorials & Resources' started by countvidal, Jan 22, 2015.

  1. I made a simple trade API for who ever wants to use it. Legacy on RS3 only

    Code (Java):
    1.  
    2. import com.runemate.game.api.hybrid.input.Keyboard;
    3. import com.runemate.game.api.hybrid.local.hud.interfaces.InterfaceComponent;
    4. import com.runemate.game.api.hybrid.local.hud.interfaces.Interfaces;
    5. import com.runemate.game.api.hybrid.util.Filter;
    6. import com.runemate.game.api.script.Execution;
    7.  
    8. import java.util.concurrent.Callable;
    9.  
    10.  
    11. public class Trade {
    12.     final static public int INTERFACE_FIRST_TRADE = 335;
    13.     final static public int INTERFACE_FIRST_TRADE_GET_TRADING_WITH = 23; // text = name
    14.     final static public int INTERFACE_FIRST_TRADE_EXIT = 11;
    15.     final static public int INTERFACE_ADD_FROM_POUCH = 38;
    16.     final static public int INTERFACE_FIRST_TRADE_ACCEPT = 60;
    17.     final static public int INTERFACE_FIRST_TRADE_DECLINE = 66;
    18.     final static public int INTERFACE_FIRST_TRADE_THEIR_OFFER_CONTAINER = 27; // Child 0 first item. Name on menu not on text
    19.     final static public int INTERFACE_FIRST_TRADE_OUR_OFFER_CONTAINER = 24;
    20.     final static public int INTERFACE_FIRST_TRADE_WEALTH_TRANSFER_VALUE = 47; // text = 1,500 coins
    21.     final static public int INTERFACE_FIRST_TRADE_OTHER_PLAYER_ACCEPTED = 31; // text = Other player has accepted.
    22.     final static public int INTERFACE_SECOND_TRADE = 334;
    23.     final static public int INTERFACE_SECOND_TRADE_OTHER_PLAYER_ACCEPTED = 14; // text = Other player has accepted.
    24.     final static public int INTERFACE_SECOND_TRADE_GET_TRADING_WITH = 21; // text = name
    25.     final static public int INTERFACE_SECOND_TRADE_ACCEPT = 47; // action = Accept
    26.     final static public int INTERFACE_SECOND_TRADE_DECLINE = 52; // action = Decline
    27.  
    28.     final static public int INTERFACE_MONEY_POUCH_CHAT_BOX = 1469;
    29.     final static public int INTERFACE_MONEY_POUCH_CHAT_BOX_ADD_HOW_MANY_COINS = 2; // text = Add how many coins to your offer?
    30.     final static public int INTERFACE_MONEY_POUCH_CHAT_QUERY_ENTRY = 3;
    31.  
    32.     public static boolean isTrading() {
    33.         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())) {
    34.             return true;
    35.         } else {
    36.             return false;
    37.         }
    38.     }
    39.  
    40.     public static boolean isInFirstTradeWindow() {
    41.         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())) {
    42.             return true;
    43.         } else {
    44.             return false;
    45.         }
    46.  
    47.     }
    48.  
    49.     public static boolean isInSecondTradeWindow() {
    50.         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())) {
    51.             return true;
    52.         } else {
    53.             return false;
    54.         }
    55.     }
    56.  
    57.     public static String getTradingWith() {
    58.         if (isTrading()) {
    59.             if (isInFirstTradeWindow()) {
    60.                 return Interfaces.getAt(INTERFACE_FIRST_TRADE, INTERFACE_FIRST_TRADE_GET_TRADING_WITH).getText();
    61.             } else if (isInSecondTradeWindow()) {
    62.                 return Interfaces.getAt(INTERFACE_SECOND_TRADE, INTERFACE_SECOND_TRADE_GET_TRADING_WITH).getText();
    63.             }
    64.         } else {
    65.             return "";
    66.         }
    67.         return "";
    68.     }
    69.  
    70.     public static boolean hasOtherPlayerAccepted() {
    71.         if (isTrading()) {
    72.             if (isInFirstTradeWindow()) {
    73.                 return Interfaces.getAt(INTERFACE_FIRST_TRADE, INTERFACE_FIRST_TRADE_OTHER_PLAYER_ACCEPTED).getText().equals("Other player has accepted.");
    74.             } else if (isInSecondTradeWindow()) {
    75.                 return Interfaces.getAt(INTERFACE_SECOND_TRADE, INTERFACE_SECOND_TRADE_OTHER_PLAYER_ACCEPTED).getText().equals("Other player has accepted.");
    76.             }
    77.         } else {
    78.             return false;
    79.         }
    80.         return false;
    81.     }
    82.  
    83.     public static boolean haveYouAccepted() {
    84.         if (isTrading()) {
    85.             if (isInFirstTradeWindow()) {
    86.                 return Interfaces.getAt(INTERFACE_FIRST_TRADE, INTERFACE_FIRST_TRADE_OTHER_PLAYER_ACCEPTED).getText().contains("Waiting");
    87.             } else if (isInSecondTradeWindow()) {
    88.                 return Interfaces.getAt(INTERFACE_SECOND_TRADE, INTERFACE_SECOND_TRADE_OTHER_PLAYER_ACCEPTED).getText().equals("Waiting");
    89.             }
    90.         } else {
    91.             return false;
    92.         }
    93.         return false;
    94.     }
    95.  
    96.     public static void sendMoneyPouchMoney(int amount) {
    97.         if (isInFirstTradeWindow()) {
    98.             if (Interfaces.getAt(INTERFACE_MONEY_POUCH_CHAT_BOX, INTERFACE_MONEY_POUCH_CHAT_BOX_ADD_HOW_MANY_COINS) == null) {
    99.                 Interfaces.getAt(INTERFACE_FIRST_TRADE, INTERFACE_ADD_FROM_POUCH).click();
    100.                 Execution.delayUntil(new Callable<Boolean>() {
    101.                     @Override
    102.                     public Boolean call() throws Exception {
    103.                         if(Interfaces.getAt(INTERFACE_MONEY_POUCH_CHAT_BOX, INTERFACE_MONEY_POUCH_CHAT_BOX_ADD_HOW_MANY_COINS) == null){
    104.                             return false;
    105.                         }
    106.                         return Interfaces.getAt(INTERFACE_MONEY_POUCH_CHAT_BOX, INTERFACE_MONEY_POUCH_CHAT_BOX_ADD_HOW_MANY_COINS).isVisible();
    107.                     }
    108.                 }, 3000, 10000);
    109.             }
    110.             if (Interfaces.getAt(INTERFACE_MONEY_POUCH_CHAT_BOX, INTERFACE_MONEY_POUCH_CHAT_BOX_ADD_HOW_MANY_COINS) != null) {
    111.                 Keyboard.type(Integer.toString(amount), true);
    112.                 Execution.delayUntil(new Callable<Boolean>() {
    113.                     @Override
    114.                     public Boolean call() throws Exception {
    115.                         if(Interfaces.getAt(INTERFACE_MONEY_POUCH_CHAT_BOX, INTERFACE_MONEY_POUCH_CHAT_BOX_ADD_HOW_MANY_COINS) == null){
    116.                             return true;
    117.                         }
    118.                         return !Interfaces.getAt(INTERFACE_MONEY_POUCH_CHAT_BOX, INTERFACE_MONEY_POUCH_CHAT_BOX_ADD_HOW_MANY_COINS).isVisible();
    119.                     }
    120.                 }, 3000, 10000);
    121.             }
    122.         }
    123.     }
    124.  
    125.     public static boolean Accept() {
    126.         if (isInFirstTradeWindow()) {
    127.             if (Interfaces.getAt(INTERFACE_FIRST_TRADE, INTERFACE_FIRST_TRADE_ACCEPT).interact("Accept")) {
    128.                 return true;
    129.             } else {
    130.                 return false;
    131.             }
    132.         } else if (isInSecondTradeWindow()) {
    133.             if (Interfaces.getAt(INTERFACE_SECOND_TRADE, INTERFACE_SECOND_TRADE_ACCEPT).interact("Accept")) {
    134.                 return true;
    135.             } else {
    136.                 return false;
    137.             }
    138.         }
    139.         return false;
    140.     }
    141.  
    142.     public static boolean Decline() {
    143.         if (isInFirstTradeWindow()) {
    144.             if (Interfaces.getAt(INTERFACE_FIRST_TRADE, INTERFACE_FIRST_TRADE_DECLINE).interact("Decline")) {
    145.                 return true;
    146.             } else {
    147.                 return false;
    148.             }
    149.         } else if (isInSecondTradeWindow()) {
    150.             if (Interfaces.getAt(INTERFACE_SECOND_TRADE, INTERFACE_SECOND_TRADE_DECLINE).interact("Decline")) {
    151.                 return true;
    152.             } else {
    153.                 return false;
    154.             }
    155.         }
    156.         return false;
    157.     }
    158.  
    159.     public static int getWealthTransferValue() {
    160.         if (isInFirstTradeWindow()) {
    161.             String wealth = Interfaces.getAt(INTERFACE_FIRST_TRADE, INTERFACE_FIRST_TRADE_WEALTH_TRANSFER_VALUE).getText();
    162.             wealth = wealth.replace(" coins", "").replace(",", "");
    163.             System.out.println(wealth);
    164.             if(wealth.contains(">")){
    165.             wealth = wealth.substring(wealth.indexOf(">")+1,wealth.lastIndexOf("<"));
    166.             }
    167.             return Integer.parseInt(wealth);
    168.         } else {
    169.             return -1;
    170.         }
    171.     }
    172.  
    173.  
    174.     public static boolean isTheirItemOffered(final String Itemname) {
    175.  
    176.         InterfaceComponent tmp = Interfaces.getFirstAt(INTERFACE_FIRST_TRADE, INTERFACE_FIRST_TRADE_THEIR_OFFER_CONTAINER, new Filter<InterfaceComponent>() {
    177.             @Override
    178.             public boolean accepts(InterfaceComponent ic) {
    179.                 if(ic.getName() == null ){
    180.                     return false;
    181.                 }
    182.                 return ic.getName().equals(Itemname);
    183.             }
    184.         });
    185.         return tmp == null ? false : true;
    186.     }
    187.  
    188.  
    189.  
    190.     public static boolean isOurItemOffered(final String Itemname) {
    191.  
    192.        InterfaceComponent tmp = Interfaces.getFirstAt(INTERFACE_FIRST_TRADE, INTERFACE_FIRST_TRADE_OUR_OFFER_CONTAINER, new Filter<InterfaceComponent>() {
    193.             @Override
    194.             public boolean accepts(InterfaceComponent ic) {
    195.                 if(ic.getName() == null){
    196.                     return false;
    197.                 }
    198.                 return ic.getName().equals(Itemname);
    199.             }
    200.         });
    201.         return tmp == null ? false : true;
    202.     }
    203.  
    204. }
    205.  
    206.  
    207.  
     
    #1 countvidal, Jan 22, 2015
    Last edited by a moderator: Jan 22, 2015
  2. Your not suppose to use ids. Bad boy.
     
  3. Hey bro long time since I saw you, last time was on Hexbot I guess? XD
     
  4. What do you recommend, querying for each one?
     
  5. Yeah, haha. Got drawn to rs again to work on some rs gambling website.
     
  6. I believe something that is on the first screen that you can identify by;

    [​IMG]
     
  7. i was on god on hexbot if you remember me i had the most feedback
     

Share This Page

Loading...