Jump to content

getMouse.click not working


d0zza

Recommended Posts

I'm trying to use getMouse().click but it doesn't seem to be clicking when I want it to.

My code is as follows:

for (i = 0; i < 28; i++) {
	if (InventorySlotDestination.getSlot(i).contains(getMouse().getPosition())) {
		if (getMouse().click(false)) {
			i++;
			sleep(random(100, 125));
		}
	} else {
		Rectangle rect = InventorySlotDestination.getSlot(i);
		getMouse().move(rect.x + (rect.width / 2), rect.y + (rect.height / 2));
		sleep(random(100, 125));
	}
}

Basically I'm just trying to click on all items in my inventory, my mouse moves through the inventory as intended but doesn't click on anything.

I don't want to use inventory.interact() as that doesn't serve the right purpose for what I want to do.

Edited by d0zza
Link to comment
Share on other sites

4 minutes ago, Charlotte said:

How do you expect to click something when there's no action after a condition?

This line here:
if (getMouse().click(false)) {

should be clicking the mouse, just because I have it in an if statement doesn't mean its not going to do anything. getMouse().click() is a boolean function that returns true if the mouse is clicked or false if it isn't.

  • Like 1
Link to comment
Share on other sites

39 minutes ago, d0zza said:

This line here:
if (getMouse().click(false)) {

should be clicking the mouse, just because I have it in an if statement doesn't mean its not going to do anything. getMouse().click() is a boolean function that returns true if the mouse is clicked or false if it isn't.

Well it should be clicking correctly, most likely the first if statement is wrong.

But Im guessing you want it to shif click drop, which osbot already does if you enable it in game :b

Link to comment
Share on other sites

2 hours ago, Vilius said:

Well it should be clicking correctly, most likely the first if statement is wrong.

But Im guessing you want it to shif click drop, which osbot already does if you enable it in game :b

Oh fuck me I know why, I should be using a while loop, not a for loop

Edited by d0zza
Link to comment
Share on other sites

try this

for (int i = 0; i < 28; i++) {
    if (getMouse().click(getInventory().getMouseDestination(i))) {
        sleep(random(100, 125));
    }
}

you can decrement i if it fails to click the slot, but that may produce weird results

also may want to check if there's an item at slot unless you want it to click empty slots

  • Like 1
Link to comment
Share on other sites

It doesn't click because you're wasting your index on moving to the slot :P then the next loop it will come in the first else again, moving to the next...but the first if statement never gets executed...
 

for (i = 0; i < 28; i++) {
	if (InventorySlotDestination.getSlot(i).contains(getMouse().getPosition())) {
		//...never gets in here, because this is the next slot...why would the mouse already be there?
	} else {
		//...always executes this to move to the next
	}
}

so basically you want something like

for (i = 0; i < 28; i++) {
	if (!InventorySlotDestination.getSlot(i).contains(getMouse().getPosition())) {
		Rectangle rect = InventorySlotDestination.getSlot(i);
		if (getMouse().move(rect.x + (rect.width / 2), rect.y + (rect.height / 2))) {
			sleep(random(100, 125));
		}
	}

	if (InventorySlotDestination.getSlot(i).contains(getMouse().getPosition())) {
		if (getMouse().click(false)) {
			// i++; this one isn't necessary unless you want to skip
			// items
			sleep(random(100, 125));
		}
	}
}

But anyways, as Stimpack already said, it's easier to let the osbot api do all that for you by using 

getMouse().click(getInventory().getMouseDestination(i))
Edited by Reveance
Link to comment
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.

  • Recently Browsing   0 members

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