Jump to content

Why doesn't this script work?


MySQLi

Recommended Posts

Hey guys, here are my problems with this script, then I'll post the code.

  • When at the Yew Tree in Varrock, even though I have a ConditionalSleep, it still spam clicks the tree
  • Once the tree is cut down once, it won't click on the tree once it respawns
  • Once the inventory is full, it won't walk to the bank, If I walk the player to the bank, it won't open the bank, deposit the logs.
Spoiler

				
			import org.osbot.rs07.api.Bank;
		import org.osbot.rs07.api.Inventory;
		import org.osbot.rs07.api.map.Position;
		import org.osbot.rs07.api.map.constants.Banks;
		import org.osbot.rs07.api.model.RS2Object;
		import org.osbot.rs07.api.util.ItemContainer;
		import org.osbot.rs07.script.Script;				
			import org.osbot.rs07.script.ScriptManifest;
		import org.osbot.rs07.utility.ConditionalSleep;				
			import java.awt.*;				
			@ScriptManifest(author = "MySQLi", info = "Varrock Yew Cutter / Banker", name = "SqlYewCutter", version = 1.0, logo = "")				
			public class Main extends Script {				
			    
		    
		    @Override
		    public void onStart() {
		        log("Enjoy cutting yews!");
		        //Code here will execute before the loop is started
		    }				
			    public int onLoop() throws InterruptedException{
		        if(canCutTrees()){
		            cut();
		        }
		        else{
		            bank();
		        }
		    
		        
		        return random (150,200); //The amount of time in milliseconds before the loop starts over
		    }				
			
		    @Override
		    public void onExit() {
		        log("Thank you for supporting my script!");
		        //Code here will execute after the script ends
		    }				
			    private void bank() throws InterruptedException{
		        if(inventory.isFull() && !Banks.VARROCK_EAST.contains(myPosition())){
		            getWalking().webWalk(Banks.VARROCK_EAST);
		        }
		        else if (!getBank().isOpen()){
		            getBank().open();
		            getBank().depositAll("Yew Logs");
		        }
		        else{
		            getWalking().walk(new Position(3247,3472,0));
		        }
		    }
		  
		    
		    private void cut(){				
			            RS2Object yew = getObjects().closest("Yew");
		            if(yew != null && yew.interact("Chop down"));
		            new ConditionalSleep(5000){
		                public boolean condition(){
		                    return myPlayer().isAnimating() || !yew.exists();
		                }
		            }.sleep();
		    }				
			    public boolean canCutTrees(){
		        return myPlayer().isOnScreen();
		        
		    }
		    
		    
		   
		    @Override
		    public void onPaint(Graphics2D g) {
		        //This is where you will put your code for paint(s)
		    }				
			}				
			

 

Link to comment
Share on other sites

42 minutes ago, MySQLi said:

Hey guys, here are my problems with this script, then I'll post the code.

  • When at the Yew Tree in Varrock, even though I have a ConditionalSleep, it still spam clicks the tree
  • Once the tree is cut down once, it won't click on the tree once it respawns
  • Once the inventory is full, it won't walk to the bank, If I walk the player to the bank, it won't open the bank, deposit the logs.
  Hide contents

 



				
			import org.osbot.rs07.api.Bank;
		import org.osbot.rs07.api.Inventory;
		import org.osbot.rs07.api.map.Position;
		import org.osbot.rs07.api.map.constants.Banks;
		import org.osbot.rs07.api.model.RS2Object;
		import org.osbot.rs07.api.util.ItemContainer;
		import org.osbot.rs07.script.Script;				
			import org.osbot.rs07.script.ScriptManifest;
		import org.osbot.rs07.utility.ConditionalSleep;				
			import java.awt.*;				
			@ScriptManifest(author = "MySQLi", info = "Varrock Yew Cutter / Banker", name = "SqlYewCutter", version = 1.0, logo = "")				
			public class Main extends Script {				
			    
		    
		    @Override
		    public void onStart() {
		        log("Enjoy cutting yews!");
		        //Code here will execute before the loop is started
		    }				
			    public int onLoop() throws InterruptedException{
		        if(canCutTrees()){
		            cut();
		        }
		        else{
		            bank();
		        }
		    
		        
		        return random (150,200); //The amount of time in milliseconds before the loop starts over
		    }				
			
		    @Override
		    public void onExit() {
		        log("Thank you for supporting my script!");
		        //Code here will execute after the script ends
		    }				
			    private void bank() throws InterruptedException{
		        if(inventory.isFull() && !Banks.VARROCK_EAST.contains(myPosition())){
		            getWalking().webWalk(Banks.VARROCK_EAST);
		        }
		        else if (!getBank().isOpen()){
		            getBank().open();
		            getBank().depositAll("Yew Logs");
		        }
		        else{
		            getWalking().walk(new Position(3247,3472,0));
		        }
		    }
		  
		    
		    private void cut(){				
			            RS2Object yew = getObjects().closest("Yew");
		            if(yew != null && yew.interact("Chop down"));
		            new ConditionalSleep(5000){
		                public boolean condition(){
		                    return myPlayer().isAnimating() || !yew.exists();
		                }
		            }.sleep();
		    }				
			    public boolean canCutTrees(){
		        return myPlayer().isOnScreen();
		        
		    }
		    
		    
		   
		    @Override
		    public void onPaint(Graphics2D g) {
		        //This is where you will put your code for paint(s)
		    }				
			}				
			

 

 

First of all the boolean canCutTree is wrong, it is just checking if player is on screen, while it should check if player is not animating and yew is not null and inventory is not full and check equipment for anyitem that contains "axe" or inventory has anything that contains "axe".

cut() condition sleep only sleeps untill animating, add another sleep to sleep untill is not animating or inventory is full.

 

private void cut() {
		RS2Object yew = getObjects().closest("Yew");
		if (yew != null && yew.interact("Chop down")) {
			new ConditionalSleep(5000) {
				public boolean condition() {
					return myPlayer().isAnimating() || !yew.exists();
				}
			}.sleep();
			new ConditionalSleep(5000) {
				public boolean condition() {
					return !myPlayer().isAnimating() || !yew.exists() || inventory.isFull();
				}
			}.sleep();
		}
	}
public boolean canCutTrees(){
	return YEWAREA.contains(myPlayer())
				&& (getInventory().contains(f -> f.getName().contains("axe"))
						|| getmp().getEquipment().contains(f -> f.getName().contains("axe")))
				&& !myPlayer().isAnimating() && !myPlayer().isMoving() && !getInventory().isFull();
}

The YEWAREA is where u define the area for the Yews. you can change it.

 

One more tip, try to format the code in your IDE for us to be able to help more.

Edited by progamerz
Link to comment
Share on other sites

2 hours ago, progamerz said:

tEquipm

 

1 hour ago, Juggles said:

So much wrong with this. Don't even know where to start.
Just leech off my code

https://pastebin.com/wFGP0F29
Thanks that'll be 2m 

I appreciate that, I'm having a lot of trouble learning how to write scripts, there so many different guides, and things to learn, I'm having trouble where to start, and every guide is different with how people do things so I'm getting mixed up. I appreciate everyone's help though.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...