Jump to content

Ignoring dropped item if fire is on the same tile


Beck

Recommended Posts

I'm working on a script which lights the logs on top of Lumbridge Castle. Quite often the logs respawn before the previous fire may despawn. How would I go about "ignoring" (of sorts) the log if it is on the same tile as the fire?

I'm assuming it could be done at the start of the onLoop, where instead of assigning the entity outside of the onLoop, I reassign it at the start of each iteration. Unsure though.

 Entity log = getGroundItems().closest("Logs");

New to the OSBot API so sorry if this is an ignorant question :/

All feedback would be appreciated.

Edited by R1pple
Link to comment
Share on other sites

6 hours ago, R1pple said:

I'm working on a script which lights the logs on top of Lumbridge Castle. Quite often the logs respawn before the previous fire may despawn. How would I go about "ignoring" (of sorts) the log if it is on the same tile as the fire?

I'm assuming it could be done at the start of the onLoop, where instead of assigning the entity outside of the onLoop, I reassign it at the start of each iteration. Unsure though.



 Entity log = getGroundItems().closest("Logs");

New to the OSBot API so sorry if this is an ignorant question :/

All feedback would be appreciated.

To do this you can declare a Filter and than use that Filter to get the closest log.

To declare a Filter to be used you would set it as a variable wherever you need it like so.

Heres a link to the Filter api doc.

private final Filter<RS2Object> logFilter = new Filter<RS2Object>() {
    @Override
    public boolean match(RS2Object rs2Object) {
        return rs2Object.getName().equalsIgnoreCase("logName")
                && getMap().canReach(rs2Object)
                && getObjects().get(rs2Object.getPosition().getX(), rs2Object.getPosition().getY())
                .stream().noneMatch((object) -> object.getName().equalsIgnoreCase("Fire"));
    }
};

You would need to replace the logName string with the name of the log you are looking for.

This Filter will check a few conditions first, if the RS2Object's name matches the supplied string, second it checks to see if you can reach the object lastly, it checks to see if there are no fires at that position.

To use the filter in the onLoop() method you would call getObjects().closest(logFilter) and set that equal to a variable than null check it before acting up on it. Like so.

RS2Object log = getObjects().closest(logFilter);

if (log != null) {
    doLogic();
}
Edited by BravoTaco
  • Like 2
Link to comment
Share on other sites

4 hours ago, BravoTaco said:

To do this you can declare a Filter and than use that Filter to get the closest log.

To declare a Filter to be used you would set it as a variable wherever you need it like so.

Heres a link to the Filter api doc.


private final Filter<RS2Object> logFilter = new Filter<RS2Object>() {
    @Override
    public boolean match(RS2Object rs2Object) {
        return rs2Object.getName().equalsIgnoreCase("logName")
                && getMap().canReach(rs2Object)
                && getObjects().get(rs2Object.getPosition().getX(), rs2Object.getPosition().getY())
                .stream().noneMatch((object) -> object.getName().equalsIgnoreCase("Fire"));
    }
};

You would need to replace the logName string with the name of the log you are looking for.

This Filter will check a few conditions first, if the RS2Object's name matches the supplied string, second it checks to see if you can reach the object lastly, it checks to see if there are no fires at that position.

To use the filter in the onLoop() method you would call getObjects().closest(logFilter) and set that equal to a variable than null check it before acting up on it. Like so.


RS2Object log = getObjects().closest(logFilter);

if (log != null) {
    doLogic();
}

Awesome, thanks for the help. 

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