nickeb0i Posted December 13, 2015 Share Posted December 13, 2015 (edited) Hello I'm new around here and I'm trying to learn how to script. I want to give something to the community but I have to learn to code first ;) My problems: I have to have a small fishing net in my inventory or it wont open bank and get one If I have a small fishing net it opens bank then closes then opens and continues like that private enum State { FISH, BANK, WAIT }; private State getState() { Entity stall = objects.closest("Fishing spot"); if (inventory.isEmpty() && !inventory.contains("Small fishing net")) return State.BANK; if (stall != null && inventory.contains("Small fishing net")) return State.FISH; return State.WAIT; } @Override public int onLoop() throws InterruptedException { switch (getState()) { case FISH: Entity spot = objects.closest("Fishing spot"); if (spot != null) { inventory.interact("Use", "Small Fishing Net"); if (inventory.isItemSelected() == true) spot.interact(); } break; case BANK: Entity bank = objects.closest("Bank booth"); if (!inventory.contains("Small fishing net")) getBank().withdraw("Small fishing net", 1); if (bank != null) { bank.interact("Bank"); sleep(random(500, 700)); getBank().depositAllExcept("Small fishing net"); } break; case WAIT: sleep(random(500, 700)); break; } return random(200, 300); } Edited December 13, 2015 by nickeb0i Quote Link to comment Share on other sites More sharing options...
Kenn Posted December 13, 2015 Share Posted December 13, 2015 (edited) Where abouts are you fishing? You haven't created a path way to get to the bank. Entity bank = objects.closest("Bank booth"); That will only pick up a bank thats within range of your camera angle Edited December 13, 2015 by Kenn Quote Link to comment Share on other sites More sharing options...
nickeb0i Posted December 13, 2015 Author Share Posted December 13, 2015 Where abouts are you fishing? You haven't created a path way to get to the bank. Entity bank = objects.closest("Bank booth"); That will only pick up a bank thats within range of your camera angle Are you sure? I think you mean if it's in a range within the minimap? Quote Link to comment Share on other sites More sharing options...
KEVzilla Posted December 13, 2015 Share Posted December 13, 2015 The fishing spot is a NPC, and not an object. Quote Link to comment Share on other sites More sharing options...
nickeb0i Posted December 13, 2015 Author Share Posted December 13, 2015 The fishing spot is a NPC, and not an object. It doesn't even get to the point where it should go to the fishing spot and fish? Quote Link to comment Share on other sites More sharing options...
KEVzilla Posted December 13, 2015 Share Posted December 13, 2015 (edited) It doesn't even get to the point where it should go to the fishing spot and fish? Alright here in pseudo-code: NPC spot = get NPC's nearby with a filter which have the name "Fishing spot" and have an action called "Net" if (spot is not null) if (spot is visible on our screen) interact with the spot with action "Net" else // so the spot isnt visible walk to the spot This isn't really pseudo-code, but it serves the purpose. Edited December 13, 2015 by KEVzilla 1 Quote Link to comment Share on other sites More sharing options...
Explv Posted December 13, 2015 Share Posted December 13, 2015 (edited) Hello I'm new around here and I'm trying to learn how to script. I want to give something to the community but I have to learn to code first My problems: I have to have a small fishing net in my inventory or it wont open bank and get one If I have a small fishing net it opens bank then closes then opens and continues like that private enum State { FISH, BANK, WAIT } private State getState() { Entity stall = objects.closest("Fishing spot"); if (inventory.isEmpty() && !inventory.contains("Small fishing net")) return State.BANK; if (stall != null && inventory.contains("Small fishing net")) return State.FISH; return State.WAIT; } @Override public int onLoop() throws InterruptedException { switch (getState()) { case FISH: Entity spot = objects.closest("Fishing spot"); if (spot != null) { inventory.interact("Use", "Small Fishing Net"); if (inventory.isItemSelected() == true) spot.interact(); } break; case BANK: Entity bank = objects.closest("Bank booth"); if (!inventory.contains("Small fishing net")) getBank().withdraw("Small fishing net", 1); if (bank != null) { bank.interact("Bank"); sleep(random(500, 700)); getBank().depositAllExcept("Small fishing net"); } break; case WAIT: sleep(random(500, 700)); break; } return random(200, 300); } Fishing spot is an NPC. Also use the built in bank method: if(!getBank().isOpen()){ getBank().open(); new ConditionalSleep(5000) { @Override public boolean condition() throws InterruptedException { return getBank().isOpen(); } }.sleep(); } else if (!inventory.contains("Small fishing net")){ getBank().withdraw("Small fishing net", 1); } else { getBank().depositAllExcept("Small fishing net"); } Also in your getState() method, State.BANK will not return if you have a full inventory. You only bank when your inventory is empty. if (inventory.isEmpty() && !inventory.contains("Small fishing net")){ return State.BANK; } It should be: if (inventory.isFull() || !inventory.contains("Small fishing net")){ return State.BANK; } As a result of this, your WAIT state is redundant: private enum State { FISH, BANK } private State getState() { if (inventory.isFull() || !inventory.contains("Small fishing net")){ return State.BANK; } return State.FISH; } @Override public int onLoop() throws InterruptedException { switch (getState()) { case FISH: NPC spot = getNpcs().closest("Fishing spot"); if (spot != null) { spot.interact("Net"); new ConditionalSleep(5000) { @Override public boolean condition() throws InterruptedException { return myPlayer().isAnimating(); } }.sleep(); } break; case BANK: if(!getBank().isOpen()){ getBank().open(); new ConditionalSleep(5000) { @Override public boolean condition() throws InterruptedException { return getBank().isOpen(); } }.sleep(); } else if (!inventory.contains("Small fishing net")){ getBank().withdraw("Small fishing net", 1); } else { getBank().depositAllExcept("Small fishing net"); } break; } return random(200, 300); } To prevent spam clicking you may then want to wrap your onLoop code with a condition, where the script does nothing if the player is animating or moving: private enum State { FISH, BANK } private State getState() { if (inventory.isFull() || !inventory.contains("Small fishing net")){ return State.BANK; } return State.FISH; } @Override public int onLoop() throws InterruptedException { if(!myPlayer().isAnimating() && !myPlayer().isMoving()){ switch (getState()) { case FISH: NPC spot = getNpcs().closest("Fishing spot"); if (spot != null) { spot.interact("Net"); new ConditionalSleep(5000) { @Override public boolean condition() throws InterruptedException { return myPlayer().isAnimating(); } }.sleep(); } break; case BANK: if(!getBank().isOpen()){ getBank().open(); new ConditionalSleep(5000) { @Override public boolean condition() throws InterruptedException { return getBank().isOpen(); } }.sleep(); } else if (!inventory.contains("Small fishing net")){ getBank().withdraw("Small fishing net", 1); } else { getBank().depositAllExcept("Small fishing net"); } break; } } return random(200, 300); } You will also need to handle the case where the bank does not contain a fishing net. You may also want to include paths to and from the bank and fishing spot: Area fishingArea = new Area(0, 0, 0, 0); // Define this Area bankArea = new Area(0, 0, 0, 0); // Define this Position[] pathToBank = new Position[]{ }; // Define this Position[] pathToSpot = new Position[]{ }; // Define this private enum State { FISH, BANK, WALK_TO_BANK, WALK_TO_SPOT } private State getState() { if (inventory.isFull() || !inventory.contains("Small fishing net")){ if(bankArea.contains(myPosition())) return State.BANK; return State.WALK_TO_BANK; } if(!fishingArea.contains(myPosition())) return State.WALK_TO_SPOT; return State.FISH; } @Override public int onLoop() throws InterruptedException { if(!myPlayer().isAnimating() && !myPlayer().isMoving()){ switch (getState()) { case FISH: NPC spot = getNpcs().closest("Fishing spot"); if (spot != null) { spot.interact("Net"); new ConditionalSleep(5000) { @Override public boolean condition() throws InterruptedException { return myPlayer().isAnimating(); } }.sleep(); } break; case BANK: if(!getBank().isOpen()){ getBank().open(); new ConditionalSleep(5000) { @Override public boolean condition() throws InterruptedException { return getBank().isOpen(); } }.sleep(); } else if (!inventory.contains("Small fishing net")){ if(getBank().contains("Small fishing net")) getBank().withdraw("Small fishing net", 1); else stop(true); } else { getBank().depositAllExcept("Small fishing net"); } break; case WALK_TO_BANK: getLocalWalker().walkPath(pathToBank); break; case WALK_TO_SPOT: getLocalWalker().walkPath(pathToSpot); break; } } return random(200, 300); } Edited December 13, 2015 by Explv 4 Quote Link to comment Share on other sites More sharing options...
nickeb0i Posted December 13, 2015 Author Share Posted December 13, 2015 Fishing spot is an NPC. Also use the built in bank method: if(!getBank().isOpen()){ getBank().open(); new ConditionalSleep(5000) { @Override public boolean condition() throws InterruptedException { return getBank().isOpen(); } }.sleep(); } Thank you very much, been looking for this Quote Link to comment Share on other sites More sharing options...
Explv Posted December 13, 2015 Share Posted December 13, 2015 (edited) Thank you very much, been looking for this See my updated post, there are more errors Edited December 13, 2015 by Explv 1 Quote Link to comment Share on other sites More sharing options...
nickeb0i Posted December 13, 2015 Author Share Posted December 13, 2015 See my updated post, there are more errors Thank you, how do I fix this case FISH: Entity spot = objects.closest("Fishing spot"); if (spot != null) { inventory.interact("Use", "Small Fishing Net"); if (inventory.isItemSelected() == true) spot.interact(); } so it recognizes fishing spot as a NPC? Quote Link to comment Share on other sites More sharing options...
Explv Posted December 13, 2015 Share Posted December 13, 2015 Thank you, how do I fix this case FISH: Entity spot = objects.closest("Fishing spot"); if (spot != null) { inventory.interact("Use", "Small Fishing Net"); if (inventory.isItemSelected() == true) spot.interact(); } so it recognizes fishing spot as a NPC? See updated post. 1 Quote Link to comment Share on other sites More sharing options...
nickeb0i Posted December 13, 2015 Author Share Posted December 13, 2015 See updated post. Thank you so much Now it works, just gonna figure out how to do a walking path and a GUI. Quote Link to comment Share on other sites More sharing options...
KEVzilla Posted December 13, 2015 Share Posted December 13, 2015 (edited) Thank you so much Now it works, just gonna figure out how to do a walking path and a GUI. There exist builders for GUI's. And for a path, if you need it.. Here's a simple Path Maker: http://dunnkers.github.io/DunkPathMaker/ Edited December 13, 2015 by KEVzilla Quote Link to comment Share on other sites More sharing options...