Jump to content

Script won't open the gate?


Recommended Posts

Posted (edited)

Hello everyone. I got into scripting yesterday and I am currently working on a chicken killing script. Sometimes the bot will get stuck outside.

 

Here is my gate opening code. Why doesn't it work? wacko.png

if(chatbox.contains(MessageType.GAME, "I can't reach that!")) {
				Entity gate = objects.closest("Gate");
				if(gate != null) {
					gate.interact("Open");
				}

I know this isn't the smartest way to implement a check. As if it happens once it will continue to try opening the gate because the message will remain in the chat. But i will fix it later. For now i just want to know why it won't work.

 

 

Edit: Solved the problem.

Edited by flamingstick70
Posted

If anyone else has this problem, a solution is to check if the gate is open already, and if it's not open, that's when you run your open command.

 

Credit to Explv for giving me this in the chat box

	public boolean doorIsClosed(RS2Object door) {

		return Arrays.asList(door.getDefinition().getActions()).contains("Open");
		}
  • Like 1
Posted

 

If anyone else has this problem, a solution is to check if the gate is open already, and if it's not open, that's when you run your open command.

 

Credit to Explv for giving me this in the chat box

	public boolean doorIsClosed(RS2Object door) {

		return Arrays.asList(door.getDefinition().getActions()).contains("Open");
		}
Posted

 

If anyone else has this problem, a solution is to check if the gate is open already, and if it's not open, that's when you run your open command.

 

Credit to Explv for giving me this in the chat box

	public boolean doorIsClosed(RS2Object door) {

		return Arrays.asList(door.getDefinition().getActions()).contains("Open");
		}
public boolean doorIsClosed(RS2Object door) {
    return door.hasAction("Open");
}

 

  • Like 2
Posted

Much cleaner, thanks for that.

 

You could actually just have something like this:

public boolean openNearestGate() {
    Entity closedGate = getObjects().closest("Gate", (e) -> (e.hasAction("Open"))); //may be incorrect syntax for Objects#closest
    if (closedGate != null) return closedGate.interact("Open");
    return false;
}
  • 2 months later...

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