Lexhanatin Posted August 12, 2018 Share Posted August 12, 2018 (edited) Previous thread: So it seems as if the portal in the rune essence mine changes types from object to NPC to whatever. I'm having trouble implementing a solution for this. I've used some of the ideas explored in the previous thread, but my understanding is still weak. I originally wanted to filter through both objects and NPCs but Chris told me this wasn't possible. Instead he suggested for me to add both types to a list then filter through them. // Is this the correct way of creating and adding to a list? // Create List <Object> portals = new ArrayList<>(); //Add portals.add(getObjects().getAll().stream().filter(object -> object.getName().contains("Portal")).findAny()); //Add portals.add(getNpcs().getAll().stream().filter(object -> object.getName().contains("Portal")).findAny()); I'm not sure how to interact with the list of type Object. I was thinking of iterating through the list checking if the object was present, then interacting with it, but you can't interact unless the list is <Entity> not <Object>. If the list is <Entity> it's difficult to add to it... Basically... I have no idea what I'm doing, and I need some more assistance :). It should be common knowledge now, but in case it's forgotten, I take a while to learn, so pls be patient :). EDIT Read the 4th post for the solution. Edited August 14, 2018 by Lexhanatin Solved Quote Link to comment Share on other sites More sharing options...
liverare Posted August 12, 2018 Share Posted August 12, 2018 NPC portalNpc = null; RS2Object portalObj = null; int portalNpcDist = Integer.MAX_VALUE; int portalObjDist = Integer.MAX_VALUE; Entity portalEntity; // Find objects portalNpc = npcs.closest("Portal"); portalObj = objects.closest("Portal"); // Check if either NPC or OBJ is valid if (portalNpc != null || portalObj != null) { // Calculate distance to NPC if (portalNpc != null) { portalNpcDist = map.distance(portalNpc); } // Calculate distance to OBJ if (portalObj != null) { portalObjDist = map.distance(portalObj); } // Check distance // Note: NPC or OBJ may be null if (portalNpcDist < portalObjDist) { // NPC is closer portalEntity = portalNpc; } else { // OBJ is same distance/closer portalEntity = portalObj; } // Finally, check portal if (portalEntity != null) { // Interact if (portalEntity.interact("Exit")) { // TODO: Conditional sleep } } } Quote Link to comment Share on other sites More sharing options...
Lexhanatin Posted August 13, 2018 Author Share Posted August 13, 2018 (edited) @liverare Not sure why nothing is being detected. Edit: It works sometimes, but when nothing is detected it just stalls. Edited August 13, 2018 by Lexhanatin Added extra info. Quote Link to comment Share on other sites More sharing options...
Lexhanatin Posted August 14, 2018 Author Share Posted August 14, 2018 I found the problem in @liverare solution. Simply the portals name isn't "Portal". Extra tags are added to the name preventing the below code from working. portalNpc = npcs.closest("Portal"); portalObj = objects.closest("Portal"); Instead partial matching should be used instead. portalNpc = getNpcs().closestThatContains("Portal"); portalObj = getObjects().closestThatContains("Portal"); This will always find a portal. The second problem in the solution was the implementation of distance. The current instance of portal would be of type NPC or Object, but when comparing distances, another instance was deemed closer. This would prevent interaction. A possible reason for this could be that the current portal instance was being compared to a previous instances distance. I'm not sure. I fixed this by taking out the distance comparison. Below is the find product. private void bank() throws InterruptedException { log("Bank method"); if (getObjects().closest("Rune Essence") != null) { log("Rune Essence Exists"); portalNpc = getNpcs().closestThatContains("Portal"); portalObj = getObjects().closestThatContains("Portal"); if (portalNpc != null || portalObj != null) { log("Entity not null"); if (portalNpc != null) { log("Portal is NPC"); portalEntity = portalNpc; } if (portalObj != null) { log("Portal is Object"); portalEntity = portalObj; } if (portalEntity != null) { log("Portal Interaction"); if (portalEntity.interact("Exit", "Use")) { new ConditionalSleep(8000) { @Override public boolean condition() throws InterruptedException { return !myPlayer().isMoving(); } }.sleep(); } } } else { log ("Entity null"); } } I would like to thank everyone for helping me solve this problem over the week. Hopefully this thread will help people with similar problems in the future. Quote Link to comment Share on other sites More sharing options...