July 28, 20178 yr Hey, so I'm pretty new to this, and I have a question.. I'm currently writing a fishing script for fun/learning purposes, and I stumbled upon the fact that my fish() method stops running after achieving a level or when the fishing spot disappears. I know that the script executioner gets called depending on the ms you specify in the onLoop method, and I've also tried adding a while loop, but neither of these methods helped me fix the problem. private void fish() { if (!lumbyFishing.contains(myPosition())) { getWalking().webWalk(lumbyFishing); } Entity fishingSpot = getNpcs().closest("Fishing spot"); while (fishingSpot.exists()) { if (fishingSpot != null && fishingSpot.interact("Net")) { new Sleep(() -> myPlayer().isAnimating() || !fishingSpot.exists(), 5000).sleep(); } } } SO my question to you guys was: What is wrong with my code? Thanks in advance. Edited July 29, 20178 yr by Jake Slang
July 28, 20178 yr If you level up, or the spot moves, you'll no longer be animating. Add in an animation check somewhere to determine if you're fishing or not. Then just loop your fishing method.
July 28, 20178 yr new Sleep(() -> myPlayer().isAnimating() || !fishingSpot.exists(), 5000).sleep(); this should be && no?
July 28, 20178 yr 1 hour ago, Jake Slang said: Hey, so I'm pretty new to this, and I have a question.. I'm currently writing a fishing script for fun/learning purposes, and I stumbled upon the fact that my fish() method stops running after achieving a level or when the fishing spot disappears. I know that the script executioner gets called depending on the ms you specify in the onLoop method, and I've also tried adding a while loop, but neither of these methods helped me fix the problem. private void fish() { if (!lumbyFishing.contains(myPosition())) { getWalking().webWalk(lumbyFishing); } Entity fishingSpot = getNpcs().closest("Fishing spot"); while (fishingSpot.exists()) { if (fishingSpot != null && fishingSpot.interact("Net")) { new Sleep(() -> myPlayer().isAnimating() || !fishingSpot.exists(), 5000).sleep(); } } } SO my question to you guys was: What is wrong with my code? Thanks in advance. I don't know anything about coding a script but From website & small java programming I'd use a loop to loop the whole code so that it constantly runs.
July 28, 20178 yr Simple way to check for this if (!myPlayer.isAnimating) { if (fish!=null) { fish.interact("Fish"); sleepConditionUntil(myPlayer.isAnimating); } } else { //do nothing }
July 28, 20178 yr if (canFish()){ fish(); } private boolean canFish(){ return !myPlayer.isAnimating && !getInventory.isFull } private void fish(){ if (fishingSpot != null){ if (fishingSpot.interact("w/e")){ // Sleep until animating } } } Something like that, you should get the idea
July 29, 20178 yr Author Thank each one of you for all your efforts. I'll read through after breakfast Edited July 29, 20178 yr by Jake Slang
July 29, 20178 yr 9 hours ago, Juggles said: Simple way to check for this if (!myPlayer.isAnimating) { if (fish!=null) { fish.interact("Fish"); sleepConditionUntil(myPlayer.isAnimating); } } else { //do nothing } Someone give this guy Scripter II!
July 29, 20178 yr Author Ok, so I don't think my code was necessarily wrong, but I did made some adjustments conform your advice: private final Area lumbyFishing = new Area(3247, 3156, 3244, 3154); public final int onLoop() throws InterruptedException { if (canFishShrimps()) { fish(); } else { bank(); } return random(150, 200); } private void fish() { if (!lumbyFishing.contains(myPosition())) { getWalking().webWalk(lumbyFishing); } Entity fishingSpot = getNpcs().closest("Fishing spot"); if (fishingSpot != null) { if (fishingSpot.interact("Net")) { sleepConditional(); } } } private void sleepConditional() { Entity fishingSpot = getNpcs().closest("Fishing spot"); if (fishingSpot != null && fishingSpot.interact("Net")) { Sleep.sleepUntil(() -> myPlayer().isAnimating() || !fishingSpot.exists(), 5000); log(Sleep.sleepUntil(() -> myPlayer().isAnimating() || !fishingSpot.exists(), 5000)); } } private void bank() { // } private boolean canFishShrimps() { return !myPlayer().isAnimating() && !getInventory().isFull(); } So I think the problem was that I also had to export my Sleep class (which was automatically created on reference) to my Script folder. PS: And I know I can refactor this logic a lot more; I'm on it! :) Edited July 29, 20178 yr by Jake Slang
July 29, 20178 yr 16 hours ago, Juggles said: Simple way to check for this if (!myPlayer.isAnimating) { if (fish!=null) { fish.interact("Fish"); sleepConditionUntil(myPlayer.isAnimating); } } else { //do nothing } LOL
July 29, 20178 yr The main issue was the while(fishingSpot.exists()) A simple fix (Removing the while loop is best though) would be to change the while to something like while(fishingSpot.exists() && myPlayer().getAnimation() != -1)
July 29, 20178 yr 21 hours ago, YoHoJo said: If you level up, or the spot moves, you'll no longer be animating. Add in an animation check somewhere to determine if you're fishing or not. Then just loop your fishing method. When the spot moves, your player still animates for a decent 5 seconds afterwards. You need to check if the object still exists if you want maximum efficiency