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

Sell OSRS Gold
Sign in to follow this  
Starfox

RSUtil class

Recommended Posts

Some useful methods.

 

public class RSUtil {    /**     * Gets the per hour value for the specified value.     * @param value The value to evaluate.     * @param startTime The time in ms when the script started.     * @return The per hour value.     */    public static long getPerHour(final int value, final long startTime) {        return (long)(value * 3600000D / (System.currentTimeMillis() - startTime));        }        /**     * Gets the xp gained for the specified skill based on the start xp.     * @param skill The skill to get the xp gained.     * @param startXp The starting xp of the skill.     * @return The xp gained.     */    public static String getXpGainedAndHour(final Skills.SKILLS skill, final int startXp) {        final int xp = skill.getXP() - startXp;        return "" + xp + " (" + getPerHour(xp, Vars.startTime) + ")";    }    /**     * Gets the players current hit points.     * @return the players current hit points.     */    public static int getPlayerHPPercent() {        return (int) (100.0 * ((double)Skills.SKILLS.HITPOINTS.getCurrentLevel() / (double)Skills.SKILLS.HITPOINTS.getActualLevel()));    }    /**     * Gets the the Image from the specified url.     * @param url The url to get the Image from.     * @return The Image retrieved; null if no Image was found.      */    public static Image getImageFromUrl(final String url) {        try {            return ImageIO.read(new URL(url));        } catch (IOException e) {            General.println("Failed to retreive image from: " + url);            return null;        }    }    /**     * Gets the nearest RSObject with the specified name.     * @param name The name of the RSObject to search for.     * @param dist The distance away from the player.     * @return the nearest RSObject with the specified name; null of no objects were found.     */    public static RSObject getObject(final String name, final int dist) {        final RSObject[] objs = Objects.findNearest(dist, name);        return objs.length > 0 ? objs[0] : null;    }        /**     * Gets the nearest RSObject with the specified id.     * @param id The id of the RSObject to search for.     * @param dist The distance away from the player.     * @return the nearest RSObject with the specified id; null of no objects were found.     */    public static RSObject getObject(final int id, final int dist) {        final RSObject[] objs = Objects.findNearest(dist, id);        return objs.length > 0 ? objs[0] : null;    }        /**     * Gets the first item in the Inventory that matches the specified id.     * @param id The id of the item to search for.     * @return the first item in the Inventory that matches the specified id;     * null of no items were found.     */    public static RSItem getItem(final int id) {        final RSItem[] inv = Inventory.find(id);        return (inv != null && inv.length > 0) ? inv[0] : null;    }        /**     * Gets the first item in the Inventory that matches the specified name.     * @param name The name of the item to search for.     * @return the first item in the Inventory that matches the specified name;     * null of no items were found.     */    public static RSItem getItem(final String name) {        final RSItem[] inv = Inventory.find(name);        return (inv != null && inv.length > 0) ? inv[0] : null;    }        /**     * Checks to see if the inventory contains the specified item.     * @param id The id of the item.     * @return true if the inventory contains the item; false otherwise.     */    public static boolean hasItem(final int id) {        final RSItem[] inv = Inventory.find(id);        return inv != null && inv.length > 0;    }}
  • Like 1

Share this post


Link to post
Share on other sites
Array

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 Aleks7000
      Hey guys, i tried to remove java, and reinstall it a few times, and the same about tribot, but it doesnt seem to get the problem fixed. i dont know if im doing this right but it used to work. Im downloading the jar file, putting it on desktop, and opening with java. it used to work like this, but now it suddenly doesnt. anybody got a fix for this or any directions? please? 
  • 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.
      • 50 replies
    • Come give us feedback on the next version of TRiBot!
      • 86 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
      • 25 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.
      • 90 replies
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...