Jump to content

First script please be gentle lol


Recommended Posts

Posted

Thanks for your time,

My first script, doesn't run. It builds, using IntelliJ. It doesn't log anything... Any and all help is appreciated. It is suppose to reanimate ensouled giant heads. 

Quote

import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.ui.MagicSpell;
import org.osbot.rs07.api.ui.Spells;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
public class HeadKiller
{
    @ScriptManifest(author = "freedom", name = "EnsouledHeadKiller", info = "Kills Ensouled Heads", version = 0.04, logo = "")
    public final class killer extends Script
    {
        @Override
        public final void onStart()
        {
            log("Script started...");
        }
        public boolean Combat;
        public boolean Head;
        public boolean Spell;
        public int Current;
        @Override
        public final int onLoop() throws InterruptedException
        {
            log("Setting up....");
            Combat = getCombat().isFighting();
            Head = getInventory().contains("Ensouled giant head");
            Spell = getMagic().canCast(Spells.ArceuusSpells.REANIMATE_GIANT);
            Current = 0;
            while ((Head == true) && (Spell == true));
            {
                if (Combat == false)
                {
                    getMagic().castSpell(Spells.ArceuusSpells.REANIMATE_GIANT);
                    getInventory().interact("Cast", "Ensouled giant head");
                    Current = Current + 1;
                    log("Currently killing number " + Current + ".");
                    sleep(random(200, 1200));
                    return 0;
                }
            }
            stop(true);
        return 0;
        }
        @Override
        public final void onExit() {
            log("Script exiting... We completed " + (Current - 1) + ".");
        }
    }


}

 

Posted
17 minutes ago, freedom1 said:

Thank you, no idea where I got that from. I will change it.

Lets be honest, I have like 4 hours making this. Mostly, looking at what others have done and trying to adapt it to my script. 

EDIT: It started, but insta logged out.

Gratz mate 😛

Post the new code & I'll take a look at that :) What does the logger say when it logs out?

  • Like 1
Posted (edited)

Ok I changed stop() to log("logout") so I can see when it wants to log out.

I have an error though,

"Inventory widget is null, trying to guess position."

The counters for how many killed and completed work!

[INFO][Bot #1][07/04 01:06:31 PM]: Script started...
[INFO][Bot #1][07/04 01:06:31 PM]: Started script : EnsouledHeadKiller
[INFO][Bot #1][07/04 01:06:31 PM]: Setting up....
[INFO][Bot #1][07/04 01:06:32 PM]: logout
[ERROR][Bot #1][07/04 01:06:33 PM]: Inventory widget is null, trying to guess position.
[INFO][Bot #1][07/04 01:06:37 PM]: Currently killing number 1.
[INFO][Bot #1][07/04 01:06:38 PM]: Setting up....
[INFO][Bot #1][07/04 01:06:39 PM]: logout
[ERROR][Bot #1][07/04 01:06:40 PM]: Inventory widget is null, trying to guess position.
[INFO][Bot #1][07/04 01:06:45 PM]: Currently killing number 1.
[INFO][Bot #1][07/04 01:06:45 PM]: Setting up....
[INFO][Bot #1][07/04 01:06:46 PM]: logout
[ERROR][Bot #1][07/04 01:06:47 PM]: Inventory widget is null, trying to guess position.
[INFO][Bot #1][07/04 01:06:51 PM]: Currently killing number 1.
[INFO][Bot #1][07/04 01:06:51 PM]: Script EnsouledHeadKiller has paused!
 

Quote

import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.ui.MagicSpell;
import org.osbot.rs07.api.Inventory;
import org.osbot.rs07.api.ui.Spells;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
    @ScriptManifest(author = "freedom", name = "EnsouledHeadKiller", info = "Kills Ensouled Heads", version = 0.05, logo = "")
    public final class HeadKiller extends Script
        {
            @Override
            public final void onStart()
                {
                    log("Script started...");
                }
            public boolean Combat;
            public boolean Head;
            public boolean Spell;
            public int Current;
            @Override
            public final int onLoop() throws InterruptedException
                {
                    log("Setting up....");
                    Combat = getCombat().isFighting();
                    Head = getInventory().contains("Ensouled giant head");
                    Spell = getMagic().canCast(Spells.ArceuusSpells.REANIMATE_GIANT);
                    Current = 0;
                    if ((Head == false) && (Spell == false));
                        {
                            log("logout");
                        }
                    if (Combat == false);
                        {
                            getMagic().castSpell(Spells.ArceuusSpells.REANIMATE_GIANT);
                            getInventory().interact("Cast", "Ensouled giant head");
                            Current = Current + 1;
                            log("Currently killing number " + Current + ".");
                            sleep(random(200, 1200));
                            return 0;
                        }
                }
            @Override
            public final void onExit()
                {
                    log("Script exiting... We completed " + (Current - 1) + ".");
                }
        }

 

Edited by freedom1
Posted (edited)
I didn't read that anywhere, thanks.

EDIT: that fixed the logout problem

but the inventory widget null error still exists, am I missing the correct import?

Currently it tries to cast the spell, but gets confused on the inventory screen, and then goes back to the spell tab and tries again

I tried a sleep timer but no luck

Quote

getMagic().castSpell(Spells.ArceuusSpells.REANIMATE_GIANT);
sleep(random(100,250));
getInventory().interact("Cast", "Ensouled giant head");
Current = Current + 1;
log("Currently killing number " + Current + ".");
sleep(random(200, 1200));
return 0;

 

Edited by freedom1
Posted
1 hour ago, freedom1 said:

I didn't read that anywhere, thanks.

EDIT: that fixed the logout problem

but the inventory widget null error still exists, am I missing the correct import?

Currently it tries to cast the spell, but gets confused on the inventory screen, and then goes back to the spell tab and tries again

I tried a sleep timer but no luck

 

learn to use conditional sleeps. It works great for stuff like that.

  • Like 1
Posted
2 hours ago, freedom1 said:

I didn't read that anywhere, thanks.

EDIT: that fixed the logout problem

but the inventory widget null error still exists, am I missing the correct import?

Currently it tries to cast the spell, but gets confused on the inventory screen, and then goes back to the spell tab and tries again

I tried a sleep timer but no luck

 

Maybe try to split the interaction part so you can debug it more. First try to find the item in your inventory, and then interact on it

Item head = getInventory().getItem("Ensouled giant head");
log("Item was found");
head.hasAction("Cast");
log("Cast action was found on the item");
head.interact("Cast");

or something like that.

Also as suggested, check out the conditional sleep so you don't have fiddle with finding a good sleep amount. 

 section 9

  • Like 1
Posted (edited)

Thanks to everyone who helped!

I have a working script only took 12hrs, but I did learn a lot.

I have no programing experience.

I could not get the spell to work, so I had to mouse click it =(.

Saturday Ill try to get it banking.

Quote

import org.osbot.rs07.api.ui.Tab;
import org.osbot.rs07.api.ui.Spells;
import org.osbot.rs07.api.ui.Spells.ArceuusSpells;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
    @ScriptManifest(author = "freedom", name = "EnsouledHeadKiller", info = "Kills Ensouled Heads", version = 0.1, logo = "")
    public final class HeadKiller extends Script {
        @Override
        public final void onStart() {
            log("Script started...");
        }

        private boolean Combat;
        private boolean Head;
        private boolean CCSpell;
        private int Current = 0;
        private ArceuusSpells Spell;
        private int x;
        private int y;
        private boolean rightclick;
        @Override
        public final int onLoop() throws InterruptedException {
            log("Setting up....");
            Combat = getCombat().isFighting();
            log("Currently fighting " + Combat + ".");
            Head = getInventory().contains("Ensouled giant head");
            Spell = Spells.ArceuusSpells.REANIMATE_GIANT;
            CCSpell = getMagic().canCast(Spell);
            x = random(700,720);
            y = random(300,318);
            rightclick = false;
            log("Almost ready...");
            if ((!Head) || (!CCSpell)) {
                stop(false);
            }
            log("Runes and Heads are ready...");
            if (!Combat) {
                log("Not in combat...");
                if (getMagic().isSpellSelected()) {
                    if (getInventory().interact("Reanimate", "Ensouled giant head")) {
                        log("Killing Giant...");
                    }
                }
                else {
                        getMagic().castSpell(Spell);
                        log("Casting Reanimate...");
                        mouse.click(x, y, rightclick);
                        Sleep.sleepUntil(() -> tabs.isOpen(Tab.INVENTORY)|| Combat, 1250);
                        getInventory().interact("Reanimate", "Ensouled giant head");
                        sleep(1000);
                        log("Success...");
                        Current = Current + 1;
                        sleep(1000);
                    }
                }
            if (Combat) {
                log("Currently killing number " + Current + ".");
                Sleep.sleepUntil(() -> !Combat, 1200);
                }
        return 0;
        }
    }

 

Edited by freedom1

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