Zenarchist 40 Share Posted August 21, 2018 Hey guys, I'm new to Dreambot (but not Java) and am just wondering what is considered best practice for making your script handle world hopping and logouts? The problem I am having is that sometimes when my character logs out or world hops, this inventory.count() == 0 guard clause returns true and stops my script: // If our player model hasn't loaded or we are logged out, wait. if(!getLocalPlayer().exists() || !getClient().isLoggedIn()) return Calculations.random(3000, 6000); // Check that we have a net if(getInventory().count(303) == 0) { stop(); log("Error - No net!"); return 1; } Any ideas why the first check isn't stopping my script from prematurely performing the second check on my inventory when my character isn't logged in yet / my inventory hasn't loaded? This only happens rarely and if I run the script for a long time, and I do use VPNs, so I believe random lag/disconnection is probably a factor. But what are your guys' methods for handling this type of situation? Am I missing something? Thanks heaps! Regards, Zen Link to comment Share on other sites More sharing options...
sadgonzer 46 Share Posted August 21, 2018 you wanna give it an extra check something like that if(getInventory().count(303) ==0&&getClient().isLoggedIn()) { stop(); log("Error - No net!"); return 1; } so it wont stop script unless it has no net and account is already logged in.... that solution might not be ideal tho but itll work Feel free to add me on discord or ask me here for any more help Link to comment Share on other sites More sharing options...
Zenarchist 40 Author Share Posted August 21, 2018 Ahhh good idea man, I didn't think of trying that. Cheers bro! I'll give it a go and let you know if it fixes the problem And thanks for the offer, I might take you up on that sometime. I could use some occasional advice from an experienced Dreambotter, I'm super rusty with bot apis (and osrs for that matter lol) Link to comment Share on other sites More sharing options...
sadgonzer 46 Share Posted August 21, 2018 with pleasure Link to comment Share on other sites More sharing options...
Miami 369 7 Share Posted August 21, 2018 you can use GameState, https://dreambot.org/javadocs/org/dreambot/api/data/GameState.html you would use getClient().getGameState() Link to comment Share on other sites More sharing options...
ArmyofDragons 28 Share Posted August 21, 2018 Or you can just do this... the simplest trick in the book: while(getLocalPlayer() == null) { sleep(1000, 1500); } getLocalPlayer() is always null if the Player is logged out. Link to comment Share on other sites More sharing options...
Hashtag 8694 Share Posted August 21, 2018 Using a while loop is not a good practice in scripts, unless you're breaking from the loop when the script is stopped/paused. Link to comment Share on other sites More sharing options...
Zenarchist 40 Author Share Posted August 23, 2018 Thanks a lot for the tips guys! I really appreciate it. like how helpful this community is, it's one of the reasons I came back to OSRS botting even though I don't really game anymore haha. It's great fun! I tried sadgonzer's suggestion last night but it didn't help. I could easily move the check into onStart() and it will not be a problem, but then if I bug out and drop my net (has never happened to me but I like to prepare for everything), the bot is going to just stand there logging in and out for hours lol. Guaranteed banhammer. Anyway thanks for the tips Miami 369 & ArmyofDragons, I'll definitely look into that. And great advice Hashtag, nothing is worse than stopping your script and it gets stuck in a loop moving your mouse around and you need to restart the bot lol. Surely one of these methods will work, I'll get experimenting and let you guys know if I sort it out. Cheers! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.