Floglet Posted June 16, 2019 Share Posted June 16, 2019 (edited) Hello all, I'm just putting together a little cow killer/hide pick up/bank script to run to earn a little GP on new accounts... At the moment I'm having a little trouble with my logic, the script works, but things do not work as they should! - Here are the issues: Some of my logic is a bit around the wrong way, I think, which causes weird waits at points My for loop seems to loop through extemely fast, even with the conditionalSleep, my goal of this for loop is to pick up a random amount of hides after killed the cow (picking up other peoples hides). It only ever prints "Picking up item.. 0 of X" never 1 of X for example. I have made the CowPenArea, how do I walk to the centre (or a random point near centre for antiban) of this location? At the moment once it reaches the outer part of the area it stops walking, causing it to get stuck outside the fence if it is closed. If there are no hides to pick up, it gets stuck in the conditional sleep of the for loop, which is weird, because it doesnt otherwise. It keeps wanting to do both pick up hides and attack at the same time, (it clicks a cow then quickly clicks a hide on the ground, causing cows to be attacking the character while its walking to pick up hides) i've tried using !is.moving etc to try and make the script wait until its moved before continuing... My banking was working perfectly fine, but now it crashes or keeps checking if inv is full, probably a logic issue. This causes the whole OSBOT to seize up. I've commented out a check if inv empty then walk to cowpen, but then I realised I should do this elsewhere, otherwise if the script is not in the cow pen when it starts it will seize up, where would be an appropriate place to do this? package core; import java.awt.Graphics2D; import org.osbot.rs07.api.model.GroundItem; import org.osbot.rs07.api.map.Position; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.api.Walking; import org.osbot.rs07.api.map.constants.Banks; import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.utility.ConditionalSleep; @ScriptManifest(author = "You", info = "Hide Picker", name = "Hide PickerUpperer", version = 0, logo = "") public class Main extends Script { Area CowPen = new Area(3239, 3297, 3265, 3260); @Override public void onStart() { log("Let's get started!"); } @Override public int onLoop() throws InterruptedException { if (!myPlayer().isMoving() && !myPlayer().isAnimating()) { AttackCow(); PickUpHides(); // when not moving it tries to both PICK UP hides and also ATTACk. //need to force to be stuck in PICKUPHIDES after KILLED cow for loop amount, will fix issue. } if (getInventory().isFull()){ // PUT THIS INSIDE PickUpHides? goToBank(); //died at go to bank? log("Detected full Inv, going to bank!"); } return random(200, 777); } @Override public void onExit() { log("Thanks for running COWLOOTER dont get B& asshole!"); } public void AttackCow() throws InterruptedException { NPC cow = getNpcs().closest("Cow"); if (!myPlayer().isMoving() && !myPlayer().isUnderAttack() && !cow.isUnderAttack() && cow.getHealthPercent()>0) { cow.interact("Attack"); log("Attacking cow"); new ConditionalSleep(15000) { @ Override public boolean condition() throws InterruptedException { return !myPlayer().isUnderAttack(); } }.sleep(); } } public void PickUpHides() throws InterruptedException { GroundItem groundItem; Position itemPosition; int PickAmt = random(1,20); //how many hides to pick up before attacking another cow int PickedAmt; for (PickedAmt = 0; PickedAmt<PickAmt; PickedAmt++) { //loop with random (1-12) of amount of times to repeat the shit groundItem = getGroundItems().closest(e -> e != null && e.getName().contains("Cowhide")); if(groundItem != null && !myPlayer().isMoving() && CowPen.contains(groundItem) && !myPlayer().isUnderAttack()) { //&& !myPlayer().isAnimating() itemPosition = groundItem.getPosition(); groundItem.interact("Take"); log("Picking up item.. " + PickedAmt + "of: " + PickAmt); new ConditionalSleep(random(10000,20000)) { @ Override public boolean condition() throws InterruptedException { return myPlayer().isMoving(); } }.sleep(); //GETS STUCK LOOKING FOR HIDES TO PICK UP!!!!!!!!! } } } public void goToBank() throws InterruptedException { log("Inside goToBank module"); if(!Banks.LUMBRIDGE_UPPER.contains(myPosition())) getWalking().webWalk(Banks.LUMBRIDGE_UPPER); else if(!getBank().isOpen()) getBank().open(); //spam clicks open bank else { log("depositing all items"); getBank().depositAll(); //if (getInventory().isEmpty()) { walking.webWalk(CowPen); log("walking back to cowPen"); //GOT STUCK OUTSIDE AREA, GATE CLOSED. CHANGE TO WALK INTO CENTER OF AREA! } } } Thanks all for the help, I'm really enjoying learning programming and making RS bots at the same time! Its making me motivated to learn new things haha. ALSO: WebWalk consistently misclicks the nothern stairs at lumbridge, walking around the outside, not that much of an issue (and not one I can fix without making my own walk path) Edited June 16, 2019 by Floglet Quote Link to comment Share on other sites More sharing options...
dreameo Posted June 16, 2019 Share Posted June 16, 2019 I didn't look through much of this but here are important things that can fix a lot of your problems. 1. You're using conditional sleeps wrong. RS2Object object; if(object.interact("something")){ new ConditionalSleep(5000) { @Override public boolean condition() throws InterruptedException { return myPlayer().isAnimating(); } }.sleep(); } ".interact()" is a boolean method. It returns true or false depending on the outcome of the interaction. If the interaction is a success, it returns true otherwise it returns false. In this example, if we do interact, we wait up to 5 seconds (which halts all execution) OR continue execution once the condition of "my player is animating becomes true". 2. Logic is flawed a bit. For example, your conditional sleep regarding the "picking up" interaction is very flawed. The execution of code should only continue until it reaches the timeout or until the item is actually picked up. "Actually picked up" means that we have one more copy in our inventory then we did before when we hit "take". GroundItem object; if(object.interact("take")){ int currentInventoryCnt = getTotalCount(object.getName()); new ConditionalSleep(5000) { @Override public boolean condition() throws InterruptedException { return currentInventoryCnt != getTotalCount(object.getName()); } }.sleep(); } So here's an example. ("getTotalCount" is a made up method which would return the total count of an item within inventory) 1 Quote Link to comment Share on other sites More sharing options...
progamerz Posted June 16, 2019 Share Posted June 16, 2019 You can use getCombat().isFighting() to check if we are fighting if not, loot Your conditional sleep after fighting would most of the time get skipped new ConditionalSleep(15000) { @ Override public boolean condition() throws InterruptedException { return !myPlayer().isUnderAttack(); } }.sleep(); because the cow might be far so after interacting it will sleep until we are not under attack which we will already be not under attack, the best bet you can do is sleep until you are in combat, and then sleep until you are not under combat And in your case i would prefer using if/else so that it won't do multiple tasks in the same loop i.e. loot and attack. 1 Quote Link to comment Share on other sites More sharing options...