Daviyow Posted October 8, 2017 Share Posted October 8, 2017 (edited) Hi all, i can't figure out why my script just nulls and logs out whenever i get the diagram of leveling up. I've tried with and without the enum DIALOGUE but makes no difference. this is the error: [INFO][Bot #1][10/08 03:27:46 PM]: Terminating script MagicTrainer... [INFO][Bot #1][10/08 03:27:46 PM]: MagicTrainer Exited. [INFO][Bot #1][10/08 03:27:46 PM]: Script MagicTrainer has exited! [ERROR][Bot #1][10/08 03:27:46 PM]: Error in script executor! java.lang.NullPointerException at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(ro:134) at java.lang.Thread.run(Unknown Source) Spoiler package MagicTrainer; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.api.map.Position; import org.osbot.rs07.api.model.GroundItem; import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.api.ui.MagicSpell; import org.osbot.rs07.api.ui.Message; import org.osbot.rs07.api.ui.Skill; import org.osbot.rs07.api.ui.Spells.NormalSpells; import org.osbot.rs07.api.ui.Tab; import org.osbot.rs07.event.WalkingEvent; import org.osbot.rs07.utility.ConditionalSleep; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import org.osbot.rs07.api.model.RS2Object; import static org.osbot.rs07.script.MethodProvider.random; import org.osbot.rs07.script.Script; import javax.swing.DefaultComboBoxModel; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import java.awt.*; import java.awt.Color; import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @ScriptManifest(name = "MagicTrainer", author = "Daviyow", version = 1.0, info = "", logo = "") public class MagicTrainer extends Script { private Position playerPosition; private long startTime, testTime; private int helmet = 0; private long runesStartup; private int randomSleep; private int startmXp; private int currentmXp; private long spellsCasted; private long mxpGained; long runes2; private double version = 1.0; private String[] runes = {"Mind rune","Fire rune"}; private enum State {NORUNES, ATTACK, ANTIBAN1, GRAB, ANTIBAN2, DIALOGUE}; private State getState() { NPC demon = getNpcs().closest("Lesser demon"); GroundItem helm = groundItems.closest("Rune med helm"); GroundItem uncut = groundItems.closest("Uncut diamond"); if(myPlayer() != null && dialogues != null && dialogues.getDialogues().inDialogue()) return State.DIALOGUE; if(inventory != null && myPlayer() != null && !inventory.contains(runes)) return State.NORUNES; if(inventory != null && helm != null && helm.isVisible() && inventory.contains("Law rune") && myPlayer() != null | inventory != null && uncut != null && uncut.isVisible() && inventory.contains("Uncut diamond") && myPlayer() != null) return State.GRAB; if(myPlayer() != null && demon != null && !myPlayer().isInteracting(demon) && demon.getHealth() != 0) return State.ATTACK; if(demon != null && myPlayer() != null && myPlayer().isInteracting(demon) && helm == null) return State.ANTIBAN1; return State.ANTIBAN2; } public void attack() throws InterruptedException { log("Attacking demon."); NPC demon = npcs.closest("Lesser demon"); if(demon != null && myPlayer() != null) { if(!myPlayer().isInteracting(demon)) { demon.interact("Attack"); sleep(random(700,1500)); switch (random(1,3)) { case 1: if(mouse != null) { log("After attack mouse movement."); mouse.move(random(40,60),(random(310,495))); } break; case 2: if(mouse != null) { log("After attack mouse movement."); mouse.moveOutsideScreen(); } break; case 3: if(mouse != null) { log("After attack mouse movement."); mouse.moveOutsideScreen(); } break; } sleep(1500); } } } public void antiBan1() throws InterruptedException { switch(random(1,60)) { case 1: if(mouse != null && myPlayer() != null) { log("Moving mouse outside of the screen"); mouse.moveOutsideScreen(); } break; case 2: if(mouse != null && myPlayer() != null) { log("Moving mouse randomly over the whole client."); mouse.move(random(0,760),(random(0,500))); } break; case 3: if(myPlayer() != null && mouse != null) { log("Moving mouse randomly on gamescreen."); mouse.move(random(20,30), random(320,485)); } break; case 4: if(mouse != null && mouse.isOnScreen() && myPlayer() != null) { log("Moving camera randomly."); camera.movePitch(random(45,67)); camera.moveYaw(random(40,350)); } break; case 5: if(mouse != null && myPlayer() != null) { log("Moving mouse outside of the screen"); mouse.moveOutsideScreen(); } break; case 6: log("Sleeping for a random time." +randomSleep); randomSleep = random(300,12000); sleep(randomSleep); break; case 7: if(mouse != null && myPlayer() != null) { log("Moving mouse outside of the screen"); mouse.moveOutsideScreen(); } break; case 8: log("Sleeping for a random time." +randomSleep); randomSleep = random(300,12000); sleep(randomSleep); break; case 9: log("Sleeping for a random time." +randomSleep); randomSleep = random(300,12000); sleep(randomSleep); break; case 10: log("Sleeping for a random time." +randomSleep); randomSleep = random(300,12000); sleep(randomSleep); break; } } public void antiBan2() throws InterruptedException { switch(random(1,60)) { case 1: if(mouse != null && myPlayer() != null) { log("Moving mouse outside of the screen"); mouse.moveOutsideScreen(); } break; case 2: if(mouse != null && myPlayer() != null) { log("Moving mouse randomly over the whole client."); mouse.move(random(0,760),(random(0,500))); } break; case 3: if(myPlayer() != null && mouse != null) { log("Moving mouse randomly on gamescreen."); mouse.move(random(20,30), random(320,485)); } break; case 4: if(mouse != null && mouse.isOnScreen() && myPlayer() != null) { log("Moving camera randomly."); camera.movePitch(random(45,67)); camera.moveYaw(random(40,350)); } break; case 5: if(mouse != null && myPlayer() != null) { log("Moving mouse outside of the screen"); mouse.moveOutsideScreen(); } break; case 6: log("Sleeping for a random time." +randomSleep); randomSleep = random(300,12000); sleep(randomSleep); break; case 7: if(mouse != null && myPlayer() != null) { log("Moving mouse outside of the screen"); mouse.moveOutsideScreen(); } break; case 8: log("Sleeping for a random time." +randomSleep); randomSleep = random(300,12000); sleep(randomSleep); break; case 9: log("Sleeping for a random time." +randomSleep); randomSleep = random(300,12000); sleep(randomSleep); break; case 10: log("Sleeping for a random time." +randomSleep); randomSleep = random(300,12000); sleep(randomSleep); break; } } public void grab() throws InterruptedException { GroundItem helm = groundItems.closest("Rune med helm"); GroundItem uncut = groundItems.closest("Uncut diamond"); MagicSpell spellToCast = NormalSpells.TELEKINETIC_GRAB; if(myPlayer() != null && helm != null && getMagic().canCast(spellToCast)) { getMagic().castSpellOnEntity(NormalSpells.TELEKINETIC_GRAB,helm); log("Grabbing rune helmet"); sleep(1500); helmet++; tabs.open(Tab.INVENTORY); } if(myPlayer() != null && uncut != null && getMagic().canCast(spellToCast)) { getMagic().castSpellOnEntity(NormalSpells.TELEKINETIC_GRAB,uncut); log("Grabbing uncut diamond"); sleep(1500); tabs.open(Tab.INVENTORY); } } public void dialogue() throws InterruptedException { if(myPlayer() != null && dialogues != null && dialogues.getDialogues().inDialogue()) { dialogues.getDialogues().clickContinue(); sleep(random(800,1600)); } } @Override public void onStart() { log("Starting Script..."); startTime = System.currentTimeMillis(); randomSleep = random(300,25000); if(myPlayer() != null && myPlayer().isVisible()) { experienceTracker.start(Skill.MAGIC); runesStartup = inventory.getAmount("Mind rune"); startmXp = skills.getExperience(Skill.MAGIC); } } @Override public int onLoop() throws InterruptedException { switch (getState()) { case ATTACK: attack(); break; case ANTIBAN1: antiBan1(); break; case ANTIBAN2: antiBan2(); break; case GRAB: grab(); break; case DIALOGUE: dialogue(); break; case NORUNES: log("No mind / fire runes."); stop(); break; } return random(300, 3000); } @Override public void onExit() { log("MagicTrainer Exited."); } @Override public void onMessage(Message m) { if (m.getMessage().contains("You do not have enough")) log("We do not have enough."); stop(); } @Override public void onPaint(Graphics2D g) { String currentTime = formatTime(System.currentTimeMillis() - startTime); testTime = (System.currentTimeMillis() - startTime) / 60000; g.drawString("CASE: " +getState(), 565, 270); g.setColor(Color.black); g.setColor(new Color(0, 0, 0, 220)); g.setColor(Color.white); if(inventory != null && myPlayer() != null) { runes2 = inventory.getAmount("Mind rune"); currentmXp = skills.getExperience(Skill.MAGIC); spellsCasted = runesStartup - runes2; mxpGained = currentmXp - startmXp; long avgxpCast = mxpGained/spellsCasted; /* * * * */ g.drawString("Time Ran: " + currentTime, 565, 285); g.drawString("Magic lvl: "+skills.getStatic(Skill.MAGIC), 565, 300); g.drawString("Magic xp: "+mxpGained, 565, 315); g.drawString("Spells casted: " +(spellsCasted), 565, 330); g.drawString("Avg xp hour: " + getExperienceTracker().getGainedXPPerHour(Skill.MAGIC), 565, 345); g.drawString("Avg xp per cast: "+avgxpCast, 565, 360); g.drawString("Avg xp start runes: "+runesStartup*avgxpCast, 565, 375); } } public final String formatTime(final long ms) { long s = ms / 1000, m = s / 60, h = m / 60; s %= 60; m %= 60; h %= 24; return String.format("%02d:%02d:%02d", h, m, s); } } Would appreciate any help. thank you! Edited October 8, 2017 by Daviyow Quote Link to comment Share on other sites More sharing options...
Deathimminent Posted October 8, 2017 Share Posted October 8, 2017 I don't have a fix to your actual issue, but one thing I noticed is you repeat a lot of the same code in your antiban switch statements. This: Spoiler public void antiBan1() throws InterruptedException { switch(random(1,60)) { case 1: if(mouse != null && myPlayer() != null) { log("Moving mouse outside of the screen"); mouse.moveOutsideScreen(); } break; case 2: if(mouse != null && myPlayer() != null) { log("Moving mouse randomly over the whole client."); mouse.move(random(0,760),(random(0,500))); } break; case 3: if(myPlayer() != null && mouse != null) { log("Moving mouse randomly on gamescreen."); mouse.move(random(20,30), random(320,485)); } break; case 4: if(mouse != null && mouse.isOnScreen() && myPlayer() != null) { log("Moving camera randomly."); camera.movePitch(random(45,67)); camera.moveYaw(random(40,350)); } break; case 5: if(mouse != null && myPlayer() != null) { log("Moving mouse outside of the screen"); mouse.moveOutsideScreen(); } break; case 6: log("Sleeping for a random time." +randomSleep); randomSleep = random(300,12000); sleep(randomSleep); break; case 7: if(mouse != null && myPlayer() != null) { log("Moving mouse outside of the screen"); mouse.moveOutsideScreen(); } break; case 8: log("Sleeping for a random time." +randomSleep); randomSleep = random(300,12000); sleep(randomSleep); break; case 9: log("Sleeping for a random time." +randomSleep); randomSleep = random(300,12000); sleep(randomSleep); break; case 10: log("Sleeping for a random time." +randomSleep); randomSleep = random(300,12000); sleep(randomSleep); break; } Can be simplified to: Spoiler switch (random(1, 60)) { case 1: case 2: case 3: if (mouse != null && myPlayer() != null) { log("Moving mouse outside of the screen"); mouse.moveOutsideScreen(); } break; case 4: if (mouse != null && myPlayer() != null) { log("Moving mouse randomly over the whole client."); mouse.move(random(0, 760), (random(0, 500))); } break; case 5: if (myPlayer() != null && mouse != null) { log("Moving mouse randomly on gamescreen."); mouse.move(random(20, 30), random(320, 485)); } break; case 6: if (mouse != null && mouse.isOnScreen() && myPlayer() != null) { log("Moving camera randomly."); camera.movePitch(random(45, 67)); camera.moveYaw(random(40, 350)); } break; case 7: case 8: case 9: case 10: log("Sleeping for a random time." + randomSleep); randomSleep = random(300, 12000); sleep(randomSleep); break; } Switch statements will "fall through" cases until a break is hit. 1 Quote Link to comment Share on other sites More sharing options...
Token Posted October 8, 2017 Share Posted October 8, 2017 @Override public void onMessage(Message m) { if (m.getMessage().contains("You do not have enough")) log("We do not have enough."); stop(); } Most likely this one. It may be easier to understand if I reformat the code properly to this @Override public void onMessage(Message m) { if (m.getMessage().contains("You do not have enough")) log("We do not have enough."); stop(); } If you don't add braces then only 1 instruction is considered to be the if block, therefore this code should stop on any message including when someone types something in public chat if your chat is not filtered. Leveling up sends 1 message in the chat behind the dialogue. 2 Quote Link to comment Share on other sites More sharing options...
Daviyow Posted October 8, 2017 Author Share Posted October 8, 2017 (edited) 20 minutes ago, Token said: @Override public void onMessage(Message m) { if (m.getMessage().contains("You do not have enough")) log("We do not have enough."); stop(); } Most likely this one. It may be easier to understand if I reformat the code properly to this @Override public void onMessage(Message m) { if (m.getMessage().contains("You do not have enough")) log("We do not have enough."); stop(); } If you don't add braces then only 1 instruction is considered to be the if block, therefore this code should stop on any message including when someone types something in public chat if your chat is not filtered. Leveling up sends 1 message in the chat behind the dialogue. Ow i thought the onMessage() only read gamechat and not public chat. anyway thanks for the information i didn't notice i hadn't put any brackets now i think this will fix it, but is there a cleaner way? @Override public void onMessage(Message m) { if (m.getMessage().contains("You do not have enough") && dialogues == null) { log("We do not have enough."); stop(); } } Edited October 8, 2017 by Daviyow Quote Link to comment Share on other sites More sharing options...
Token Posted October 8, 2017 Share Posted October 8, 2017 7 minutes ago, Daviyow said: Ow i thought the onMessage() only read gamechat and not public chat. anyway thanks for the information i didn't notice i hadn't put any brackets now i think this will fix it, but is there a cleaner way? @Override public void onMessage(Message m) { if (m.getMessage().contains("You do not have enough") && dialogues == null) { log("We do not have enough."); stop(); } } I don't see why dialogues would ever be null, that's an instance of an OSBot API class. Try to reformat your code so you have a more clear picture of what's going on in there. CTRL + SHIFT + L in Intellij or CTRL + F in eclipse. Quote Link to comment Share on other sites More sharing options...
HeyImJamie Posted October 8, 2017 Share Posted October 8, 2017 44 minutes ago, Daviyow said: Ow i thought the onMessage() only read gamechat and not public chat. anyway thanks for the information i didn't notice i hadn't put any brackets now i think this will fix it, but is there a cleaner way? @Override public void onMessage(Message m) { if (m.getMessage().contains("You do not have enough") && dialogues == null) { log("We do not have enough."); stop(); } } You can check messages by type. So game, chat, trade etc. Take a look at the API Quote Link to comment Share on other sites More sharing options...
Daviyow Posted October 8, 2017 Author Share Posted October 8, 2017 (edited) 11 minutes ago, HeyImJamie said: You can check messages by type. So game, chat, trade etc. Take a look at the API right! thanks does this look better? @Override public void onMessage(Message m) { if(chatbox.contains(MessageType.GAME, "You do not have enough")) { log("We do not have enough."); stop(); } } Edited October 8, 2017 by Daviyow Quote Link to comment Share on other sites More sharing options...
Juggles Posted October 9, 2017 Share Posted October 9, 2017 Why are you null checking dialogue? Just do getDialogue.inDialogue Quote Link to comment Share on other sites More sharing options...
whipz Posted October 10, 2017 Share Posted October 10, 2017 On 9/10/2017 at 3:26 AM, Daviyow said: right! thanks does this look better? @Override public void onMessage(Message m) { if(chatbox.contains(MessageType.GAME, "You do not have enough")) { log("We do not have enough."); stop(); } } For the level up message just do getDialouge.canContinue() returns a boolean Quote Link to comment Share on other sites More sharing options...
Daviyow Posted October 10, 2017 Author Share Posted October 10, 2017 i got it working now thank you people Quote Link to comment Share on other sites More sharing options...