freedom1 Posted July 4, 2019 Share Posted July 4, 2019 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) + "."); } } } Quote Link to comment Share on other sites More sharing options...
Hybris Posted July 4, 2019 Share Posted July 4, 2019 onLoop is a loop by itself, so using a while-loop inside is bad programming practice. You should use if-statements there. 1 Quote Link to comment Share on other sites More sharing options...
freedom1 Posted July 4, 2019 Author Share Posted July 4, 2019 Thank you, I will revise it. Quote Link to comment Share on other sites More sharing options...
Medusa Posted July 4, 2019 Share Posted July 4, 2019 Nice script considering it's your first one Gl with your future scripts. Just noticed that you say it doesn't run. Why do you have a class within another class? You can just use one class and have that extend Script 1 Quote Link to comment Share on other sites More sharing options...
freedom1 Posted July 4, 2019 Author Share Posted July 4, 2019 (edited) 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. Edited July 4, 2019 by freedom1 WOOT ITS ALIVE! Quote Link to comment Share on other sites More sharing options...
Hybris Posted July 4, 2019 Share Posted July 4, 2019 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? 1 Quote Link to comment Share on other sites More sharing options...
freedom1 Posted July 4, 2019 Author Share Posted July 4, 2019 (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 July 4, 2019 by freedom1 Quote Link to comment Share on other sites More sharing options...
Medusa Posted July 4, 2019 Share Posted July 4, 2019 Not sure if you have to do this, but maybe open the inventory when checking if it contains smth. Same for spells. 1 Quote Link to comment Share on other sites More sharing options...
freedom1 Posted July 4, 2019 Author Share Posted July 4, 2019 (edited) Will do Thanks, I thought this was automatic. I tried starting from the spell and inventory screens, manually. No luck. Edited July 4, 2019 by freedom1 Quote Link to comment Share on other sites More sharing options...
FuryShark Posted July 4, 2019 Share Posted July 4, 2019 if you have ; after a while/if it will run that code no matter what that would be what is logging you out. 1 Quote Link to comment Share on other sites More sharing options...
freedom1 Posted July 4, 2019 Author Share Posted July 4, 2019 (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 July 4, 2019 by freedom1 Quote Link to comment Share on other sites More sharing options...
Medusa Posted July 4, 2019 Share Posted July 4, 2019 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. 1 Quote Link to comment Share on other sites More sharing options...
Chorux Posted July 4, 2019 Share Posted July 4, 2019 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 1 Quote Link to comment Share on other sites More sharing options...
FuryShark Posted July 5, 2019 Share Posted July 5, 2019 Im also getting the same error on another script [ERROR][Bot #1][07/05 01:38:00 AM]: Inventory widget is null, trying to guess position. 1 Quote Link to comment Share on other sites More sharing options...
freedom1 Posted July 5, 2019 Author Share Posted July 5, 2019 (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 July 5, 2019 by freedom1 Quote Link to comment Share on other sites More sharing options...