Jump to content

[SNIPPET] Attack Option Switcher [SNIPPET]


Recommended Posts

Posted (edited)

The Code:

import org.osbot.rs07.api.ui.Tab;
import org.osbot.rs07.script.MethodProvider;
import org.osbot.rs07.script.Script;

public class CombatSwitcher {
	private Script si;

	private final int parent = 261;
	
	private final int topColumn = 1;
	
	private final int playerSettingBox = 60;
	private final int npcSettingBox = 61;
	
	private final int playerOptionBox = 76;
	private final int npcOptionBox = 77;

	private final int openButton = 7;
	
	private final int mainBox = 4;
	
	private final static int depends = 1;
	private final static int rightClick = 2;
	private final static int leftClick = 3;
	private final static int hidden = 4;
	
	public CombatSwitcher(Script si) {
		this.si = si;
	}

	public static enum Setting {
		DEPENDS_ON_COMBAT_LEVELS("Depends on combat levels", depends), 
		LEFT_CLICK_WHERE_AVAILABLE("Left-click where available", leftClick), 
		ALWAYS_RIGHT_CLICK("Always right-click", rightClick), 
		HIDDEN("Hidden", hidden);

		private final String s;
		private final int id;
		
		Setting(String s, int id) {
			this.s = s;
			this.id = id;
		}
		
		public String toString() {
			return s;
		}
		
		public int getId() {
			return id;
		}
		
		public static Setting toSetting(String s1) {
			for(Setting s: Setting.values()) {
				if(s.toString().equals(s1)) {
					return s;
				}
			}
			return null;
		}
	}

	public boolean isOpen() {
		return si.widgets.getWidgetContainingText("Player 'Attack' Options") != null;
	}

	public boolean open() throws InterruptedException {
		if(isOpen()) {
			return true;
		}
		if (si.tabs.getOpen() != Tab.SETTINGS) {
			if (si.tabs.open(Tab.SETTINGS)) {
				Script.sleep(MethodProvider.random(500, 1000));
				if(!isOpen())  {
					return si.widgets.get(parent, topColumn, openButton).interact();
				}
				return true;
			}
		}
		return si.widgets.get(parent, topColumn, openButton).interact();
	}

	public boolean close() {
		return si.tabs.open(Tab.INVENTORY);
	}
	
	public boolean setPlayerOption(Setting s) throws InterruptedException {
		if (isOpen() || open()) {
			if (s == getCurrentPlayerOption()) 
				return true;
			if(si.widgets.get(parent, playerSettingBox, mainBox).interact() && s != null) {
				Script.sleep(MethodProvider.random(500, 800));
				return si.widgets.get(parent, playerOptionBox, s.getId()).interact();
			}
		}
		return false;
	}

	public boolean setNPCOption(Setting s) throws InterruptedException {
		if (isOpen() || open()) {
			if (s == getCurrentNPCOption()) {
				return true;
			}
			if(si.widgets.get(parent, npcSettingBox, mainBox).interact() && s != null) {
				Script.sleep(MethodProvider.random(500, 800));
				return si.widgets.get(parent, npcOptionBox, s.getId()).interact();
			}
		}
		return false;
	}

	public Setting getCurrentNPCOption() {
		if (isOpen()) {
			return Setting.toSetting(si.widgets.get(parent, npcSettingBox, mainBox).getMessage());
		}
		return null;
	}
	
	public Setting getCurrentPlayerOption() {
		if (isOpen()) {
			return Setting.toSetting(si.widgets.get(parent, playerSettingBox, mainBox).getMessage());
		}
		return null;
	}
}

 

What It Does:

Changes the NPC / Player attack options. Occasionally, the client was misclicking for me and attacking characters that it shouldn't have (both NPCs and Players), so I ended up needing this. Was thinking someone else might need this as well. Should work perfectly. Also always looking for constructive criticism if you want to give some smile.png

 

 

Usage:

public class Main extends Script {
	private CombatSwitcher cs;

    @ Override
    public void onStart() {
    	cs = new CombatSwitcher(this);
    }

    @ Override
    public int onLoop() {
    	cs.setNPCOption(CombatSwitcher.Setting.ALWAYS_RIGHT_CLICK);
        return 100;
    }
}
Edited by Imateamcape

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