Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package scripts;
- import java.awt.Color;
- import java.awt.Graphics2D;
- import java.text.NumberFormat;
- import java.util.Locale;
- import org.osbot.rs07.api.model.Entity;
- import org.osbot.rs07.api.model.Item;
- import org.osbot.rs07.api.ui.Option;
- import org.osbot.rs07.api.ui.Skill;
- import org.osbot.rs07.api.ui.Spells;
- import org.osbot.rs07.api.ui.Tab;
- import org.osbot.rs07.script.Script;
- import org.osbot.rs07.script.ScriptManifest;
- @ScriptManifest(name = "Stun Alcher", author = "MegaManAlpha", logo = "", version = 0.0, info = "")
- public class StunAlcher extends Script {
- String targetEnemyName = "Monk of Zamorak";
- long scriptStartTime = 0;
- int startMagicLevel = 0;
- int startMagicExp = 0;
- int currentMagicExp = 0;
- int soulRunesStartAmount = 0;
- int soulRunesCurrentAmount = 0;
- int soulRunesUsed = 0;
- int natureRunesStartAmount = 0;
- int natureRunesCurrentAmount = 0;
- int natureRunesUsed = 0;
- boolean started = false;
- @Override
- public void onStart() throws InterruptedException {
- antiBan.unregisterAllBehaviors();
- scriptStartTime = System.currentTimeMillis();
- startMagicExp = skills.getExperience(Skill.MAGIC);
- startMagicLevel = skills.getStatic(Skill.MAGIC);
- soulRunesStartAmount = getNumberOfSoulRunes();
- natureRunesStartAmount = getNumberOfNatureRunes();
- log("MegaManAlpha's Stun-Alcher script has now started!");
- log("You will be splashing: " + targetEnemyName);
- started = true;
- }
- @Override
- public int onLoop() throws InterruptedException {
- if(started) getState();
- return random(100, 200);
- }
- private void getState() throws InterruptedException {
- if(!client.isLoggedIn()) {
- log("Not logged in.");
- log("You need to be logged in for this script to work.");
- return;
- }
- if(!tabs.getOpen().equals(Tab.MAGIC)) {
- if(tabs.open(Tab.MAGIC)) {
- sleepUntilMagicTabOpens();
- }
- return;
- }
- Entity enemy = npcs.closest(targetEnemyName);
- if(enemy == null) {
- log("Target enemy not found");
- return;
- }
- soulRunesCurrentAmount = getNumberOfSoulRunes();
- natureRunesCurrentAmount = getNumberOfNatureRunes();
- soulRunesUsed = soulRunesStartAmount - soulRunesCurrentAmount;
- natureRunesUsed = natureRunesStartAmount - natureRunesCurrentAmount;
- currentMagicExp = skills.getExperience(Skill.MAGIC);
- if(magic.castSpellOnEntity(Spells.NormalSpells.STUN, enemy) && sleepUntilStunIsCast(soulRunesCurrentAmount)) {
- sleep(random(25, 100));
- if(moveMouseToAlchArea()) {
- leftClick();
- if(sleepUntilInventoryTabActive() && isHighAlchOption()) {
- sleep(random(25, 100));
- leftClick();
- sleepUntilMagicTabOpens();
- }
- }
- }
- }
- private int getNumberOfSoulRunes() throws InterruptedException {
- for(Item item : inventory.getItems()) {
- if(item != null && item.getDefinition() != null && item.getName() != null) {
- if(item.getName().equals("Soul rune")) {
- return item.getAmount();
- }
- }
- }
- return 0;
- }
- private int getNumberOfNatureRunes() throws InterruptedException {
- for(Item item : inventory.getItems()) {
- if(item != null && item.getDefinition() != null && item.getName() != null) {
- if(item.getName().equals("Nature rune")) {
- return item.getAmount();
- }
- }
- }
- return 0;
- }
- private boolean moveMouseToAlchArea() throws InterruptedException {
- //high alch area rectangle
- //709, 322
- //719, 336
- mouse.move(random(709, 719), random(322, 336));
- return isHighAlchOption();
- }
- private boolean isHighAlchOption() {
- for(Option option : menu.getMenu()) {
- if(option != null) {
- if(option.action.equals("Cast")) {
- if(option.name.contains("High Level Alchemy")) {
- return true;
- }
- }
- }
- }
- return false;
- }
- private void leftClick() {
- mouse.click(false);
- }
- private void rightClick() {
- mouse.click(true);
- }
- private void sleepUntilMagicTabOpens() throws InterruptedException {
- long startTime = System.currentTimeMillis();
- long timeout = 4000;
- while(!tabs.getOpen().equals(Tab.MAGIC)) {
- long timeNow = System.currentTimeMillis();
- if(timeNow > startTime + timeout) {
- break;
- }
- sleep(100);
- }
- }
- private boolean sleepUntilStunIsCast(int startNumOfSoulRunes) throws InterruptedException {
- long startTime = System.currentTimeMillis();
- long timeout = 4000;
- while(getNumberOfSoulRunes() == startNumOfSoulRunes) {
- long timeNow = System.currentTimeMillis();
- if(timeNow > startTime + timeout) {
- return false;
- }
- sleep(100);
- }
- return true;
- }
- private boolean sleepUntilInventoryTabActive() throws InterruptedException {
- long startTime = System.currentTimeMillis();
- long timeout = 4000;
- while(!tabs.getOpen().equals(Tab.INVENTORY)) {
- long timeNow = System.currentTimeMillis();
- if(timeNow > startTime + timeout) {
- return false;
- }
- sleep(100);
- }
- return true;
- }
- @Override
- public void onPaint(Graphics2D g) {
- int baseY = 10;
- int baseX = 275;
- int gapYAfterHeading = 20;
- g.setColor(Color.LIGHT_GRAY);
- g.fillRect(baseX, baseY, 290, 151);
- g.setColor(Color.BLACK);
- g.drawString("---: STUN-ALCHER :---", baseX+30, baseY+20);
- long totalRunTime = System.currentTimeMillis() - scriptStartTime;
- long secondsRunTime = totalRunTime / 1000;
- long minutesRunTime = 0;
- if(secondsRunTime >= 60) {
- minutesRunTime = secondsRunTime / 60;
- secondsRunTime = secondsRunTime - (minutesRunTime * 60);
- }
- String strRunTime = "";
- if(minutesRunTime > 0)
- strRunTime += minutesRunTime + "min ";
- strRunTime += secondsRunTime + "s";
- g.drawString("Run Time: " + strRunTime, baseX+10, baseY+gapYAfterHeading+35);
- g.drawString("Total Stuns: " + soulRunesUsed, baseX+10, baseY+gapYAfterHeading+50);
- g.drawString("Total High Alchs: " + natureRunesUsed, baseX+10, baseY+gapYAfterHeading+65);
- g.drawString("Exp to next level: " + NumberFormat.getNumberInstance(Locale.ENGLISH).format(skills.experienceToLevel(Skill.MAGIC)), baseX+10, baseY+gapYAfterHeading+80);
- int totalMagicExp = currentMagicExp - startMagicExp;
- String strMagicExp = NumberFormat.getNumberInstance(Locale.ENGLISH).format(totalMagicExp);
- g.drawString("Total Exp gained: " + strMagicExp, baseX+10, baseY+gapYAfterHeading+95);
- int magicLevel = skills.getStatic(Skill.MAGIC);
- g.drawString("Current level: " + magicLevel, baseX+10, baseY+gapYAfterHeading+110);
- g.drawString("Levels gained: " + (magicLevel - startMagicLevel), baseX+10, baseY+gapYAfterHeading+125);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement