Jump to content

Script double clicking object - Help


Recommended Posts

Posted (edited)

God day,

Note that i'm currently a complete beginner on scripting, but i have some strange behavior that when we can interact with deposit box it double clicks it every time. I don't know if this is intentional or something i'm doing wrong?

log("Invt full and we are at deposit area!");
                if(depositbox.isVisible() && deposit.contains(myPlayer().getPosition())) {
                    // Depositbox is visable and we are in the area
                    log("Deposit box visable and we are in area!");
                    if(!bank.depositBox.isOpen()) {
                        // Deposit box aint open
                        log("Depositbox aint open");
                        if(depositbox.interact("Deposit")) {
                            log("Clicking deposit box!");
                            // We can interact with the deposit box
                            new ConditionalSleep(5000) {
                                @Override
                                public boolean condition() {
                                    return bank.depositBox.open();
                                }
                            }.sleep();
                        } else {
                            // We cant interact with the deposit box!
                            log("We cant interact with deposit box!");
                        }
                    } else {
                        // Depositbox is open.
                        log("Depositbox is open!");
                    }
                } else {
                    // Deposit box not visable or we are not in area.
                    log("Depositbox or area not there.");
                }

 

Edited by Slakan
Posted

The reason this is happening is due to this:

new ConditionalSleep(5000) {
	@Override
	public boolean condition() {
		return bank.depositBox.open();
  }
}.sleep();

The line: return bank.depositBox.open(); is a function that tries to open the deposit box and returns true if it executes the action, so basically you are clicking to open the depositBox and then your conditional sleep is opening it again. What you want to do here instead is use the isOpen() function:

new ConditionalSleep(5000) {
	@Override
	public boolean condition() {
		return bank.depositBox.isOpen();
	}
}.sleep();

 

  • Like 2
Posted
17 hours ago, Delision said:

The reason this is happening is due to this:

new ConditionalSleep(5000) {
	@Override
	public boolean condition() {
		return bank.depositBox.open();
  }
}.sleep();

The line: return bank.depositBox.open(); is a function that tries to open the deposit box and returns true if it executes the action, so basically you are clicking to open the depositBox and then your conditional sleep is opening it again. What you want to do here instead is use the isOpen() function:

new ConditionalSleep(5000) {
	@Override
	public boolean condition() {
		return bank.depositBox.isOpen();
	}
}.sleep();

 

Thank you! You are absolute correct there, i didn't see the mistake i did, but i should have used isOpen() as you say. 

 

Much appreciated for the help!

  • Like 1
Posted (edited)
11 hours ago, Slakan said:

Thank you! You are absolute correct there, i didn't see the mistake i did, but i should have used isOpen() as you say. 

 

Much appreciated for the help!

Also you could replace 

deposit.contains(myPlayer().getPosition())

with just deposit.contains(myPlayer()) or deposit.contains(myPosition())

Edited by minewarriors
Posted
17 hours ago, minewarriors said:

Also you could replace 

deposit.contains(myPlayer().getPosition())

with just deposit.contains(myPlayer()) or deposit.contains(myPosition())

What is the benefit of the different versions? - If i understand my original one i access myPlayer() to get the position of my entity.

The deposit.contains(myPlayer()) would just check if my entity is within the spesific area and deposit.contains(myPosition()) would actually check the position of my entity?

Posted
20 minutes ago, Slakan said:

What is the benefit of the different versions? - If i understand my original one i access myPlayer() to get the position of my entity.

The deposit.contains(myPlayer()) would just check if my entity is within the spesific area and deposit.contains(myPosition()) would actually check the position of my entity?

all the 3 things do the same.

  • Like 1

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...