flipjazz 13 Posted February 21, 2021 Hey, started to learn how to script. Here is a basic Lumbridge anchovies fisher I wrote. Let me know if you have any tips! I saw some scripts do some human like movements like clicking on skills tab or change camera angle. Wondering how important this is and how to do it. import org.dreambot.api.Client; import org.dreambot.api.methods.MethodProvider; import org.dreambot.api.methods.container.impl.Inventory; import org.dreambot.api.methods.container.impl.bank.Bank; import org.dreambot.api.methods.container.impl.bank.BankLocation; import org.dreambot.api.methods.container.impl.bank.BankType; import org.dreambot.api.methods.interactive.NPCs; import org.dreambot.api.methods.interactive.Players; import org.dreambot.api.methods.map.Area; import org.dreambot.api.methods.walking.impl.Walking; import org.dreambot.api.script.AbstractScript; import org.dreambot.api.script.Category; import org.dreambot.api.script.ScriptManifest; import org.dreambot.api.wrappers.interactive.Entity; import org.dreambot.api.wrappers.interactive.NPC; import org.dreambot.api.wrappers.interactive.Player; @ScriptManifest( name = "Script Name", description = "My script description!", author = "Developer Name", version = 1.1, category = Category.UTILITY, image = "") public class TestScript extends AbstractScript { private final Area fishArea = new Area(3243, 3150, 3245, 3153); private final Area lumbridgeBank = BankLocation.LUMBRIDGE.getArea(2); @Override public int onLoop() { MethodProvider.log("On loop is called..."); if (!Inventory.isFull()) { doFish(); } else { goBank(); } return (int) (Math.random() * 500) + 500; } private void goBank() { Player currPlayer = Players.localPlayer(); if (currPlayer.isAnimating()) { MethodProvider.log("Player is moving."); return; } if (!lumbridgeBank.contains(currPlayer)) { MethodProvider.log("Go to bank."); Walking.walk(lumbridgeBank.getRandomTile()); return; } Entity banker = Bank.getClosestBank(BankType.NPC); if (banker != null) { MethodProvider.log("depositing."); Bank.openClosest(); Bank.depositAll(item -> item.getName().equals("Raw shrimps")); return; } } private void doFish() { Player currPlayer = Players.localPlayer(); if (currPlayer.isAnimating()) { MethodProvider.log("Player is moving."); return; } NPC fishingSpot = NPCs.closest("Fishing spot"); if (fishingSpot != null) { MethodProvider.log("Cast Net."); fishingSpot.interact("Net"); return; } if (!fishArea.contains(currPlayer)) { MethodProvider.log("Walk to area."); Walking.walk(fishArea.getRandomTile()); return; } } }
RandyPowers 0 Posted May 30, 2023 Minor programming tip. If you can avoid the bang operator (!) then that is generally a better practice. The reason is the "NOT" adds extra cognitive load. So in your onLoop you do: if (!Inventory.isFull()) { doFish(); } else { goBank(); } but if you switch this it is easier to follow/read if (Inventory.isFull()) { goBank(); } else { doFish(); } You could make your banking more generic by changing: Bank.depositAll(item -> item.getName().equals("Raw shrimps")); to something like: Bank.depositAll(item -> item.getName().contains("Raw")); and then that might be more general and work for anchovies at higher levels. Also, how do you handle when you gain a level? Does it just stop there, or did I miss that?
Recommended Posts
Archived
This topic is now archived and is closed to further replies.