Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • New LesserDemonMage Script


    turbobk1990

    Recommended Posts

    Hiya guys!!


    I'm new to Dream Bot and Java scripting.
    I have tried to create a script that will automatically attack the lesser demon at the top of the mage tower south of draynor using Magic.
    Here is a rundown of what I've tried to do so far but I really need help to get it compiled and built and running.

    Is anybody here a professional at java and dream bot scripting? I assume there are plenty of people lol.

    Thanks in advance for any help you can give me.


    1. Check if we are logged in, if not then login using the dream bot account manager.
    2. Check if we are standing in the top level of the Wizards tower with the Lesser Demon visible on the mini map, if so then continue, if not then exit with an error saying we need to be in the top level of the wizards tower to start.
    3. Make sure an auto cast spell is set, if not then exit with an error saying that you need to set an auto cast spell.
    4. If an auto cast spell is set then set Auto Retaliate to ON if it isn't already.
    5. Check if 2 or more players are in the area already, excluding ourselves from the count. If so then world hop to another random F2P world and start the script from the start again. If not then go to the next step.
    6. Find the lesser demon on the screen and right click on it and select Attack.
    7. Perform anti random checks to handle random events, advanced antiban features to act human like to avoid getting banned, and inventory checks to see if runes are need or the inventory is full, if so then go to Draynor bank and withdraw the needed items and/or deposit the looted items only, do not deposit what the user already had in the inventory at startup, this should be kept and not deposited. If  if runes are not needed or the inventory is not full then go to the next step.
    8. Wait until the Lesser demon is dead.
    9. Check if we have the runes needed for telekinetic grab, if so then loot any item from the lesser demon with a value over 400gp. If we don't have any runes for telekinetic grab then send an error saying that we can loot items because we don't have the runes or level necessary for telekinetic grab but don't exit the script just continue.
    10. Wait for the lesser demon to respawn after we have killed it, wait for a random time between 3 seconds and 6 seconds, and then check it the lesser demon is on the screen again, if not then re wait another 3 to 6 seconds until the lesser demon reappears or a time of 1 minute runs out, if the time runs out exit the script saying a lesser demon couldn't be found within 1 minute.
    During this waiting time perform anti random checks and advanced anti ban features.
    11. If the lesser demon reappears and everything is ok then repeat from step 5.


    Here is the script I've created below, so far but I am getting so many errors and it just wont compile and run.
    I'm happy to even pay for a professional to help me fix it and get it into a full working script with user set options etc if needed.

     


    THANKS GUYS!!


     

    import org.dreambot.api.Client;
    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.methods.combat.Combat;
    import org.dreambot.api.methods.combat.CombatStyle;
    import org.dreambot.api.methods.container.impl.bank.Bank;
    import org.dreambot.api.methods.container.impl.Inventory;
    import org.dreambot.api.methods.interactive.NPCs;
    import org.dreambot.api.methods.interactive.Players;
    import org.dreambot.api.methods.magic.Magic;
    import org.dreambot.api.methods.magic.Normal;
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.methods.settings.PlayerSettings;
    import org.dreambot.api.methods.walking.impl.Walking;
    import org.dreambot.api.methods.world.World;
    import org.dreambot.api.methods.world.Worlds;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.wrappers.interactive.NPC;
    import org.dreambot.api.wrappers.interactive.Player;
    import org.dreambot.api.wrappers.items.GroundItem;
    import org.dreambot.api.methods.map.Tile;
    import org.dreambot.api.methods.map.Area;
    
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;
    
    @ScriptManifest(author = "LukeyJ", name = "LesserDemonMage", version = 1.0, description = "Automatically attacks Lesser Demons in Wizards' Tower, Loots and Banks, contains AntiBan", category = Category.MAGIC)
    public class LesserDemonMage extends AbstractScript {
    
        private static final String LESSER_DEMON = "Lesser demon";
        private static final Area WIZARDS_TOWER_TOP_FLOOR = new Area(3102, 3164, 3109, 3159, 2);
        private static final Area DRAYNOR_BANK_AREA = new Area(3092, 3245, 3096, 3240, 0);
        private List<Integer> startInventory;
        private boolean loggedIn = false;
    
        @Override
        public void onStart() {
            log("Script started");
            if (!Client.isLoggedIn()) {
                log("Failed to log in. Stopping script.");
                stop();
            }
            loggedIn = true;
        }
    
            if (!WIZARDS_TOWER_TOP_FLOOR.contains(getLocalPlayer())) {
                log("You must be on the top floor of the Wizards' Tower to start this script.");
                stop();
            }
    
            if (Magic.isAutocasting() == null) {
                log("You need to set an autocast spell before starting the script.");
                stop();
            }
    
            if (!getSettings().isAutoRetaliateOn()) {
                Combat.toggleAutoRetaliate(true);
            }
    
            startInventory = new ArrayList<>(Inventory.all(item -> item != null).stream().map(item -> item.getID()).toList());
        }
    
        @Override
        public int onLoop() {
            if (!loggedIn) {
                return 1000;
            }
    
            if (WIZARDS_TOWER_TOP_FLOOR.contains(getLocalPlayer())) {
                List<Player> players = Players.all(player -> player != null && !player.equals(getLocalPlayer()) && WIZARDS_TOWER_TOP_FLOOR.contains(player));
    
                if (players.size() >= 2) {
                    World randomF2PWorld = Worlds.getRandomWorld(world -> world != null && world.isF2P() && !world.isHighRisk() && !world.isPVP());
                    if (randomF2PWorld != null && Worlds.hopTo(randomF2PWorld)) {
                        sleepUntil(() -> getClient().getWorld() == randomF2PWorld.getID(), 10000);
                        return 1000;
                    }
                }
    
                if (Inventory.isFull() || (Inventory.contains("Law rune") && Inventory.contains("Air rune"))) {
                    if (DRAYNOR_BANK_AREA.contains(getLocalPlayer())) {
                        if (!Bank.isOpen()) {
                            if (Bank.openClosest()) {
                                sleepUntil(Bank::isOpen, 5000);
                            }
                        } else {
                            handleBanking();
                        }
                    } else {
                        Walking.walk(DRAYNOR_BANK_AREA.getRandomTile());
                        sleep(Calculations.random(1000, 2000));
                    }
                    return 1000;
                }
    
                NPC lesserDemon = NPCs.closest(npc -> npc != null && npc.getName().equals(LESSER_DEMON) && !npc.isInCombat());
                if (lesserDemon != null) {
                    if (!getLocalPlayer().isInCombat()) {
                        if (lesserDemon.interact("Attack")) {
                            sleepUntil(() -> getLocalPlayer().isInCombat(), Calculations.random(3000, 6000));
                        }
                    } else {
                        performAdvancedAntiBan();
    
                        // Step 8 - Wait until the Lesser demon is dead
                        sleepUntil(this::isLesserDemonDead, Calculations.random(3000, 6000));
    
                        // Step 9 - Loot items
                        lootItems();
    
                        // Step 10 - Wait for the Lesser demon to respawn
                        int elapsedTime = 0;
                        while (!lesserDemonRespawned() && elapsedTime < 60000) {
                            performAdvancedAntiBan();
                            sleep(Calculations.random(3000, 6000));
                            elapsedTime += 6000;
                        }
    
                        if (!lesserDemonRespawned()) {
                            log("A Lesser demon couldn't be found within 1 minute. Exiting script.");
                            stop();
                        }
                    }
                }
            } else {
                Walking.walk(WIZARDS_TOWER_TOP_FLOOR.getRandomTile());
                sleep(Calculations.random(1000, 2000));
            }
    
            return Calculations.random(250, 500);
        }
    
        private void handleBanking() {
            // Deposit looted items
            Inventory.all(item -> item != null && !startInventory.contains(item.getID())).forEach(item -> {
                if (Bank.deposit(item.getID(), item.getAmount())) {
                    sleepUntil(() -> !Inventory.contains(item.getID()), 3000);
                }
            });
    
            // Withdraw runes if needed
            if (!Inventory.contains("Law rune")) {
                if (Bank.withdraw("Law rune", 100)) {
                    sleepUntil(() -> Inventory.contains("Law rune"), 3000);
                }
            }
    
            if (!Inventory.contains("Air rune")) {
                if (Bank.withdraw("Air rune", 100)) {
                    sleepUntil(() -> Inventory.contains("Air rune"), 3000);
                }
            }
        }
    
        private void performAdvancedAntiBan() {
            int antiban = Calculations.random(1, 100);
    
            if (antiban < 10) {
                getCamera().rotateTo(Calculations.random(0, 2048), Calculations.random(128, 384));
                sleep(Calculations.random(200, 12500));
            } else if (antiban < 20) {
                getMouse().moveMouseOutsideScreen();
                sleep(Calculations.random(250, 20000));
            } else if (antiban < 30) {
                NPC randomNPC = NPCs.closest(npc -> npc != null && !npc.getName().equals(LESSER_DEMON));
                if (randomNPC != null) {
                    getCamera().rotateToEntity(randomNPC);
                    sleep(Calculations.random(200, 5000));
                }
            } else if (antiban < 40) {
                Player randomPlayer = Players.closest(player -> player != null && !player.equals(getLocalPlayer()));
                if (randomPlayer != null) {
                    getCamera().rotateToEntity(randomPlayer);
                    sleep(Calculations.random(200, 5000));
                }
            } else {
                sleep(Calculations.random(250, 1000));
            }
        }
    
        private void lootItems() {
            if (Magic.canCast(Normal.TELEKINETIC_GRAB)) {
                List<GroundItem> lootableItems = getGroundItems().all(item -> item != null && item.getTile().distance(getLocalPlayer()) < 10 && item.getDefinition().getPrice() > 400);
                for (GroundItem item : lootableItems) {
                    if (Magic.castSpellOn(Normal.TELEKINETIC_GRAB, item)) {
                        sleepUntil(() -> !item.exists(), 3000);
                    }
                }
            } else {
                log("Cannot loot items because we don't have the runes or level necessary for Telekinetic Grab.");
            }
        }
    
        private boolean isLesserDemonDead() {
            NPC lesserDemon = NPCs.closest(npc -> npc != null && npc.getName().equals(LESSER_DEMON) && !npc.isInCombat());
            return lesserDemon == null;
        }
    
        private boolean lesserDemonRespawned() {
            return NPCs.closest(npc -> npc != null && npc.getName().equals(LESSER_DEMON)) != null;
        }
    }

     

    Link to comment
    Share on other sites

    if (Inventory.isFull() || (Inventory.contains("Law rune") && Inventory.contains("Air rune"))) {
                    if (DRAYNOR_BANK_AREA.contains(getLocalPlayer())) {
                        if (!Bank.isOpen()) {
                            if (Bank.openClosest()) {
                                sleepUntil(Bank::isOpen, 5000);
                            }
                        } else {
                            handleBanking();
                        }
                    } else {
                        Walking.walk(DRAYNOR_BANK_AREA.getRandomTile());
                        sleep(Calculations.random(1000, 2000));
                    }
                    return 1000;
                }

    This I would change to 

     

    do {
                            Bank.open(BankLocation.DRAYNOR);
                            sleep(Calculations.random(3000, 8000));
                        }while (Bank.open() == false);

    Will get you to the bank and with the bank in Draynor open.

    Link to comment
    Share on other sites

    A few other recommendation

    • Drop all your extra antiban first and get just the core program working
    • Review what the lessor demon drops and build an Arraylist of only the items that make sense to telegrab. You could use this same array for depositing at the bank or just deposit all and withdraw the runes you need.
    • You appear to lack any test if you are at least high enough level to telegrab so you will want to consider that as well if your plan is to level accounts here.
    Link to comment
    Share on other sites

    On 5/8/2023 at 5:14 AM, RSMasterGuard said:

    A few other recommendation

    • Drop all your extra antiban first and get just the core program working
    • Review what the lessor demon drops and build an Arraylist of only the items that make sense to telegrab. You could use this same array for depositing at the bank or just deposit all and withdraw the runes you need.
    • You appear to lack any test if you are at least high enough level to telegrab so you will want to consider that as well if your plan is to level accounts here.

    Hey man I really appreciate your help on this!
    Do you have extensive knowledge of java/JavaScript and the dreambot client?

    Link to comment
    Share on other sites

    40 minutes ago, turbobk1990 said:

    Hey man I really appreciate your help on this!
    Do you have extensive knowledge of java/JavaScript and the dreambot client?

    enough to be dangerous not enough to get scripter+

    Link to comment
    Share on other sites

    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
    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.