Derogan Posted July 21, 2019 Share Posted July 21, 2019 Hello guys, Trying to script for the first time, and I have encountered a problem. What I mean is bot spam clicks on the onLoop() return time, untill it finally understands that it is in action. @Override public int onLoop() throws InterruptedException { log("Fishing shrimps"); fishing(); return 1_000; // Always acts on on this return when the fishing spot is pressed, presses few times more (even tho the player starts his actions } public void fishing (){ NPC fishingSpot = getNpcs().closest("Fishing spot"); if (fishingSpot != null && fishingSpot.interact("Small Net")) { Sleep.sleepUntil(()-> !myPlayer().isAnimating(), 8_000); //If I understand correctly, the onLoop is suspended for untill the condition is met, or 8 seconds has passed? } } How should I implement such idea: Bot interacts with fishing spot (doesn't click more than one time), is fishing untill it is not animating and Idles. Does it mean I should increase the return integer for like 5 seconds and timeout for 20? How should I implement my idea more logically. And could you please answer my comment that I left in code snippet? Quote Link to comment Share on other sites More sharing options...
HeyImJamie Posted July 21, 2019 Share Posted July 21, 2019 Just add an animation check prior to clicking the spot. if (!not fishing / animating) { fish } Quote Link to comment Share on other sites More sharing options...
Derogan Posted July 21, 2019 Author Share Posted July 21, 2019 Well on the first go, when it is not animating it will enter the fish() method, but then later it quits, and just is moving and fishing and looping. Maybe my lack of logic testing is at fault in my code. What I am trying to achieve is "go to fishing spot" -> "fishing till full" -> "go to bank and back everything" Repeat. I have implemented the walking from bank to fishing spot, but stuck at this fishing activity. @Override public int onLoop() throws InterruptedException { Walker walker = new Walker(); log("Looping again"); log("Walking to fishing spot"); getWalking().walkPath(walker.getToFishingSpot()); 3. Starts Walking and Repeats itself... log("Fishing shrimps"); if (!myPlayer().isAnimating()) { //1. First it is not animating so it matches the condition. fishing(); } log("Exiting"); return 2_000; } public void fishing (){ //2. Enters the Method but quits instatly. NPC fishingSpot = getNpcs().closest("Fishing spot"); if (fishingSpot != null) { fishingSpot.interact("Small Net"); Sleep.sleepUntil(()-> myPlayer().isAnimating(), 16_000); log("Exiting fishing() method."); } } Quote Link to comment Share on other sites More sharing options...
Reminiscence Posted July 29, 2019 Share Posted July 29, 2019 (edited) On 7/21/2019 at 5:18 AM, Derogan said: Well on the first go, when it is not animating it will enter the fish() method, but then later it quits, and just is moving and fishing and looping. Maybe my lack of logic testing is at fault in my code. What I am trying to achieve is "go to fishing spot" -> "fishing till full" -> "go to bank and back everything" Repeat. I have implemented the walking from bank to fishing spot, but stuck at this fishing activity. @Override public int onLoop() throws InterruptedException { Walker walker = new Walker(); log("Looping again"); log("Walking to fishing spot"); getWalking().walkPath(walker.getToFishingSpot()); 3. Starts Walking and Repeats itself... log("Fishing shrimps"); if (!myPlayer().isAnimating()) { //1. First it is not animating so it matches the condition. fishing(); } log("Exiting"); return 2_000; } public void fishing (){ //2. Enters the Method but quits instatly. NPC fishingSpot = getNpcs().closest("Fishing spot"); if (fishingSpot != null) { fishingSpot.interact("Small Net"); Sleep.sleepUntil(()-> myPlayer().isAnimating(), 16_000); log("Exiting fishing() method."); } } 3. you're constantly calling for the script to walk and not checking if it should walk 1. the built-in isAnimating is not ideal for this kind of scenario, use - public boolean isAnimating() throws InterruptedException{ for(int i = 0; i < 5; i++){ if(myPlayer().isAnimating() || players.myPlayer().isMoving()) return true; else sleep(100); } return false; } 2. change your sleep myPlayer().isAnimating to just isAnimating as posted above also, isn't the interaction to catch shrimp "Net"? Edited July 29, 2019 by qmqz Quote Link to comment Share on other sites More sharing options...
Derogan Posted July 29, 2019 Author Share Posted July 29, 2019 Thank you qmqz, hope this helps for other people learning to code. I actually fixed my code, works well now. For other people here is the code for the fishing method: 1. The fishing method will execute when all conditions fail. 2. When player is in fishing area and is not animating will interact with fishing spot. 3. Will enter conditional sleep cycle, will quit sleep cycle untill returns true (bot is animating) or time outs after 5 seconds. @Override public int onLoop() throws InterruptedException { if(lumbyCastle().contains(myPlayer())){ log("Should execute when dead"); getWalking().webWalk(Banks.LUMBRIDGE_UPPER); } if (lumbyBank().contains(myPlayer()) && !essiantalItems()){ log("Is in lumby bank and needs to bank"); reBank(); } if (lumbyBank().contains(myPlayer()) && getBank().isOpen()){ reBank();} if (lumbyBank().contains(myPlayer()) && essiantalItems()){ log("Going to alkharid bank, have all items"); getWalking().webWalk(Banks.AL_KHARID);} if (shouldBank() || myPlayer().isUnderAttack()) { bank(); } else { fishing(); } return random(2_000, 4_000); } //Fishing method private void fishing() { Walker walker = new Walker(); //creates walker object. I'm using this class for List<Position> creation. if (!fishingArea().contains(myPlayer())) { getWalking().walkPath(walker.getToFishingSpot()); } else { NPC fishingSpot = getNpcs().closest("Fishing spot"); if (!myPlayer().isAnimating() && fishingSpot != null) { if (fishingSpot.interact("Small Net")) ; { new ConditionalSleep(5000) { @Override public boolean condition() throws InterruptedException { return myPlayer().isAnimating(); } }.sleep(); } } } } Quote Link to comment Share on other sites More sharing options...
liverare Posted August 3, 2019 Share Posted August 3, 2019 Fishing spots are NPCs which means that when you interact with it, you can check for it: Character<?> c = myPlayer().getInteracting(); if (c != null && c.exists() && c.getName().equals("Fishing spot")) { // we're fishing } else { // we're not fishing } Quote Link to comment Share on other sites More sharing options...