Jump to content

Simple onLoop() script :)


Saiyan

Recommended Posts

Ok so this is a simple recoil enchanter script (it is quite old I made it last year but never used it till now)
It can be improved it's no where near perfect but it is stable as far as i'm aware 
you are free to use this and improve etc. but I request that you do not resell unless your planning on adding more features etc.
Please do comment if this was helpful in helping you understand how to script I will document this tomorrow
if you want to compile this into a jar open up intellij or eclipse and use a script tutorial guide like apaecs in how to compile (it is quite easy) if you struggle tho i will post the jar of this
 
 
there are two classes to this one is for the Dynamic Sleeping which is less tedious to write out (made by @Explv ) All credits go to him for it.
 
P.S Sorry for the {} indentation it's how it is when i post this so i'll post the whole code on Pastebin if you find this annoying lol
 
 
DOWNLOAD LINK http://www.filedropper.com/simpleenchanter_1 (old version) need to update the jar link lol
 
 
EDITS:

1) Removed the logOut method as it threw an error (you can make one yourself easily)

2) Added logOut method acerd was kind enuff to share his rewrite version :)


 
http://pastebin.com/z2JWh6g7
 

 import java.util.function.BooleanSupplier;
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;
import org.osbot.rs07.utility.ConditionalSleep;

@ScriptManifest(logo = "", name = "Simple Recoil Enchanter", author = "Saiyan", info = "Recoil enchanter", version = 0)
public class Main extends Script {

    @Override
    public void onStart() {

        log("recoil enchanter");
    }

    private class DynamicSleep extends ConditionalSleep {
        private final BooleanSupplier condition;

        public DynamicSleep(final BooleanSupplier condition, int timeout) {
            super(timeout);
            this.condition = condition;
        }

        @Override
        public boolean condition() throws InterruptedException {
            return condition.getAsBoolean();
        }
    }

    @Override
    public int onLoop() throws InterruptedException {
        if (canEnchant()) {
            enchantRing();
            log("enchantRing active");
        } else {
            banking();
            log("banking active");
        }
        return 350;
    }

    private boolean canEnchant() {
        return getInventory().contains("Sapphire ring") && getInventory().contains("Cosmic rune")
                && !getBank().isOpen();
    }

    private void enchantRing() throws InterruptedException {
        if (!getTabs().open(Tab.MAGIC)) {
            getTabs().open(Tab.MAGIC);
        } else {
            if (getMagic().canCast(Spells.NormalSpells.LVL_1_ENCHANT)) {
                if (getMagic().castSpell(Spells.NormalSpells.LVL_1_ENCHANT)) {
                    if (getInventory().interact("Cast", "Sapphire ring")) {
                        new DynamicSleep(() -> getTabs().getOpen() == Tab.MAGIC, 5000).sleep();
                    }
                }
            }
        }
    }

    @SuppressWarnings("unchecked")
    private void banking() throws InterruptedException {
        if (!getBank().isOpen()) {
            if (getBank().open())
                new DynamicSleep(() -> getBank().isOpen(), 5000).sleep();
        } else if (getInventory()
                .contains(i -> !i.getName().equals("Cosmic rune") && !i.getName().equals("Sapphire ring"))) {
            getBank().depositAllExcept("Cosmic rune", "Sapphire ring");
        } else if (!getInventory().contains("Cosmic rune")) {
            if (getBank().contains("Cosmic rune"))
                getBank().withdrawAllButOne("Cosmic rune");
            else
                stop();
        } else if (!getInventory().contains("Sapphire ring")) {
            if (getBank().contains("Sapphire ring"))
                getBank().withdrawAll("Sapphire ring");
            else
                stop();
        } else {
            getBank().close();
        }
    }
}

 
 
TLDR; if you need help on me explaining any parts please do message me smile.png
 
Thanks and i hope you have learnt something new

Edited by Saiyan
  • Like 1
Link to comment
Share on other sites

because i was bored , i rewrote it:

import java.util.function.BooleanSupplier;
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;
import org.osbot.rs07.utility.ConditionalSleep;

@ScriptManifest(logo = "", name = "Simple Recoil Enchanter", author = "Saiyan", info = "Recoil enchanter", version = 0)
public class Main extends Script {

	@Override
	public void onStart() {

		log("recoil enchanter");
	}

	private class DynamicSleep extends ConditionalSleep {
		private final BooleanSupplier condition;

		public DynamicSleep(final BooleanSupplier condition, int timeout) {
			super(timeout);
			this.condition = condition;
		}

		@Override
		public boolean condition() throws InterruptedException {
			return condition.getAsBoolean();
		}
	}

	@Override
	public int onLoop() throws InterruptedException {
		if (canEnchant()) {
			enchantRing();
			log("enchantRing active");
		} else {
			banking();
			log("banking active");
		}
		return 350;
	}

	private boolean canEnchant() {
		return getInventory().contains("Sapphire ring") && getInventory().contains("Cosmic rune")
				&& !getBank().isOpen();
	}

	private void enchantRing() throws InterruptedException {
		if (!getTabs().open(Tab.MAGIC)) {
			getTabs().open(Tab.MAGIC);
		} else {
			if (getMagic().canCast(Spells.NormalSpells.LVL_1_ENCHANT)) {
				if (getMagic().castSpell(Spells.NormalSpells.LVL_1_ENCHANT)) {
					if (getInventory().interact("Cast", "Sapphire ring")) {
						new DynamicSleep(() -> getTabs().getOpen() == Tab.MAGIC, 5000).sleep();
					}
				}
			}
		}
	}

	@SuppressWarnings("unchecked")
	private void banking() throws InterruptedException {
		if (!getBank().isOpen()) {
			if (getBank().open())
				new DynamicSleep(() -> getBank().isOpen(), 5000).sleep();
		} else if (getInventory()
				.contains(i -> !i.getName().equals("Cosmic rune") && !i.getName().equals("Sapphire ring"))) {
			getBank().depositAllExcept("Cosmic rune", "Sapphire ring");
		} else if (!getInventory().contains("Cosmic rune")) {
			if (getBank().contains("Cosmic rune"))
				getBank().withdrawAllButOne("Cosmic rune");
			else
				stop();
		} else if (!getInventory().contains("Sapphire ring")) {
			if (getBank().contains("Sapphire ring"))
				getBank().withdrawAll("Sapphire ring");
			else
				stop();
		} else {
			getBank().close();
		}
	}
}
  • Like 1
Link to comment
Share on other sites

Ok so this is a simple recoil enchanter script (it is quite old I made it last year but never used it till now)

It can be improved it's no where near perfect but it is stable as far as i'm aware 

you are free to use this and improve etc. but I request that you do not resell unless your planning on adding more features etc.

Please do comment if this was helpful in helping you understand how to script I will document this tomorrow

if you want to compile this into a jar open up intellij or eclipse and use a script tutorial guide like apaecs in how to compile (it is quite easy) if you struggle tho i will post the jar of this

 

 

there are two classes to this one is for the Dynamic Sleeping which is less tedious to write out (made by @Explv ) All credits go to him for it.

 

P.S Sorry for the {} indentation it's how it is when i post this so i'll post the whole code on Pastebin if you find this annoying lol

 

 

DOWNLOAD LINK http://www.filedropper.com/simpleenchanter_1 (old version) need to update the jar link lol

 

 

EDITS:

1) Removed the logOut method as it threw an error (you can make one yourself easily)

2) Added logOut method acerd was kind enuff to share his rewrite version smile.png

 

http://pastebin.com/z2JWh6g7

 

 import java.util.function.BooleanSupplier;
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;
import org.osbot.rs07.utility.ConditionalSleep;

@ScriptManifest(logo = "", name = "Simple Recoil Enchanter", author = "Saiyan", info = "Recoil enchanter", version = 0)
public class Main extends Script {

    @Override
    public void onStart() {

        log("recoil enchanter");
    }

    private class DynamicSleep extends ConditionalSleep {
        private final BooleanSupplier condition;

        public DynamicSleep(final BooleanSupplier condition, int timeout) {
            super(timeout);
            this.condition = condition;
        }

        @Override
        public boolean condition() throws InterruptedException {
            return condition.getAsBoolean();
        }
    }

    @Override
    public int onLoop() throws InterruptedException {
        if (canEnchant()) {
            enchantRing();
            log("enchantRing active");
        } else {
            banking();
            log("banking active");
        }
        return 350;
    }

    private boolean canEnchant() {
        return getInventory().contains("Sapphire ring") && getInventory().contains("Cosmic rune")
                && !getBank().isOpen();
    }

    private void enchantRing() throws InterruptedException {
        if (!getTabs().open(Tab.MAGIC)) {
            getTabs().open(Tab.MAGIC);
        } else {
            if (getMagic().canCast(Spells.NormalSpells.LVL_1_ENCHANT)) {
                if (getMagic().castSpell(Spells.NormalSpells.LVL_1_ENCHANT)) {
                    if (getInventory().interact("Cast", "Sapphire ring")) {
                        new DynamicSleep(() -> getTabs().getOpen() == Tab.MAGIC, 5000).sleep();
                    }
                }
            }
        }
    }

    @SuppressWarnings("unchecked")
    private void banking() throws InterruptedException {
        if (!getBank().isOpen()) {
            if (getBank().open())
                new DynamicSleep(() -> getBank().isOpen(), 5000).sleep();
        } else if (getInventory()
                .contains(i -> !i.getName().equals("Cosmic rune") && !i.getName().equals("Sapphire ring"))) {
            getBank().depositAllExcept("Cosmic rune", "Sapphire ring");
        } else if (!getInventory().contains("Cosmic rune")) {
            if (getBank().contains("Cosmic rune"))
                getBank().withdrawAllButOne("Cosmic rune");
            else
                stop();
        } else if (!getInventory().contains("Sapphire ring")) {
            if (getBank().contains("Sapphire ring"))
                getBank().withdrawAll("Sapphire ring");
            else
                stop();
        } else {
            getBank().close();
        }
    }
}

 

 

TLDR; if you need help on me explaining any parts please do message me smile.png

 

Thanks and i hope you have learnt something new

 

Looking good bawss, nice work.

 

Just a few things you might want to clean up:

 

Firstly,

if(getInventory().contains(i -> !i.getName().equals("Cosmic rune") && !i.getName().equals("Sapphire ring")))

Can be replaced with:

if(!getInventory().onlyContains("Cosmic rune", "Sapphire ring"))

Secondly, I don't think you need to open the magic tab before casting a spell, it will already do that for you.

 

Also when enchanting you don't need to check:

if (getMagic().canCast(Spells.NormalSpells.LVL_1_ENCHANT)) 

Because you already know you have the required runes. Instead, in onStart() you should check if the player has a magic level >= the required, and stop the script if they don't with a useful message:

if(getSkills().getStatic(Skill.MAGIC) < Spells.NormalSpells.LVL_1_ENCHANT.getRequiredLevel()) {
  log("You do not have a magic level high enough to use this script!");
  stop();
}

In onStart you also may want to check the player is in a P2P world, as enchanting is members only (I think). If they are not in P2P attempt to hop worlds, if it fails, again log a useful message and stop the script:

if(!getWorlds().isMembersWorld()) {
  log("You need to be logged into a members world to use this script.");
  log("Attempting to hop worlds");
  if(!getWorlds().hopToP2PWorld()) {
    log("Failed to hop to P2P world");
    stop();
  }
}

You also haven't made any checks anywhere for if the player has water runes /  a staff of water, and no banking to retrieve them.

Edited by Explv
  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...