Jump to content

Recommended Posts

Posted (edited)

It's a basic short and simple system. I'm learning the API so please if you have any additional ideas and things to add or guides or anything I can use to better myself and my scripts please PM me or reply here!!

 

Script Features:

  • Camera Movement
  • Picks up full inventory of Bones to bury

Hoping to add more!

 

Jar: https://mega.nz/#!1R11TTjJ!WkjkMtG6EU-c-k0StJGnVVLgA4nIUiGP1xP4tTJwBnM

Raw: https://paste.ee/p/2ZRLP

package main.script;

import java.awt.Graphics2D;

import org.osbot.rs07.api.model.GroundItem;
import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(author = "Booleans Yay", info = "Bone burying made ez pz", name = "Bone Bury", version = 1, logo = "")

public class BoneBury extends Script
{

	@[member='Override']
	public void onStart(){}
	
	private enum BotState
	{
		PICKUP, BURY
	};

	private BotState getState()
	{
		return inventory.isFull() ? BotState.BURY : BotState.PICKUP;
	}
	
	@[member='Override']
	public int onLoop() throws InterruptedException
	{
		switch (getState())
		{
		case PICKUP:
			if (!myPlayer().isAnimating())
			{
				GroundItem bone = groundItems.closest("Bones");
				if (bone != null)
				{
					bone.interact("Take");
					Thread.sleep(random(1500));
				}
			}
			break;
		case BURY:
			camera.moveYaw(random(360));
			while (!inventory.isEmpty())
			{
				Item bones = inventory.getItem("Bones");
				if (bones != null)
				{
					bones.interact("Bury");
					if (myPlayer().isAnimating())
					{
						bones.interact("Bury");
						Thread.sleep(random(200));
					}
				}
			}
			break;
		}
		return random(200, 300);
	}

	@[member='Override']
	public void onExit(){}

	@[member='Override']
	public void onPaint(Graphics2D g){}
}
Edited by booleans yay
  • Like 1
Posted

Everything is fine and dandy, but personally the code style of how you put braces is what saddens me the most, also the state framework you have is the cause for some spaghetti code.

But instead of using just simple sleeps, try looking into the ConditionalSleep class of OSBot.

Just my two cents :xfeels:

Posted (edited)

Will sleep until the inventory is empty or until 5.5 seconds have passed. Look into using this in your scripts as it is a lot better than regular sleeps. 

Also as Vilius stated, the bracket placement is off and makes it harder to read. 


  new ConditionalSleep(5500) {
                        @ Override
                        public boolean condition() throws InterruptedException {
                            return a.getInventory().isEmpty();
                        }
                    }.sleep();


Overall, not bad for your first script

Edited by Juggles
  • Like 1
Posted

This isn't bad for a first script. However, a more efficient way of burying would be:

while(inventory.contains("Bones")) {
 inventory.interact("Bury", "Bones");
}

Also, look into conditionalsleeps.

				if (bone != null) {
					bone.interact("Take");
					Thread.sleep(random(1500));
				}

could be:

long boneCount = inventory.getAmount("Bones");
new ConditionalSleep(5000) {
   @ Override
   public boolean evaluate() {
        return inventory.getAmount("Bones") > boneCount;
   }
}.sleep();

This will sleep until you have more bones, or until 5 seconds have passed. Very useful in situations like this.

 

Also, this is java! Please never use that brace formation!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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