Jump to content

Bobrocket

Members
  • Posts

    1664
  • Joined

  • Last visited

  • Days Won

    4
  • Feedback

    100%

Posts posted by Bobrocket

  1. filter will go through all the items in the list just like a loop will, unless its async it shouldn't perform significantly better. I do agree filters are much cleaner code though.

     

    Also, without using a 3rd party API you can use filter like:

    getObjects().getAll().stream().filter(o -> o.exists()).findFirst()

    Its not as pretty but it works!

     

    Edit: Fixed derp typo lol

     

    Don't forget that you can replace stream() with parallelStream() to multithread the operation smile.png

    Streams can be used for a lot of cooler things, if you want to learn some more things to do with streams as well as learning the full syntax visit here:

    http://osbot.org/forum/topic/81691-basic-streams-and-how-to-use-them/

    The full stream would look a little like this:

    Entity chest = getObjects().getAll().stream().filter((o) -> (o != null && o.exists() && o.getName().equals("Chest") && o.getPosition().equals(new Position(x, y, z)))).findFirst().orElse(null);
    

    On the off chance that you're using OmniAPI (shameless self plug because fuck you), you can just use:

    Entity chest = getEntityFinder().findClosest("Chest", (entity) -> (entity.getPosition().equals(new Position(x, y, z))));
    

    OmniAPI uses streams in its finders too smile.png

  2. RuneScape has over 200 million registered users, it's the biggest F2P* MMORPG and will remain that way for a very long time. It won't be dying any time soon.

     

    *f2p as in free to play, not free for everything

     
     
     
     
    • Like 1
  3.  

    You can use a filter. I made a script very similar to this which also alches the looted nats. Heres an example using filters, although i prefer to use lambas rather than the traditional way of filtering:

    chest = getObjects().closest(o -> o.getPosition().equals(new Position(2671, 3301, 1))); // filters out every entity that's not at the specified position (ie. chest 2)
    			if(chest.interact("Search for traps")){
    			log("Attempting to loot chest...");
    			new ConditionalSleep(15500, 17550){
    
    				@Override
    				public boolean condition() throws InterruptedException {
    					int start = getSkills().getExperience(Skill.THIEVING);
    					return ((getSkills().getExperience(Skill.THIEVING) > start) || wasLooted);
    				}
    				
    			}.sleep();
    // I have a method that wasLooted that uses game messages to see if its already looted and then the wait time is adjusted accordingly
    

     

    Your conditional sleep won't work, because it calls condition() which means it will reset start every time. 

  4. How would you implement interaction with other utilities like what if you need to enter an amount into a GUI for how many X of X you want to do?

    Also how do you listen for interaction with paint? Dumb question but i never learned it.

     

    I have my own - infrequently updating - paint library that's on Github, it has buttons, pictures etc. Adding textboxes wouldn't be too hard, I have experience from all of this because I was a game developer back in the day :) Even if I didn't make my own paint textbox, I could just have a popup.

    The github also explains how to listen for mouse movement/clicks.

  5. c35f069f1753fde746d5bd5c78577828.gif

    Going to move from having separate GUIs to having them built in to the RS paint. Thoughts?

    Pros at a glance:

    • More intuitive, can display things such as selected entities easier

    Cons at a glance:

    • Will use a tiny bit more resources than a separate GUI (we're talking very small numbers)
    • Like 5
  6. The "science" of this:

    In windows, we have 2 SWAP partitions (or files if you will): hiberfile.sys and pagefile.sys - hiberfile stores the states of every program for when you hibernate (it's how we recover programs, it's essentially a dump of your RAM). Disabling this means that you can't hibernate, which means hiberfile no longer has a dump of the RAM and is now useless (and empty).

    I wouldn't recommend doing this, as it can cause problems.

  7. I'm not a professional but I made a version of this that wrote the items in a list on the paint a while back, here's the snippet just because. Even though the problem was already solved.

    		List<GroundItem> itemsog = getGroundItems().getAll();
    		int count = 0;
    		for (int i = 0; i < itemsog.toArray().length; i++) {
    			for (int i2 = 0; i2 < itemsog.toArray().length; i2++) {
    				if (itemsog.get(i).getName().equalsIgnoreCase(itemsog.get(i2).getName()) && count == 1) {
    					itemsog.remove(i2);
    					count = 0;
    				}
    				if (itemsog.get(i).getName().equalsIgnoreCase(itemsog.get(i2).getName()) && count == 0) {
    					count = 1;
    				}
    			}
    		}
                    g.setFont(new Font("Trebuchet MS", Font.PLAIN, 10);
                    g.setColor(Color.WHITE);
    		for (int i = 0; i < itemsog.toArray().length; i++) {
    			g.drawString(itemsog.get(i).getName(), 8, 30 + (i * 11));
    		}
    

    I know it's lazy as hell and doesn't properly use the API but it's something I improvised due to lack of knowledge there was an easier way xD

    Even though it's dirty code it works fine and weeds out all duplicate item names and displays them in the top left corner. of the screen in a nice screen space saving list.

     

    @OP, if you want a cleaner version of Paradox's code (pretty inefficient, hard to read etc) here you go:

    List<GroundItem> groundItems = getGroundItems().getAll().stream().distinct().collect(Collectors.toList());
    int j = 0;
    groundItems.forEach((gi) -> (g.drawString(gi.getName(), 8, 30 + ((j++) * 11))));
    
  8. There is no native support in the Item class, or even ItemContainer for that matter. You (sadly) need to make an inventory destination and get the rectangle through there.

     

    EDIT: For bank, you can get it like so:

    public Rectangle getRectForItem(Item i) {
        int slot = getBank().getSlot(i);
        int tab = getBank().getTabForAbsoluteSlot(slot);
        return getBank().getAbsoluteSlotPosition(tab, slot);
    }
    
×
×
  • Create New...