Jump to content

Fuz

Trade With Caution
  • Posts

    39
  • Joined

  • Last visited

  • Days Won

    1
  • Feedback

    0%

Posts posted by Fuz

  1. Ok, I feel like a few things are missing, as well as ways current methods could be improved. This is a Beta and I feel these are useful suggestions. I will be updating the thread with more suggestions as I come across anything that could be improved. Feel free to use any of my code from this thread in your own scripts etc (Credit would be appreciated).

     


    Closest entity methods:
    Overall, it would be more benificial to loop through the entities like this:

    for (RS2Object o : client.getCurrentRegion().getObjects()) {

    rather than (what I presume is) this: Spoke to Laz about this, the original method only returns "reachable" objects.

    for (RS2Object o : client.getObjects()) {

    as the latter seems to be buggy (for example, in my Fight Caves script it seems to almost always return null for the entrance).

    I also would like to add that a method for returning the closest ground items is also abscent in the API. Here is a method which I quickly wrote:

    private RS2Object getClosestObject(int id) {    RS2Object o = null;    for (RS2Object obj : client.getCurrentRegion().getObjects())	    if (obj != null && obj.getId() != null && obj.getId() == id)		    if (o == null || distance(obj) < distance(o))			    o = obj;    return o;}

     

    Another useful feature (paired with the closestEntity methods) is the use of Filters, which would be useful in most scripts. This could also be easily achieved by creating an abstract class:

    interface Filter<T> {    public boolean accept(T element);}

    and could be implemented, for example, with

    GroundItem closestGroundItem(Filter f) {    GroundItem item = null;    for (GroundItem i : client.getCurrentRegion().getItems())        if (i != null) if (item == null && f.accept(i))        item = g;    return item;}

    and could be called with

    GroundItem getCoins() {    return closestGroundItem(new Filter<GroundItem>() {         @Override boolean accept(GroundItem item) {            return item.getId() == 996;        }    });}

    This is all I have now, but as stated above, I shall add more as I see fit.

     

    Interaction methods:
    It is likely to have been mentioned before, but I think it would be a good move to have interact with entities using a method more along the lines of

    entity.interact(String, boolean);

    as opposed to the current

    selectEntityOption(Entity, boolean)

    as it has a more logical look to it (in my opinion). At the same time, I would also like mention another important method to add would be said interacton methods for inventory items and possibly widgets (RSInterface/RSInterfaceChild) too.


     

    Distance calculation methods:
    Similar to above, not much to be improved but for calculating distance between entities it would be more convenient to have the method

    entity.distance(Entity)

    instead of

    entity.getPosition().distance(Entity.getPosition())

    or just have a script-level method such as

    distance(Entity, Entity)

     

     

    Widget-related methods:

    This is another thing I find is missing, it would also be useful to be able to "search" for widgets using a String argument as well as a method to click continue in dialogue. Here is some code I quickly wrote (under the assumption that RS2InterfaceChild.getMessage() returns the text on the widget)

    public boolean clickContinue() {    RS2InterfaceChild c = getChildWithText("continue");    if (c != null)        return c.click();    return false;}public RS2InterfaceChild getChildWithText(String text) {    for (RS2Interface i : client.interfaces)        for (RS2InterfaceChild c : i.getChildren())            if (c.getMessage().contains(text))                return c;    return null;}public RS2InterfaceChild getChildWithText(String... text) {    for (RS2Interface i : client.interfaces)        for (RS2InterfaceChild c : i.getChildren())            for (String s : text)                if (c.getMessage().contains(s))                    return c;    return null;}
×
×
  • Create New...