Jump to content

Interact with Random Item


Recommended Posts

Posted

Hey guys. I've been testing and testing for few hours now. I'm trying to for example out of all the Sharks in my inventory click a random shark. Tried loads of methods. All just seem to click the top shark. Please don't post or ask what this is for or it is not needed. I need someone who could push me in the right direction. Thanks!

Posted (edited)

Not the best way to do it, but i wrote it in about 30 seconds...and it should work

 

			int slot = random(0, 27);
			int attempts = 0;
			while (!inventory.getItemInSlot(slot).getName().equals("Shark")) {
				if (attempts > 50)
					break;
				slot = random(0, 27);
				attempts++;
			}
			mouse.click(new InventorySlotDestination(getBot(), slot), false);

Add you own logic, error checking, etc

 

https://osbot.org/api/org/osbot/rs07/input/mouse/InventorySlotDestination.html#InventorySlotDestination-org.osbot.rs07.Bot-int-

Edited by Polymorphism
Posted
Just now, Polymorphism said:

Not the best way to do it, but i wrote it in about 30 seconds...and it should work

 


			int slot = random(0, 27);
			int attempts = 0;
			while (!inventory.getItemInSlot(slot).getName().equals("Shark")) {
				if (attempts > 50)
					break;
				slot = random(0, 27);
				attempts++;
			}
			mouse.click(new InventorySlotDestination(getBot(), slot), false);

 

Thanks a bunch!!! Going to try this soon!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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