Jump to content

Plague's Snippet Collection


PlagueDoctor

Recommended Posts

Gonna consolidate all of the useful snippets i find or am shown by other users here, so i don't have to mess up my bookmarks.

 

Timer Code:

 

 

For a timer you could do something like this:

//Class variable
private long timer;

//when you want to start/reset the timer
timer = System.currentTimeMillis();

//to check if the timer is past a certain amount of time, ex. 1 min.
System.currentTimeMillis() - timer >= 60000;

 

NPC Filtering:

 

NPCs closest returns a single NPC, not a collection of NPCs for you to filter.

 

You want something like:

 Optional<NPC> suitableNpc = getNpcs().getAll().stream().filter(npc -> npc.getHealthPercent() > 1).findFirst();
        if (suitableNpc.isPresent()) {
            suitableNpc.get().interact("examine");
        }

You may want to look a little bit into Java 8 streams before using them.

 

 

Edit:

Or better yet you can use the FilterAPI way which is native to OSBot smile.png
 

getNpcs().closest(new Filter<NPC>() {
            @[member='Override']
            public boolean match(NPC obj) {
                return obj.getHealthPercent() > 1;
            }
        }) ;

 

EntityAPI: http://osbot.org/api/org/osbot/rs07/api/EntityAPI.html

 

 

Lvl 2 Enchant Ring @ Falador East Bank: (wrote this and decided not to use it feels.png)
RS2Widget enchant = getWidgets().get(218, 17);
    		Item emeraldRing = getInventory().getItem("Emerald ring");
    		if(!faladorEastBank.contains(myPlayer())) {
    			status = "Walking to falador east bank.";
    			getWalking().webWalk(faladorEastBank);
    		}
    		if(!getEquipment().isWearingItem(EquipmentSlot.WEAPON, "Staff of air")) {
    			if(!inventory.contains("Staff of air")) {
    				if(!bank.isOpen()) {
    					status = "Opening bank.";
    	    			getBank().open();
    	    			Constants.condSleep(10000, 300, () -> bank.isOpen()); 
    	    		}
    				status = "Withdrawing staff of air.";
    				bank.withdraw("Staff of air", 1);
    				Constants.condSleep(10000, 300, () -> inventory.contains("Staff of air")); 
    			}
    			getEquipment().equip(EquipmentSlot.WEAPON,"Staff of air");
    			status = "Equiping Staff of air.";
    			Constants.condSleep(10000, 300, () -> getEquipment().isWearingItem(EquipmentSlot.WEAPON, "Staff of air"));
    		} 	
    		
    		if(!getInventory().contains("Emerald ring") || !getInventory().contains("Cosmic rune")) {
    			if(!bank.isOpen()) {
    				status = "Opening bank.";
        			getBank().open();
        			Constants.condSleep(10000, 300, () -> bank.isOpen()); 
        		}
    			status = "Depositing inventory.";
    			getBank().depositAllExcept("Emerald ring", "Cosmic rune");
    			Constants.condSleep(10000, 300, () -> inventory.onlyContains("Cosmic rune"));
    			status = "Withdrawing cosmics/emerald rings.";
    			bank.withdrawAll("Cosmic rune");
    			bank.withdrawAll("Emerald ring");
    			Constants.condSleep(10000, 300, () -> inventory.contains("Emerald ring", "Cosmic rune"));    			
    		}
    		if(inventory.contains("Emerald ring", "Cosmic rune")) {
    			if(bank.isOpen()) {
    				status = "Closing bank.";
    				bank.close();
    			}
    			if(!getTabs().open(Tab.MAGIC)) {
    				status = "Opening Magic tab.";
    				getTabs().open(Tab.MAGIC);
    			}
    			if(enchant != null && enchant.isVisible()) {
    				enchant.interact();
    				status = "Clicking enchant.";
    				if(getTabs().open(Tab.INVENTORY)) {
    					if(emeraldRing != null) {
    						status = "Clicking emerald ring.";
    						emeraldRing.interact();
    					}
    					Constants.condSleep(10000, 300, () -> getTabs().open(Tab.MAGIC)); 
    				}
    			}
    			
    			
    		}
Players are nearby: 
public boolean imAlone()	{
		Area area = alchSpot;//create your own area
		int amount = 0;
		
		for (Player player: players.getAll())	{
			if (player != null && !player.getName().equalsIgnoreCase(myPlayer().getName())){
				if (area.contains(player))	{
					amount++;
				}
			}
		}
		return amount == 0;	
	}

 

Edited by PlagueDoctor
  • Like 4
Link to comment
Share on other sites

  • 2 months later...
  • 2 weeks later...

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...