Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Different loops

Featured Replies

Hello, I am working on my first basic script which is fighter. Mainly it is working and doying what I need most - changing combat style according to levels, but the thing is that the script tries to change combat stat every loop. Tried to change sleep time but it either does nothing or messes up whole loop, then the script only attacks new monster when its time to check if combat style is good for level.

 

import com.sun.xml.internal.bind.annotation.OverrideAnnotationOf;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.api.ui.Tab;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

import java.util.Arrays;

@ScriptManifest(name = "First one", version = 1.0, info = "", author = "Kramnik", logo = "")
public class Main extends Script {
    String npcName;

    @Override
    public int onLoop() throws InterruptedException {

        if (npcName == null) {
            if (myPlayer().getInteracting() != null) {
                npcName = myPlayer().getInteracting().getName();
            } else {
                return 500;
            }
        }

        if (!myPlayer().isAnimating() && myPlayer().getInteracting() == null) {
            NPC next = getNpcs().closest(npc -> npc.getName().equals(npcName) && npc.isAttackable() && !npc.isUnderAttack() && npc.getInteracting() == null);

            if (next != null) {
                next.interact("Attack");
                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return myPlayer().getInteracting() != null;
                    }
                }.sleep();

            }
        }



        int str = getSkills().getDynamic(Skill.STRENGTH);
        RS2Widget modeStr = getWidgets().get(593, 7);
        int atk = getSkills().getDynamic(Skill.ATTACK);
        RS2Widget modeAtk = getWidgets().get(593, 3);
        int def = getSkills().getDynamic(Skill.DEFENCE);
        RS2Widget modeDef = getWidgets().get(593, 15);

        int config = getConfigs().get(43);

            if (str < 20) {
                getTabs().open(Tab.ATTACK);
                sleep(1000);
                if (config != 1) {
                    modeStr.interact("Slash");
                    sleep(random(3000, 7000));
                }
                getTabs().open(Tab.INVENTORY);
            } else if (atk < 20) {
                getTabs().open(Tab.ATTACK);
                sleep(1000);
                if (config != 0) {
                    modeAtk.interact("Chop");
                    sleep(random(3000, 7000));
                }
                getTabs().open(Tab.INVENTORY);
            } else if (def < 20) {
                getTabs().open(Tab.ATTACK);
                sleep(1000);
                if (config != 3) {
                    modeDef.interact("Block");
                    sleep(random(3000, 7000));
                }
                getTabs().open(Tab.INVENTORY);
            } else {
                getTabs().open(Tab.ATTACK);
                sleep(1000);
                if (config != 1) {
                    modeStr.interact("Slash");
                    sleep(random(3000, 7000));
                }
                getTabs().open(Tab.INVENTORY);

                return 25000;

            }
            return 500;
        }
    }
}

 

Well, every loop, you are opening the combat tab and then opening the inventory tab, going back and forth between the two. You should set it so only on a level up message (the onMessage function) set a boolean for checking attack style, then setting that variable back to false after everything has been checked

 

Try break your code down into separate routines and use a data structure for your attack styles:

if (defenceLevel < 20) {
	// need to train defence
	if (!isAttackStyleSelected(AttackStyle.DEFENCE)) {
		// need to change attack style
		if (setAttackStyle(AttackStyle.DEFENCE)) {
			// we are now training defence (yay)
		} else {
			// something f'd up?
			throw new InterruptedException("Something wen't wrong!");
		}
	}
}

via

static enum AttackStyle {
	
	ATTACK(0, "Slash"),
	STRENGTH(1, "Chop"),
	DEFENCE(3, "Block");
	
	private final int configValue;
	private final String action;
	
	private AttackStyle(int configValue, String action) {
		this.configValue = configValue;
		this.action = action;
	}
	
	public int getConfigValue() {
		return configValue;
	}
	
	public String getAction() {
		return action;
	}
	
	public static AttackStyle valueOf(int configValue) {
		AttackStyle value = null;
		for (AttackStyle next : values()) {
			if (next.configValue == configValue) {
				value = next;
				break;
			}
		}
		return value;
	}
}
	
private int getAttackStyleConfigValue() {
	return configs.get(43);
}
	
private boolean isAttackStyleSelected(AttackStyle attackStyle) {
	
	int configValue = getAttackStyleConfigValue();
	
	return attackStyle == AttackStyle.valueOf(configValue);
}
	
private boolean setAttackStyle(AttackStyle attackStyle) {
	
	boolean success = false;
	List<RS2Widget> styleButtons;
	ConditionalSleep conditionalSleep;
	
	if (tabs.open(Tab.ATTACK)) {

		styleButtons = widgets.containingActions(593, attackStyle.action);

		if (styleButtons != null && !styleButtons.isEmpty()) {

			if (styleButtons.get(0).interact(attackStyle.action)) {

				conditionalSleep = new ConditionalSleep(2500) { // 2.5 seconds

					@Override
					public boolean condition() throws InterruptedException {

						return getAttackStyleConfigValue() == attackStyle.configValue;
					}
				};

				success = conditionalSleep.sleep();
			}
		}
	}
	
	return success;
}

 

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.