Jump to content

Script won't open the gate?


September

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

 

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");
		}
Link to comment
Share on other sites

 

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
Link to comment
Share on other sites

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;
}
Link to comment
Share on other sites

  • 2 months 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...