wafihsn Posted May 14, 2016 Share Posted May 14, 2016 my qustion is this : how do i get object state ? i will explain , lets say i wanna chope down a tree , but if its already beeing choped or there is a player choping it i want the scrept to select another tree or wait , same this with logs , when i fire logs i want the script wait until the log is fired and then fire the next log , thank , i know im kind of "alot of qustion" guy but i issuer u when i get us for the work with this api ill be much more help then "need help" , waiting for replay thanx .. Quote Link to comment Share on other sites More sharing options...
Lemons Posted May 14, 2016 Share Posted May 14, 2016 Check for players chopping around the tree. You could do a simple check of any Player within 3 tiles of the tree and if they are animating, a better check would be to check the trees perimeter and possibly if they are facing the tree (since trees can be close to eachother). Depends how specific you need to get. For the fire, just keep watching the Position you are attempting to light on (not your current position as you will move) for a fire, or just check when your done animating (might not work if theres a break in the animation). Sorry for no code, I'm sure someone else can help :p. Quote Link to comment Share on other sites More sharing options...
Explv Posted May 14, 2016 Share Posted May 14, 2016 (edited) my qustion is this : how do i get object state ? i will explain , lets say i wanna chope down a tree , but if its already beeing choped or there is a player choping it i want the scrept to select another tree or wait , same this with logs , when i fire logs i want the script wait until the log is fired and then fire the next log , thank , i know im kind of "alot of qustion" guy but i issuer u when i get us for the work with this api ill be much more help then "need help" , waiting for replay thanx .. For checking if your player is chopping a tree you can just check if your player is animating: if(myPlayer().isAnimating()) // player is performing the chop animation, so is cutting a tree For finding the tree with the fewest players chopping it, you could try doing something like: private Optional<RS2Object> getTreeWithFewestPlayers() { return getObjects() .getAll() .stream() .filter(obj -> obj.getName().equals("Tree")) .min((tree1, tree2) -> Long.compare(getNumPlayersInteracting(tree1), getNumPlayersInteracting(tree2))); } private long getNumPlayersInteracting(final Entity entity) { return getPlayers().getAll().stream().filter(player -> player.getInteracting() == entity && player.isAnimating()).count(); } For lighting a fire you could sleep until your position changes (because after you light a fire your player walks to another tile): if(!isItemWithNameSelected("Tinderbox")) getInventory().interact("Use", "Tinderbox"); else lightFire(); private boolean isItemWithNameSelected(final String itemName) { final String selectedItemName = getInventory().getSelectedItemName(); return selectedItemName != null && selectedItemName.equals(itemName); } private void lightFire() { if(getInventory().getItem("Logs").interact()){ final Position playerPos = myPosition(); new ConditionalSleep(20_000) { @Override public boolean condition() throws InterruptedException { return !myPosition().equals(playerPos) && !myPlayer().isMoving(); } }.sleep(); } } Edited May 14, 2016 by Explv 1 Quote Link to comment Share on other sites More sharing options...
wafihsn Posted May 14, 2016 Author Share Posted May 14, 2016 For chopping a tree you can just check if your player is animating: if(myPlayer().isAnimating()) // player is performing the chop animation, so is cutting a tree For lighting a fire you could sleep until your position changes (because after you light a fire your player walks to another tile): if(!isItemWithNameSelected("Tinderbox")) getInventory().interact("Use", "Tinderbox"); else lightFire(); private boolean isItemWithNameSelected(final String itemName) { final String selectedItemName = getInventory().getSelectedItemName(); return selectedItemName != null && selectedItemName.equals(itemName); } private void lightFire() { if(getInventory().getItem("Logs").interact()){ final Position playerPos = myPosition(); new ConditionalSleep(20_000) { @Override public boolean condition() throws InterruptedException { return !myPosition().equals(playerPos) && !myPlayer().isMoving(); } }.sleep(); } } great i understand the way u used it , but there is one problem , if the player get back on the same path where he connot deploy logs and fire them , how can i tell the player to change direction if there is any problem firing them ? Quote Link to comment Share on other sites More sharing options...
Explv Posted May 14, 2016 Share Posted May 14, 2016 (edited) great i understand the way u used it , but there is one problem , if the player get back on the same path where he connot deploy logs and fire them , how can i tell the player to change direction if there is any problem firing them ? I think that when firemaking the player will always walk in one specific direction after lighting a log. I can't remember if it is North, East, South or West, but it is one of those. So, for example, if the player always walks South after lighting a log. Just make sure that the first position in the line where the player will light, is the Northern most position. That way, the player will never walk back over his fires. However, if this is not possible, you could always check if the player can light a fire in the current position, and walk to a different one if a fire cannot be lit. Maybe something like this would work? private boolean canPlayerLightAFire() { return getObjects().filter(new PositionFilter<>(myPosition())).size() == 0; } Alternatively, you can listen for the message "The player cannot light a fire here", or whatever it is, and move if that happens. Edited May 14, 2016 by Explv Quote Link to comment Share on other sites More sharing options...