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.

Conditional Combat Style Switcher

Featured Replies

Here's a simple method that will change combat styles using whatever conditions you want, just call the method and pass it an enum of type style corresponding to what you want to switch to:

enum style {
	ATTACK, DEFENSE, STRENGTH;
}
public void combatSwitch(style changeStyle) {
	switch (changeStyle) {
	case ATTACK:
		if (getTabs().open(Tab.ATTACK)) {
			if (getWidgets().get(593, 3).interact()) {
				new ConditionalSleep(3000) {
					@Override
					public boolean condition() throws InterruptedException {
						return getConfigs().get(43) == 0;
					}
				}.sleep();
			}
		}
		break;

	case STRENGTH:
		if (getTabs().open(Tab.ATTACK)) {
			if (getWidgets().get(593, 7).interact()) {
				new ConditionalSleep(3000) {
					@Override
					public boolean condition() throws InterruptedException {
						return getConfigs().get(43) == 1;
					}
				}.sleep();
			}
		}
		break;
		
	case DEFENSE:
		if (getTabs().open(Tab.ATTACK)) {
			if (getWidgets().get(593, 15).interact()) {
				new ConditionalSleep(3000) {
					@Override
					public boolean condition() throws InterruptedException {
						return getConfigs().get(43) == 3;
					}
				}.sleep();
			}
		}
		break;
	}
}

Example usage: 

//checking if strength is a certain level
if (skills.getDynamic(Skill.STRENGTH) < 40 && getConfigs().get(43) != 1) {
	changeStyle = style.STRENGTH;
	combatSwitch(changeStyle);
}

Hope this is of help to somebody!

Kudos to @ProjectPact and @HeyImJamie for the suggestions.

Edited by luciuspragg

Try rewriting to not use static ID's :D 

 

Could also check to make sure the tab is actually opened before looking to interact with a widget since 

getTabs().open

should be a boolean ? 

 

Hope this helps!

Edited by ProjectPact

Looks good, but may I suggest making it a more 'universal' method? I've edited slightly on here so there may be a few errors etc, but this gives you an idea. This way instead of editing the method everytime to edit it to your combat style, you can just select which style you want. You could even make an AttackStyle enum for readability, rather than using ints.

public boolean switchCombatStyle(int combatStyle) {
	int style = getConfigs().get(43);
	if (combatStyle == style) {
		return true;
	}

	switch (combatStyle) {
	case 0:
	RS2Widget attButton = getWidgets().get(593, 3);
	if (attButton != null && getTabs().open(Tab.ATTACK)) {
		if (attButton.interact()) {
			// sleep until style equals desired.
		}
	}
	break;

	case 1:
	RS2Widget strButton = getWidgets().get(593, 7);
	etc
	break;

	case 2:
	break;

	case 3:
	RS2Widget defButton = getWidgets().get(593, 15);
	etc
	break;
	}

	return combatStyle == getConfgs().get(43);
}

 

  • Author

I had originally written it as a standalone one task thing instead of a more universal method so I decided to go ahead and take both of your suggestions into account:

public void combatSwitch(style changeStyle) {
	switch (changeStyle) {
	case ATTACK:
		if (getTabs().open(Tab.ATTACK)) {
			if (getWidgets().get(593, 3).interact()) {
				new ConditionalSleep(3000) {
					@Override
					public boolean condition() throws InterruptedException {
						return getConfigs().get(43) == 0;
					}
				}.sleep();
			}
		}
		break;

	case STRENGTH:
		if (getTabs().open(Tab.ATTACK)) {
			if (getWidgets().get(593, 7).interact()) {
				new ConditionalSleep(3000) {
					@Override
					public boolean condition() throws InterruptedException {
						return getConfigs().get(43) == 1;
					}
				}.sleep();
			}
		}
		break;
		
	case DEFENSE:
		if (getTabs().open(Tab.ATTACK)) {
			if (getWidgets().get(593, 15).interact()) {
				new ConditionalSleep(3000) {
					@Override
					public boolean condition() throws InterruptedException {
						return getConfigs().get(43) == 3;
					}
				}.sleep();
			}
		}
		break;
	}
}

Using:

enum style {
	ATTACK, DEFENSE, STRENGTH;
}

Thanks again for the suggestions!

Edited by luciuspragg

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.