Miammoai 0 Share Posted May 21, 2018 Code: import java.awt.Graphics; import org.dreambot.api.methods.Calculations; import org.dreambot.api.script.AbstractScript; import org.dreambot.api.script.ScriptManifest; import org.dreambot.api.script.Category; import org.dreambot.api.wrappers.interactive.NPC; import org.dreambot.api.wrappers.items.Item; import org.dreambot.server.net.datatype.GetWorldsData; import org.dreambot.api.methods.container.impl.Shop; import org.dreambot.api.methods.world.World; import org.dreambot.api.methods.container.impl.Inventory; @ScriptManifest(author = "Test", name = "Bolt shop script", version = 0.1, description = "Simple woord cutter", category = Category.WOODCUTTING) public class wc extends AbstractScript { int state = 1; @Override public void onStart() { log("onStart"); } @Override public int onLoop() { if(state == 1) { log("state 1"); if(!getLocalPlayer().isAnimating() && !getLocalPlayer().isMoving()) { NPC shop = getNpcs().closest("Lowe"); if(shop != null && shop.isOnScreen()) { shop.interact("Trade"); sleepUntil(() -> getShop().isOpen(), Calculations.random(2000, 6000)); state++; } } } if(state == 2) { log("state 2"); if (getShop().isOpen()) { Item bolt = getShop().get("Bronze Bolts"); if(bolt != null) { if(bolt.getAmount() >34) { getShop().purchase(bolt, 50); Calculations.random(50, 250); } else { state++; } } else { log("bolt = null"); } } else { state--; } } if(state == 3) { log("state 3"); if (getShop().isOpen()) { getShop().close(); Calculations.random(600, 5000); } Calculations.random(350, 600); World e = getWorlds().getRandomWorld(w -> w !=null && !w.isDeadmanMode() && !w.isF2P() && !w.isHighRisk() && !w.isLastManStanding() && !w.isPVP() && w.isMembers() && !w.equals(getClient().getCurrentWorld()) && w.getID() != 353 && w.getID() != 366 && w.getID() != 373 && w.getID() != 349 && w.getID() != 361); log("GETWORLD"); log(e.toString()); if(!getLocalPlayer().isInCombat()) { getWorldHopper().hopWorld(e); sleep(Calculations.random(1000, 2000)); log("hopped world"); } state = 1; sleep(Calculations.random(3000, 10000)); log("back to state 1"); //int currentworld = getClient().getCurrentWorld(); //World hopworld = getWorlds().getWorld(currentworld+1); //if (hopworld.isHighRisk() || hopworld) //World randWorld = getWorlds().getRandomWorld(); //if (randWorld.isHighRisk() || randWorld.isPVP() || randWorld.isF2P() || randWorld.getMinimumLevel() > 100) { // randWorld = getWorlds().getRandomWorld(); //} //getWorldHopper().hopWorld(randWorld); } return Calculations.random(100, 300); } @Override public void onExit() { log("onExit"); } @Override public void onPaint(Graphics graphics) { super.onPaint(graphics); } } Screenshot: http://prntscr.com/jklkd4 Details: It works well for 1 or two world hops. Suddenly it just stops buying. If you hover the mouse manually over the bot item it sometimes starts working again. Any idea what is causing this / how I can improve it ? Also for some reason debugging options don't work for me. So i can't see the mouse click location etc (so i have no idea how random this is / how detectable the clicks are). Link to comment Share on other sites More sharing options...
Hashtag 8697 Share Posted May 22, 2018 I'm sure if you replaced your states with the structure below, you'd get it working. int onLoop() { if (getInventory().isFull()) { // bank } else if (getShop().isOpen()) { if (getShop().count("Bolts") > 34) { // buy bolts } else { // world hop } } else { // open shop } } Link to comment Share on other sites More sharing options...
Miammoai 0 Author Share Posted May 22, 2018 Thanks for the tip, I'll try it tomorrow. Note when it "fails" buying the shop window is open and it has bought before and it is in the correct state. But let's see if this works better Link to comment Share on other sites More sharing options...
Miammoai 0 Author Share Posted May 23, 2018 As i kinda suspected I still get the get.purchase fail. http://prntscr.com/jlshxe import java.awt.Graphics; import org.dreambot.api.methods.Calculations; import org.dreambot.api.script.AbstractScript; import org.dreambot.api.script.ScriptManifest; import org.dreambot.api.script.Category; import org.dreambot.api.wrappers.interactive.NPC; import org.dreambot.api.wrappers.items.Item; import org.dreambot.server.net.datatype.GetWorldsData; import org.dreambot.api.methods.container.impl.Shop; import org.dreambot.api.methods.world.World; import org.dreambot.api.methods.container.impl.Inventory; @ScriptManifest(author = "Test", name = "Bolt shop script", version = 0.1, description = "Simple woord cutter", category = Category.WOODCUTTING) public class wc extends AbstractScript { @Override public void onStart() { log("onStart"); } @Override public int onLoop() { if (getInventory().isFull()) { // bank log("inventory is full"); } else if (getShop().isOpen()) { Item bolt = getShop().get("Bronze Bolts"); if (bolt.getAmount() >34) { // buy bolts log("has enough bolts"); getShop().purchase(bolt, 50); Calculations.random(50, 250); } else { // world hop if (getShop().isOpen()) { getShop().close(); Calculations.random(600, 5000); } Calculations.random(350, 600); World e = getWorlds().getRandomWorld(w -> w !=null && !w.isDeadmanMode() && !w.isF2P() && !w.isHighRisk() && !w.isLastManStanding() && !w.isPVP() && w.isMembers() && !w.equals(getClient().getCurrentWorld()) && w.getID() != 353 && w.getID() != 366 && w.getID() != 373 && w.getID() != 349 && w.getID() != 361); log("GETWORLD"); log(e.toString()); if(!getLocalPlayer().isInCombat()) { getWorldHopper().hopWorld(e); sleep(Calculations.random(1000, 2000)); log("hopped world"); } sleep(Calculations.random(3000, 10000)); } } else { // open shop if(!getLocalPlayer().isAnimating() && !getLocalPlayer().isMoving()) { NPC shop = getNpcs().closest("Lowe"); if(shop != null && shop.isOnScreen()) { shop.interact("Trade"); sleepUntil(() -> getShop().isOpen(), Calculations.random(2000, 6000)); } } } return Calculations.random(100, 300); } @Override public void onExit() { log("onExit"); } @Override public void onPaint(Graphics graphics) { super.onPaint(graphics); } } Closing the shop and opening it again fixes it. So is it possible that the ID of the item suddenly changes or something like that ? Link to comment Share on other sites More sharing options...
Miammoai 0 Author Share Posted May 24, 2018 I managed to temporary fix the buying failure. Simply if it takes too long to buy it close the shop and try again. Not it keeps working. Also added world hopping to the next world based on a world array i made. I know it is a shitty method but i could not figure out how to work the world filter Also added checking if the player has enough money in the inventory. if not log out. It is far from perfect but ... it works so far. Have bought around 500k bronze bolts now and it is going well import java.awt.Graphics; import org.dreambot.api.methods.Calculations; import org.dreambot.api.script.AbstractScript; import org.dreambot.api.script.ScriptManifest; import org.dreambot.api.script.Category; import org.dreambot.api.wrappers.interactive.NPC; import org.dreambot.api.wrappers.items.Item; @ScriptManifest(author = "Cool baby", name = "Bolt shop script", version = 0.1, description = "Easy Money Maker", category = Category.MONEYMAKING) public class wc extends AbstractScript { public int getArrayIndex(int[] arr,int value) { for(int i=0;i<arr.length;i++) if(arr[i]==value) return i; return -1; } int count = 0; int i = 0; int w = 0; int world_arr[] = { 301,302,303,304,305,306,307,309,310,311,312,313,314,315,317,318,319, 320,321,322,323,326,327,328,329,330,331,332,333,334,335,336,338, 339,340,341,342,343,344,346,347,348,350,351,352,354,355,356,357,358, 359,360,362,367,368,370,374,375,376,377,378,382,383,384,386,387,388, 389,390,393,394}; @Override public void onStart() { log("onStart"); int world = getClient().getCurrentWorld(); log("current world W"+world); w = getArrayIndex(world_arr,world); log("w index"+w); w++; log("next world W"+world_arr[w]); /*if(world_arr[w] != getClient().getCurrentWorld()) { getWorldHopper().hopWorld(world_arr[w]); Calculations.random(3000, 6000); w++; }*/ } @Override public int onLoop() { if (getInventory().isFull() || getInventory().count("Coins") <= 5000) { // bank log("inventory is full"); getShop().close(); sleep(Calculations.random(1000, 2000)); getTabs().logout(); Calculations.random(3000, 6000); stop(); } else if (getShop().isOpen()) { Item bolt = getShop().get("Bronze Bolts"); if (bolt.getAmount() >34) { // buy bolts log("has enough bolts"); count = bolt.getAmount(); getShop().purchase(bolt, 50); Calculations.random(700, 800); if(bolt.getAmount() == count) { //no bolts were bought over 5 tries //close shop and try again i++; log(""+i); if(i > 35) { //tried 5 times , close shop and try again getShop().close(); Calculations.random(300, 600); i = 0; } } } else { log("world hop"); // world hop if (getShop().isOpen()) { log("step 1"); getShop().close(); Calculations.random(600, 5000); } log("hop world W"+world_arr[w]); if(!getLocalPlayer().isInCombat()) { getWorldHopper().hopWorld(world_arr[w]); sleep(Calculations.random(1000, 2000)); log("hopped world"); if(world_arr[w] == 394) { w = 0; } else { w++; } } sleep(Calculations.random(3000, 10000)); i = 0; } } else { // open shop if(!getLocalPlayer().isAnimating() && !getLocalPlayer().isMoving()) { NPC shop = getNpcs().closest("Lowe"); if(shop != null && shop.isOnScreen()) { shop.interact("Trade"); sleepUntil(() -> getShop().isOpen(), Calculations.random(2000, 6000)); i = 0; } } } return Calculations.random(100, 300); } @Override public void onExit() { log("onExit"); } @Override public void onPaint(Graphics graphics) { super.onPaint(graphics); } } Things I still want to add / fix: 1. Grabbing the world array using the filter method 2. Finding a proper way to fix the not buying issue 3. Adding (basic) graphics 4. Buying more items (which make sense financially) Any tips or help is appreciated. Link to comment Share on other sites More sharing options...
qwAQ 17 Share Posted May 24, 2018 @Miammoai I have not read your code above, but you should definitely look into the Worlds class. It gives you a list of the worlds, so you don't have to manually make an array like you've done in the post above. An example is following: World randomF2pNonPvpWorld = getWorlds().getRandomWorld(w -> f2pWorlds.contains(w) && !pvpWorlds.contains(w)); Then you simply do following to get the world id: int worldID = randomF2pNonPvpWorld.getID(); Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.