klongrich 0 Posted October 29, 2019 package Tester.main; import org.dreambot.api.methods.filter.Filter; import org.dreambot.api.script.AbstractScript; import org.dreambot.api.script.Category; import org.dreambot.api.script.ScriptManifest; import org.dreambot.api.methods.map.Area; import org.dreambot.api.wrappers.interactive.NPC; import org.dreambot.api.wrappers.items.GroundItem; @ScriptManifest(category = Category.MISC, name="HelloWorldTest", author="klongrich", version=1) public class main extends AbstractScript { private Area lumbridgeBank = new Area(3210, 3218, 3207, 3220, 2); private Area lumbridgeCows = new Area(3243, 3294, 3263, 3283); private static final Filter<NPC> CowFilter = new Filter<NPC>() { @Override public boolean match(NPC npc) { if (npc == null) { return false; } return npc.getName().equals("Cow") && !npc.isHealthBarVisible(); } }; private void bank() { getDepositBox().open(); getDepositBox().depositAllItems(); } @Override public int onLoop() { GroundItem Cowhide = getGroundItems().closest("Cowhide"); if (getLocalPlayer().isInCombat()) { //Do nothing } else if (getInventory().isFull()) { getWalking().walk(lumbridgeBank.getRandomTile()); bank(); log("Seeing full Inventory"); } else if (Cowhide != null && Cowhide.distance(getLocalPlayer()) < 3) { if (!getLocalPlayer().isAnimating()) { if (Cowhide.interact("Take")) { sleepUntil(() -> !Cowhide.exists(), 15000); } } } else if (lumbridgeCows.contains(getLocalPlayer())) { NPC cow = getNpcs().closest(CowFilter); if (cow != null) { cow.interact("Attack"); } } else { getWalking().walk(lumbridgeCows.getRandomTile()); } log("Running"); return 1000; } }
ThatGuyLo 1 Posted October 30, 2019 I see this is your first script, so I'd like to give some pointers for a beginner. First, I highly recommend dividing your process into states. For example, you might have an enum called State which contains Bank, Collect, Attack, and maybe Walk. Then have a function simply called GetState() which returns the state you want to be in based on the logic you have above. So GetState would run the conditionals like: State playerState; if (getInventory().isFull()) { playerState = State::Bank; } //(I mainly code in C++ so forgive me if im mixing languages, but the idea is here) elseif (!lumbridgeCows.contains(getLocalPlayer().getTile()) { playerState = State::Walk; } and so on. Then have functions that are run based on which state you are in using a switch or conditional chain: switch(GetState()) case State::Bank: Bank(); Another tip would be to (personal preference) log your states/functions (that you find necessary) at the beginning of the function, rather than the end. The reason I say this is because in your code: getWalking().walk(lumbridgeBank.getRandomTile()); bank(); log("Seeing full Inventory"); You are going to see "Seeing full inventory" after you watch your bot walk to the bank, which may be confusing (and useless) to know afterwards. Last tip (for beginners): rather than setting hard sleep times (return 1000;//or sleep(1000); Use Calculations.random(int a, int b) where a is the minimum sleep time desired, and b is the max. This helps to ensure that your bot isn't always acting exactly at the same times on the clock, helping lower ban rate.
ThatGuyLo 1 Posted October 30, 2019 Oh, also, while this isn't always required, I sometimes like verifying that my bot didn't do something crazy somehow before trying to do things like your function bank(); I would have written: Bank() { if (lumbridgeBank.contains(getLocalPlayer.getTile()) { //NOW banking is done } else { WalkToBank(); //or something of the sort } }
klongrich 0 Author Posted October 31, 2019 Ahh I see if you could see States it might be a little easier to see what's going on and Error checking here and there probably wouldn't be the worst idea. Thanks for the feedback!
camelCase 323 Posted February 16, 2022 On 2/12/2022 at 1:46 PM, Finawe said: how do i download? this script is 3 years old and would not work now.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.