Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Buy OSRS Gold

Sell OSRS Gold

Recommended Posts

Description:
I thought some new scripters might find this useful. So I rewrote @TehRhio's old shop api since it's #getAll method was outdated.

Original Thread:

Snippet:

import org.tribot.api.Timing;
import org.tribot.api.types.generic.Condition;
import org.tribot.api2007.Interfaces;
import org.tribot.api2007.Inventory;
import org.tribot.api2007.types.RSInterfaceChild;
import org.tribot.api2007.types.RSInterfaceComponent;
import org.tribot.api2007.types.RSItem;
import org.tribot.api2007.types.RSItemDefinition;

import java.awt.*;
import java.util.ArrayList;
import java.util.Arrays;

public class OSShopping {

    private static final int MASTER_ID = 300;
    private static final int FRAME_CHILD_ID = 1;
    private static final int ITEMS_CHILD_ID = 2;

    public static boolean isShopOpen() {
        return Interfaces.get(MASTER_ID, ITEMS_CHILD_ID) != null;
    }

    public static String getShopName() {
        RSInterfaceChild frame = Interfaces.get(MASTER_ID, FRAME_CHILD_ID);
        if (frame != null) {
            return frame.getText();
        }
        return "";
    }

    public static boolean close() {
        RSInterfaceChild frame = Interfaces.get(MASTER_ID, FRAME_CHILD_ID);
        if (frame != null) {
            RSInterfaceComponent closeButton = frame.getChild(11);
            return closeButton != null && closeButton.click("Close") && Timing.waitCondition(new Condition() {
                @Override
                public boolean active() {
                    return !isShopOpen();
                }
            }, 2000);
        }
        return false;
    }

    public static RSItem[] getAll() {
        ArrayList<RSItem> itemList = new ArrayList<>();
        RSInterfaceChild itemsChild = Interfaces.get(MASTER_ID, ITEMS_CHILD_ID);
        if (itemsChild != null && itemsChild.getChildren() != null) {
            for (int i = 0; i < itemsChild.getChildren().length; i++) {
                RSInterfaceComponent itemComponent = itemsChild.getChild(i);
                if (itemComponent != null && !itemComponent.isHidden()) {
                    final int garbageLength = 11;
                    String name = itemComponent.getComponentName();
                    Rectangle bounds = itemComponent.getAbsoluteBounds();
                    if (name != null && name.length() >= garbageLength && bounds != null) {
                        RSItem item = new RSItem(name.substring(garbageLength).replace("</col", ""), itemComponent.getActions(), itemComponent.getIndex(), itemComponent.getComponentItem(), itemComponent.getComponentStack(), RSItem.TYPE.OTHER);
                        item.setArea(bounds);
                        itemList.add(item);
                    }
                }
            }
        }
        return itemList.toArray(new RSItem[itemList.size()]);
    }

    public static boolean contains(String... names) {
        return get(names).length > 0;
    }

    public static boolean contains(int... ids) {
        return get(ids).length > 0;
    }

    public static RSItem[] get(String... names) {
        ArrayList<RSItem> items = new ArrayList<>();
        for (RSItem i : getAll()) {
            RSItemDefinition definition = i.getDefinition();
            if(definition != null && Arrays.asList(names).contains(definition.getName())) {
                items.add(i);
            }
        }
        return items.toArray(new RSItem[items.size()]);
    }

    public static RSItem[] get(int... ids) {
        ArrayList<RSItem> items = new ArrayList<>();
        for (RSItem i : getAll()) {
            if(Arrays.asList(ids).contains(i.getID())) {
                items.add(i);
            }
        }
        return items.toArray(new RSItem[items.size()]);
    }

    public static int getCount(String... name) {
        int total = 0;
        for (RSItem item : get(name)) {
            total += item.getStack();
        }
        return total;
    }

    public static int getCount(int... id) {
        int total = 0;
        for (RSItem item : get(id)) {
            total += item.getStack();
        }
        return total;
    }

    public static boolean buy(int amount, String name) {
        RSItem[] items = get(name);
        RSItem item = items.length > 0 ? items[0] : null;
        return item != null && item.getStack() > 0 && exchangeItem(amount, "Buy", item);
    }

    public static boolean buy(int amount, int id) {
        RSItem[] items = get(id);
        RSItem item = items.length > 0 ? items[0] : null;
        return item != null && item.getStack() > 0 && exchangeItem(amount, "Buy", item);
    }

    public static boolean sell(int count, String name) {
        RSItem[] items = Inventory.find(name);
        return items.length > 0 && exchangeItem(count, "Sell", items[0]);
    }

    public static boolean sell(int count, int id) {
        RSItem[] items = Inventory.find(id);
        return items.length > 0 && exchangeItem(count, "Sell", items[0]);
    }

    private static boolean exchangeItem(int amount, String action, RSItem item) {
        if (amount >= 50 && action.equals("Sell")) {
            return item.click(action + " 50");
        } else if (amount >= 10) {
            return item.click(action + " 10");
        } else if(amount >= 5) {
            return item.click(action + " 5");
        } else {
            return item.click(action + " 1");
        }
    }
}

 

Edited by Flamo353
  • Like 5
  • Thanks 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Similar Content

    • By Sidesteppin12
      I decided to create my own banking API that mimics tribots way of implementing the API as much as possible. Basically it would only contain nothing more than just method calls. Simple and easy to use.
      This API is a reworked version that is currently in my jHerblore script. I intend to release my GE api as well once I have finished that one up too. The API requires DaxWalker & Wastedbro's Item Price API. Other than that the rest is achieveable with standard dependencies that already comes with tribot.
      All of the method names are the same as the ones from Banking & GrandExchange class in tribot, with a few exceptions, the only difference is that these methods are called with different class names such as Banker & Exchanger, so they do not collide with the Banking & GrandExchange class of tribot and cause an ambiguity problem.
       
      List of available methods:
       
      Some of the features this API offers:
      - Methods that incorporate any form of withdrawing or depositing do not need you to first check if the bank is open nor if it is loaded. It will attempt to open the bank if it is not open before returning false, and wait for bank to load if it is not loaded yet.
      - Methods that incorporate any form of buying or selling do not need you to first check if the exchange window is open. It will attempt to open the exchange window if it is not open before returning false.
      - Deselector. All methods that require the mouse to click somewhere on the screen first check if an item or spell is selected, if it is then it will deselect whatever is selected before attempting the requested action.
      - Additional failsafes, not just the deselector. Tribots banking api does not know if what you were trying to click actually was succesfully clicked. Instead it views succesfully calling the click function as a succesfull attempt. It's kind of like playing pin the nail to the donkey game. It does not know if it pinned it at the right location, but as long as it pinned it the function returns true. This is not true for all methods, some methods do actually check if the action was succesfully performed, however they do not reattempt the action if it failed. 1 call = 1 attempt. My api will reattempt any action that might fail, several times, before returning false and will also wait until inventory count is updated. For example using the tribot banking API if you were to deposit all your items and then immediately check your available inventory space before withdrawing items then it might not work as you wish because Banker.depositAll() returns before the action of depositing has finished.
      - When banking, closes GrandExchange window if it is open.
      - When buying/selling, closes the bank screen if it is open.
      - Support for withdrawing items in noted format and with or without stack exception. Stack exception is basically if you wish to draw X amount of items in your inventory but you only had Y left, then you can choose if you wish to draw these items or not. Also supports depositing of noted item ids if you happen to pass a list with of items that contains items of unnoted item ids, but the item in your inventory is a noted version of the item in your inventory. Also will not deposit equipment or items if you have none equipped or in your inventory. There is a total of 4 different depositing methods and 16 different withdrawing methods.
      - Unique dynamic sleeping method, all methods that should sleep already have sleeps implemented so you do not need to call a sleep after executing any of the methods. Involves random varying sleeps but will occasionally, every so often, in a irregular pattern, sleep a bit longer. I use this because I prefer it over General.sleep(). Feel free to replace it with whichever method you wish. Remember before running the main loop in your script to call:
      jGeneral.get().generateSeed(); This will create a random number between 0-100 that will be added to your dynamic sleeps in milliseconds. This is so no bot has the same average reaction/sleeping time.
      - When buying items on the GE, if the bot does not have any money or too little money in the inventory, it will check if you have enough of the missing amount in the bank and withdraw that amount.
      - Custom buying method that checks for an exact string match of the item you wish to buy and chooses that one from the returned items in the buy window search box. The standard GE api does not do this and will for instance click the wrong herb when it searches for "Guam leaf" in the grand exhcange, this is because more than one item contains "guam leaf" in their name. Such as Grimy guam leaf and so on.
      - Profit tracking when buying/selling items on the GE. This is optional.
       
      GET THE SOURCE HERE!
       
      UPDATES:
      - Pushed new updates that fix some of the methods that I've tested a bit for now, bit of logic and efficiency improvements. Also added 2 new depositing methods. Remember to replace the old java files with the new ones.
      - Pushed even more updates. Fixed interface problem for withdrawing noted items. My GE api is now also been released to the public. Enjoy!
    • By rsgoldbar
      RS GOLD BAR CHECK IT OUT
       
      ○ !JOIN TO OUR DISCORD! ○
      ○ !JOIN TO OUR SKYPE! ○  
      ○ ! JUST GO OUR WEBSITE ! ○  
       
       24/7 LIVE CHAT
       
       
      The rate at which we buy RuneScape gold are always changing and depends on different factors such as quantity and payment method.

      !CONNTACT WITH US TO GET BEST OFFTER!


      !!!ALWAYS ASK FOR A PM BEFORE A TRADE!!!
    • By pauliusam
      need 6.5 credits (or 7 if half is not a option)
      paying osrs gp
    • By pauliusam
      pay method - osrs gp
    • By SMT
      Hello if you are reading this I have a great opportunity open for you.
       
      -If you are picked for the job. I am currently looking
      to hire a video editor. Requirements: They must have
      adobe after fx and the ability to make a 30-second intro.
      They must also have a recent video editing program.
        And able to show previous work. There really isn't a limit
      on how much I am willing to pay. And yes I am willing to pay
      first if they have the right amount of vouchs. 
      The video will be
      sponsored on Sythe. And the creator will have the luxury of
      adding a created by to the end of the video.
       
      The deadline  Wednesday 14th of March.
      If you didn't know already Sythe is
      throwing a community event this Saint
      Patricks day and all of you are invited.
      If you have any questions about how the video should look. Or what needs to be included let me know. 370+ Vouchs are on sythe on the username: Mentarley
      Or you can click this link: https://www.sythe.org/threads/mentarleys-vouches-300-vouchs-100-000-usd-traded-500-donor-rank/
      Reply to this thread or on sythe instead of adding me on skype.
       
       
       
       
    • By Memberino
      In Stock: 0m
      Price: $1.00 / M

      Accepted payment methods:
      ETH / LTC
      Only accepting BTC, if youre willing to pay fees (Currently $15.43)

      Chatting with me:
      Just private message. Fast PM's guaranteed.
  • Our picks

    • Over the past few months, I’ve been working diligently on a new project - TRiBot X. Everything has been written from the ground up, with all of the best practices of software engineering. Every aspect of TRiBot has been re-imagined to support three main goals: flexibility, useability, and reliability.
        • Like
      • 30 replies
    • Come give us feedback on the next version of TRiBot!
        • Thanks
        • Like
      • 74 replies
    • TRiBot is looking to improve a lot of its customer relationship management, customer on boarding process, customer experience, design elements, community engagement and pretty much everything else you can imagine when it comes to marketing.

      Our goal: To ensure that the marketing done TRULY reflects the experience and does not shine an inaccurate light on what TRiBot is lacking in.

      So I ask, what do you love about TRiBot and what do you hate about TRiBot? What does O S Bot, Rune M8, PowR Bot and Dre amBot do better? (yes I purposely didn't spell it right 😂).

      Love, 

      RileyZ
        • Like
      • 23 replies
    • Over the last three weeks, I've been working on upgrading our server infrastructure. It's finally ready and is now live!

      Why?

      Increased reliability - less server errors


      Increased availability - less downtime


      Increased security - keeping us and you secure


      Increased capacity - ability to serve you better


      Increased speed - less waiting for things to load


      Faster development - server and service updates will come faster


      What are the changes?

      Move from a single AWS EC2 instance to AWS ECS (Elastic Container Service)


      Distributed computing


      Load balancing


      Git management of server files and filesystem


      Redis caching


      How?

      AWS ECS (with 10 EC2 instances)


      AWS ElastiCache (Redis)


      AWS Load Balancing


      AWS EFS (Elastic file system)


      Please bare with us as I continue to tune the server for maximum performance. Slow loading speeds may occur temporarily. I thank everyone for their patience.

      Please post on this thread if you experience any issues other than slow loading times.
        • Like
      • 51 replies
    • This release will:

      Fix prayers and world hopper API (Thanks @JoeDezzy1 and @erickho123)


      Improve banking API (Thanks @Encoded)


      Adds methods for returning and using Java Lists, rather than arrays


      Slightly randomizes some hardcoded behaviour


      Removes sleeps from waitConditions; the efficiency saving potential is negligible in these use-cases, therefore cleaner code is preferable


      Other back-end improvements





      Note: If you are using LG, please restart both the RS client and TRiBot.
        • Sad
        • Haha
        • Thanks
        • Like
      • 90 replies
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...