kocke Posted April 13, 2014 Share Posted April 13, 2014 Hello So I'm kinda stuck in making my new script, I can't figure out how to check if the door is closed and open it if it's closed. Please help me. Link to comment Share on other sites More sharing options...
Ande Posted April 13, 2014 Share Posted April 13, 2014 if(door.getDefinition().getActions()[0].equals("Open")){ door.interact("Open); } 1 Link to comment Share on other sites More sharing options...
Joseph Posted April 13, 2014 Share Posted April 13, 2014 (edited) you could also create an area using one tile. Check that one tile to see if a door is null or not. Because the position of a tile changes when you open and close the door. Edited April 13, 2014 by josedpay Link to comment Share on other sites More sharing options...
Swizzbeat Posted April 13, 2014 Share Posted April 13, 2014 Arrays.asList(door.getDefinition().getActions()).contains("Open"); Link to comment Share on other sites More sharing options...
kocke Posted April 21, 2014 Author Share Posted April 21, 2014 Arrays.asList(door.getDefinition().getActions()).contains("Open"); Care to elaborate? if(door.getDefinition().getActions()[0].equals("Open")){ door.interact("Open); } I can't get this to work, where do I add the id/name of the door I want to open? Link to comment Share on other sites More sharing options...
Mr def nerd Posted April 21, 2014 Share Posted April 21, 2014 (edited) If you are using the code for one specific door at a specific location you could create a class to hold the name and position, such as this: package com.scripts.mrsdefnerd.dnfishcooker.utils; import org.osbot.script.rs2.map.Position; import org.osbot.script.rs2.model.RS2Object; import com.scripts.mrsdefnerd.dnfishcooker.core.Main; public abstract class ObstacleObject { private String name; private Position location; public ObstacleObject(String name, Position location) { this.name = name; this.location = location; } public final String getName() { return name; } public final Position getLocation() { return location; } public final RS2Object get(Script ctx) { for (RS2Object object : ctx.closestObjectListForName(getName())) if (object != null && object.getPosition().equals(getLocation())) return object; return null; } public abstract boolean validate(Script ctx); } Declare this somewhere (I guess you can just declare it at the top of the class): ObstacleObject door; Then you can do something like this in you startup method: door = new ObstacleObject("Door", new Position(2816, 3438, 0)) { @Override public boolean validate(Script ctx) { return this.get(ctx) != null && !this.get(ctx).getDefinition().getActions()[1].toLowerCase().contains("close"); } } What the above code does is that it overrides the validate method to your custom prefference (it will check if the object at that position is not null, and make sure that the object does not have an action that contains close). EDIT: The "Door" is the name of the object, the new Position() is the position of the object, and the validate is the requirements for the object to retrieved (This way you can support most objects) This is probably a bit overdone, but if you have to handle alot of different objects I guess its a good way to do it. To use the code simply do (I am assuming you are calling the door class from the class that extends script): RS2Object doorObject = door.get(this); Edited April 21, 2014 by Mrsdefnerd Link to comment Share on other sites More sharing options...
lazyy Posted April 21, 2014 Share Posted April 21, 2014 ^^ nobo above me said it :D Link to comment Share on other sites More sharing options...
Th3 Posted April 21, 2014 Share Posted April 21, 2014 You use pathfinder and clear door/obstacle flags and check for door/obstacle on the path. If one exists and is operable then it opens it. This is how AIO scripts handle obstacles without the actual position of them. Link to comment Share on other sites More sharing options...
Mr def nerd Posted April 21, 2014 Share Posted April 21, 2014 You use pathfinder and clear door/obstacle flags and check for door/obstacle on the path. If one exists and is operable then it opens it. This is how AIO scripts handle obstacles without the actual position of them. Yep, but its not really needed if you know what objects you are interacting with (lets say a specific door) Link to comment Share on other sites More sharing options...
PolishCivil Posted April 21, 2014 Share Posted April 21, 2014 Yep, but its not really needed if you know what objects you are interacting with (lets say a specific door) public final RS2Object get(Script ctx) { for (RS2Object object : ctx.closestObjectListForName(getName())) if (object != null && object.getPosition().equals(getLocation())) return object; return null; } Just a little enhancement by me: public WallObject getWallObjectOnPosition(Position position, String... names) { try { if (position == null) { return null; } if (client.getCurrentRegion() == null || client.getCurrentRegion().instance == null || client.getCurrentRegion().instance.getTiles() == null) { return null; } int localX = position.getLocalX(bot); int localY = position.getLocalY(bot); if (localX <= 104 && localY <= 104 && localX >= 0 && localY >= 0) { if (client.getCurrentRegion().instance.getTiles()[position.getZ()][localX][localY] == null) { return null; } XWallObject wallObject = client.getCurrentRegion().instance.getTiles()[position.getZ()][localX][localY].getWallObject(); WallObject wrap = WallObject.wrap(wallObject, position.getZ()); if (names.length == 0 || Arrays.asList(names).contains(wrap.getDefinition().getName())) { return wallObject == null ? null : wrap; } } } catch (Exception ignored) { } return null; } Link to comment Share on other sites More sharing options...
Daviyow Posted April 21, 2014 Share Posted April 21, 2014 well, closed door and a open door has 2 different ID's wouldnt it be possible to check if the open door id exist, to run trough, else just to open door ? Link to comment Share on other sites More sharing options...