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.

[Snippet] Autocast API

Featured Replies

Currently only supports the normal spellbook.

 

 

Examples

package org.botre.magic;

import org.osbot.rs07.api.ui.MagicSpell;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;

//Script manifest...
public class ExampleScript extends Script {

	private Autocast auto = new Autocast(this);
	
	@Override
	public int onLoop() throws InterruptedException {

		/*
		 * These are radom non-dependant examples.
		 */
		
		// Autocasts the fireblast spell in non-defensive mode
		auto.autocast(AutocastSpell.FIRE_BLAST, false);
		
		// Autocast the wind bolt spell in defensive mode
		auto.autocast(AutocastSpell.WIND_BOLT, true);
		
		// Stop the script immediately if in defensive mode.
		if(auto.isDefensiveMode()) {
			stop();
		}
		
		// Get the difference between the level required to autocast the...
		// spell you are autocasting and your static magic level (a bit arbitrary).
		MagicSpell spell = auto.getAutocastSpell();
		if(spell != null) {
			int difference = Math.abs(spell.getRequiredLevel() - getSkills().getStatic(Skill.MAGIC));
		}
		
		return 500;
	}

}

Autocast

package org.botre.magic;

import java.awt.Point;

import org.botre.tab.TabHotkey;
import org.osbot.rs07.api.ui.MagicSpell;
import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.input.mouse.WidgetDestination;
import org.osbot.rs07.script.MethodProvider;
import org.osbot.rs07.utility.ConditionalLoop;
import org.osbot.rs07.utility.ConditionalSleep;

public class Autocast {

	public static final int AUTOCAST_SPELL_CONFIG = 108;
	public static final int AUTOCAST_MODE_CONFIG = 439; // 0 = regular, 256 = defensive
	public static final Point DEFENSIVE_AUTOCAST_BUTTON_POSITION = new Point(650, 280);
	public static final Point REGULAR_AUTOCAST_BUTTON_POSITION = new Point(651, 333);
	
	private MethodProvider ctx;
	
	public Autocast(MethodProvider ctx) {
		this.ctx = ctx;
	}
	
	public boolean isAutocasting() {
		return ctx.getConfigs().get(AUTOCAST_SPELL_CONFIG) != 0;
	}
	
	public boolean isAutocasting(AutocastSpell auto) {
		return ctx.getConfigs().get(AUTOCAST_SPELL_CONFIG) == auto.getConfigValue();
	}
	
	public boolean isAutocasting(AutocastSpell auto, boolean defensive) {
		return ctx.getConfigs().get(AUTOCAST_SPELL_CONFIG) == auto.getConfigValue() && defensive == isDefensiveMode();
	}
	
	public boolean isRegularMode() {
		return ctx.getConfigs().get(AUTOCAST_MODE_CONFIG) == 0;
	}
	
	public boolean isDefensiveMode() {
		return ctx.getConfigs().get(AUTOCAST_MODE_CONFIG) == 256;
	}
	
	public MagicSpell getAutocastSpell() {
		AutocastSpell auto = AutocastSpell.forConfigValue(ctx.getConfigs().get(AUTOCAST_SPELL_CONFIG));
		if(auto == null) return null;
		return auto.getSpell();
	}
	
	public boolean isAutocastPanelOpen() {
		RS2Widget panel = ctx.getWidgets().get(201, 0);
		return panel != null && panel.isVisible();
	}
	
	@SuppressWarnings("unchecked")
	public boolean openAutocastPanel(boolean defensive) {
		new ConditionalLoop(ctx.getBot(), 10) {
			@Override
			public boolean condition() {
				return !isAutocastPanelOpen();
			};
			@Override
			public int loop() {
				if(TabHotkey.COMBAT.openTab(ctx)) {
					RS2Widget button = ctx.getWidgets().singleFilter(ctx.getWidgets().getAll(), w -> {
						return w != null && w.isVisible() && w.getMessage() != null && w.getMessage().equals("Spell") && w.getPosition().equals(defensive ? DEFENSIVE_AUTOCAST_BUTTON_POSITION : REGULAR_AUTOCAST_BUTTON_POSITION);
					});
					if(button != null) {
						WidgetDestination destination = new WidgetDestination(ctx.getBot(), button);
						if(ctx.getMouse().click(destination)) {
							new ConditionalSleep(2400, 200) {
								@Override
								public boolean condition() throws InterruptedException {
									return !button.isVisible();
								}
							}.sleep();
						}
					}
				}
				return MethodProvider.random(50, 150);
			}
		}.start();
		return isAutocastPanelOpen();
	}

	@SuppressWarnings("unchecked")
	public boolean closeAutocastPanel() {
		new ConditionalLoop(ctx.getBot(), 10) {
			@Override
			public boolean condition() {
				return isAutocastPanelOpen();
			};
			@Override
			public int loop() {
				RS2Widget cancel = ctx.getWidgets().singleFilter(ctx.getWidgets().getAll(), w -> {
					return w != null && w.isVisible() && w.getMessage() != null && w.getMessage().equals("Cancel");
				});
				if(cancel != null) {
					WidgetDestination destination = new WidgetDestination(ctx.getBot(), cancel);
					if(ctx.getMouse().click(destination)) {
						new ConditionalSleep(2400, 200) {
							@Override
							public boolean condition() throws InterruptedException {
								return !cancel.isVisible();
							}
						}.sleep();
					}
				}
				return MethodProvider.random(50, 150);
			}
		}.start();
		return !isAutocastPanelOpen();
	}
	
	public boolean autocast(AutocastSpell spell, boolean defensive) {
		new ConditionalLoop(ctx.getBot(), 10) {
			@Override
			public boolean condition() {
				return spell != null ? !isAutocasting(spell) : isAutocasting();
			};
			@SuppressWarnings("unchecked")
			@Override
			public int loop() {
				if(isAutocastPanelOpen()) {
					if(spell == null) {
						closeAutocastPanel();
					}
					else {
						if(defensive != isDefensiveMode()) {
							closeAutocastPanel();
						}
						else {
							RS2Widget button = ctx.getWidgets().singleFilter(ctx.getWidgets().getAll(), w -> {
								if(w != null && w.isVisible() && w.getInteractActions() != null) {
									String name = spell.getSpell().toString().replace("_", " ");
									for (String action : w.getInteractActions()) if(action != null && action.equalsIgnoreCase(name)) return true;
								}
								return false;
							});
							if(button != null) {
								WidgetDestination destination = new WidgetDestination(ctx.getBot(), button);
								if(ctx.getMouse().click(destination)) {
									new ConditionalSleep(2400, 200) {
										@Override
										public boolean condition() throws InterruptedException {
											return !button.isVisible();
										}
									}.sleep();
								}
							}
						}
					}
				}
				else {
					openAutocastPanel(defensive);
				}
				return MethodProvider.random(50, 150);
			}
			
		}.start();
		return spell != null ? isAutocasting(spell) : !isAutocasting();
	}
	
}

AutocastSpell

 

This is a MagicSpell wrapper storing the config value for a MagicSpell.

package org.botre.magic;

import org.osbot.rs07.api.ui.MagicSpell;
import org.osbot.rs07.api.ui.Spells.NormalSpells;

public enum AutocastSpell {

	WIND_STRIKE(NormalSpells.WIND_STRIKE, 3),
	WATER_STRIKE(NormalSpells.WATER_STRIKE, 5),
	EARTH_STRIKE(NormalSpells.EARTH_STRIKE, 7),
	FIRE_STRIKE(NormalSpells.FIRE_STRIKE, 9),
	WIND_BOLT(NormalSpells.WIND_BOLT, 11),
	WATER_BOLT(NormalSpells.WATER_BOLT, 13),
	EARTH_BOLT(NormalSpells.EARTH_BOLT, 15),
	FIRE_BOLT(NormalSpells.FIRE_BOLT, 17),
	WIND_BLAST(NormalSpells.WIND_BLAST, 19),
	WATER_BLAST(NormalSpells.WATER_BLAST, 21),
	EARTH_BLAST(NormalSpells.EARTH_BLAST, 23),
	FIRE_BLAST(NormalSpells.FIRE_BLAST, 25),
	WIND_WAVE(NormalSpells.WIND_WAVE, 27),
	WATER_WAVE(NormalSpells.WATER_WAVE, 29),
	EARTH_WAVE(NormalSpells.EARTH_WAVE, 31),
	FIRE_WAVE(NormalSpells.FIRE_WAVE, 33);
	
	private MagicSpell spell;
	private int configValue;
	
	private AutocastSpell(MagicSpell spell, int configValue) {
		this.spell = spell;
		this.configValue = configValue;
	}
	
	public MagicSpell getSpell() {
		return spell;
	}
	
	public int getConfigValue() {
		return configValue;
	}
	
	public static AutocastSpell forSpell(MagicSpell spell) {
		for (AutocastSpell a : values()) {
			if(a.spell == spell) return a;
		}
		return null;
	}
	
	public static AutocastSpell forConfigValue(int configValue) {
		for (AutocastSpell a : values()) {
			if(a.configValue == configValue) return a;
		}
		return null;
	}
	
}

Good code, but kinda pointless I just use Omni API. Bobrocket the guy that made OmniAPI is a genius, and that thing covers all worthwhile things.

Edited by MegaManAlpha

  • Author

Good code, but kinda pointless I just use Omni API. Bobrocket the guy that made OmniAPI is a genius, and that thing covers all worthwhile things.

 

His library is an broad generic framework, this is a very specific set of methods just for autocasting :p Apples and oranges I guess.

Good code, but kinda pointless I just use Omni API. Bobrocket the guy that made OmniAPI is a genius, and that thing covers all worthwhile things.

 

obviously has no idea who botre is

 

anyway looks nice bud

  • 2 months later...

god bless for this snippet.

 

Thanks daddy

  • 10 months later...
  • 4 weeks later...

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.