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
  • Try asking for help in the chatbox
  • mcleod63

    • Posts

    • Joined

    • Last visited

    mcleod63's Achievements

    1. Thanks hashbang. I tried that but Players.getLocal() isn't null, so I repeatedly got NPEs by executing the Players.getLocal().getLevel() line inside the loop. I imagine jagex will pick up on this quickly and ban me, if I can't solve my problem soon. I also tried a loop with Client.isLoggedIn but found that I was always logged in, so passed by the while loop, and still got the NPEs when I tried to set the combat level. int count = 0; while (!Client.isLoggedIn()) { sleep(10000); count++; if (count >= 12) stop(); } Does anyone have any other ideas I can try? I've exhausted my small bit of DB3 knowledge, and tried to find answers in both the forum and Javadocs but failed.
    2. Can someone explain why I can't get Players.getLocal().getLevel(); to work in onStart(). It immediately throws an NPE error. I wrote a simple script, with lots of logs, to confirm it's not my node system: import org.dreambot.api.methods.Calculations; import org.dreambot.api.methods.container.impl.Inventory; import org.dreambot.api.methods.container.impl.bank.Bank; import org.dreambot.api.methods.interactive.Players; import org.dreambot.api.methods.tabs.Tab; import org.dreambot.api.methods.tabs.Tabs; import org.dreambot.api.script.AbstractScript; import org.dreambot.api.script.Category; import org.dreambot.api.script.ScriptManager; import org.dreambot.api.script.ScriptManifest; import org.dreambot.api.utilities.Sleep; @ScriptManifest(description = "Testing why combat level causing errors.", name = "TestDB", version = 1.0, author = "NAD", category = Category.MISC) public class Main extends AbstractScript { public static int combatLevel = 0; @Override public void onStart() { log("--- Script has started ---"); //combatLevel = Players.getLocal().getLevel(); // <--- throws errors log("#1 combat level: " + combatLevel); // was set to 0 when declared if (Players.getLocal() != null) { combatLevel = Players.getLocal().getLevel(); log("#2 combat level is now " + combatLevel); } else { log("#2 getLocal() is null, combat level is " + combatLevel); } if (combatLevel == 0) { // it shouldn't be but just checking combatLevel = 1; // must assign a value else crashes later in Fighter program log("#3 should never get here,combat level is " + combatLevel); } else { log("#3 combat level should have the correct value: " + combatLevel); } } @Override public int onLoop() { // A simple code to walk to the bank. if (Bank.open()) { log("Arrived at the bank."); if (!Tabs.isOpen(Tab.INVENTORY)) { if (Tabs.openWithMouse(Tab.INVENTORY)) { Sleep.sleepUntil(() -> Tabs.isOpen(Tab.INVENTORY), 3000); } } if (!Inventory.isEmpty()) { Bank.depositAllItems(); Sleep.sleepUntil(Inventory::isEmpty, 3000); } Sleep.sleep(250, 350); ScriptManager.getScriptManager().stop(); sleep(3000); // need a few seconds for stop() to kick in } else { log("Walking to the bank."); sleep(2500, 3500); } return Calculations.random(350, 500); } } And here's the error: The NPE occurs at line 31 in onStart, where I do a null check and then try to set the combatLevel variable ?? I'm confused. Players.getLocal() is not null, and getLevel() is an int, so where is the null pointer exception coming from? More importantly, how do I fix it? Can it be that onStart runs before the client is fully up to speed? I did try insertiing a 2 minute sleep before setting the combat level, but that didn't fix it. Any assistance would be greatly appreciated.
    3. I'm slowly working on a method to handle random events and this is a great help. Thank you for the contribution.
    4. Just a quick update. This one solved my issue. Thanks again for the helpful responses! Player player = Players.getLocal(); if (player != null) { g.drawString("Combat Level: " + player.getLevel(), 10, 90); }
    5. Oh no, I fell for the 'failed to do a null check"' thing. Thank you both for the responses. Must remember null checks. Must remember null checks. Must remember null checks.
    6. Hi, can anyone help me understand why my Paint is throwing errors? The error appears to be caused by Players.getLocal().getLevel() throwing errors until the login handler has finished. I say this because the logs show login handler starting, and then repetitive errors pointing to my codeline 143, and the errors stop as soon as the log shows that the login handler finished. I can show the log entries if that will help. This is line 143 in my code: g.drawString("Combat skill level: " + Players.getLocal().getLevel(), 10, 135); I recently returned to botting after taking a 1-2 year break, so I had to update my scripts for the deprecated items since I last played. That included changing getLocalPlayer().getLevel() to Players.getLocal().getLevel() but I don't see how that is the problem. Any help would be appreciated.
    • 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.