Jump to content

Super Basic Smithing script


Chikan

Recommended Posts

Made my first script today, and by first I mean first OSBot script. I struggled through the API, so be gentle: I'm learning.

 

import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.api.map.constants.Banks;
import org.osbot.rs07.api.ui.RS2Widget;

@ScriptManifest(author = "Chikan", name = "Dagger Maker 3.0", info = "Dagger Maker 3.0", version = 0.3, logo = "")
public final class Main extends Script  
{
	public enum State {
		USEANVIL, SMITH, BANK, WAIT		
	}
	
	private State getState()
	{
		RS2Widget smithingInterface = getWidgets().get(312, 2, 2);
		if(smithingInterface == null&&canSmithBars())
			return State.USEANVIL;
		if (smithingInterface != null&&canSmithBars())
            return State.SMITH;
		if (!getInventory().contains("Bronze Bar"))
		
			return State.BANK;
		return State.WAIT;
	}
	
    @Override
    public final int onLoop() throws InterruptedException 
    {
       switch (getState()) {
    	   case USEANVIL:
    		   getObjects().closest("anvil").interact("Smith");
    		   sleep(random(3000, 4000));
    		   log("starting state: USEANVIL");
    		   break;
    	   case SMITH:
    		   log("starting state: SMITH");
    		   getWidgets().get(312, 2, 2).interact("Smith 10");
    		   sleep(random(12500, 14500));
    		   break;
    	   case BANK:
    		   log("starting state: BANK");
    		   bankHandler();
    	   case WAIT:
   			log("starting state: Wait");
   			sleep(random(250, 700));
   			break;
       }
    	return random(200, 400) ;
    }
       
    //space for making variables
    //inventory check
    private boolean canSmithBars() {
    	return getInventory().contains("Bronze Bar");
    }
    
     //anvil entity
    public boolean useAnvil() {
    	return getObjects().closest("anvil").interact("Smith");
    }
    
    //bank handler (if statement loop)
    private void bankHandler() throws InterruptedException 
    {
    	if (!Banks.VARROCK_WEST .contains(myPosition())) {
            getWalking().webWalk(Banks.VARROCK_WEST );
        } else if (!getBank().isOpen()) {
            getBank().open();
        } else if (!getInventory().isEmptyExcept("Bronze Bar", "Hammer")) {
            getBank().depositAll();
        } else if (getBank().contains("Bronze Bar")) {
            getBank().withdrawAll("Bronze Bar");
        } else {
            stop(true);
        }
    } 	
}

 

Link to comment
Share on other sites

Nice work! 

Just a few tips -

  • Firstly, be sure to check out Conditional Sleeps https://osbot.org/api/org/osbot/rs07/utility/ConditionalSleep.html (Note that the class is abstract so you will have to provide your own implementation, anonymous or otherwise). They will help cut slack time in your script, and make your script suitable for SDN application!
  • Secondly, perhaps you have considered not using static widget child ids? I noticed that when you're checking for widgets in your 'getState()' method, you check for child and grandchild ids; since these values often change, it is advised to use other filters like perhaps checking for the presence of text. Since the parent id rarely (if ever) changes when new content is added, you should be able to refine your filters by providing the root id as a parameter to the Widgets#containingText method. Again, you will probably need to do this for SDN submission.
  • Finally, maybe add a paint? (:

Keep it up

Apa

Link to comment
Share on other sites

1 minute ago, Deathimminent said:

Isn't your bank handler going to deposit your hammer as well when you deposit all? I don't see where you withdraw your hammer again to be able to smith.

Yeah, you're right. I just fixed it I think, but I got lazy and just added bank fillers so I didn't make a difference when I was testing.

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...