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
  • GameObject returns false value


    Skinners

    Recommended Posts

    Hello there. I am creating a woodcutting / firemaking bot, but I am having some trouble when the bot is checking the current tile it is standing on.
    The setup is simple: If the value is 0 (that means that the ground is empty, and that the bot can light a bonfire) of its current tile then it creates a bonfire. 

    However, I gave the bot some time (3.5 to 3.854 seconds) to move away from where it is currently creating a bonfire to the new tile before it checks the ground again.
    The issue is that I (my self) can visible see that the ground is empty (value 0) but the script returns the value 1, which is NOT correct... Any idea how to fix this issue? 
     

    while (Inventory.contains("Oak logs", "Logs")) {
        List<GameObject> gameObjectsOnMyTile = GameObjects.all(object -> object instanceof SceneObject && object.getTile().equals(Client.getLocalPlayer().getTile()));
        log(Inventory.contains("Oak logs")); // Delete later
        log(gameObjectsOnMyTile.size()); // Delete later
        if (Inventory.contains("Oak logs") && gameObjectsOnMyTile.size() > 0) {
            log("Considering moving...");
            sleep(randomNum(3500, 3854));
            log(gameObjectsOnMyTile.size()); // Delete later
            if(Inventory.contains("Oak logs") && gameObjectsOnMyTile.size() >0) {
                log("TILE OCCUPIED, MOVING TO areaForExtraFire");
                Walking.walk(areaForExtraFire.getRandomTile());
                sleep(randomNum(1900, 2406));
            }
    Link to comment
    Share on other sites

    Don't use a while loop when the entire script is a loop, this is likely the main source of your issue. Something like the below should work, though I haven't coded in a few months

    if (Inventory.contains("Oak logs")) {
        if (Inventory.contains("Oak logs") && getTopObjectOnTile(getLocalPlayer().getTile()) == null) {
          	// light fire
         } else {
                log("TILE OCCUPIED, MOVING TO areaForExtraFire");
                Walking.walk(areaForExtraFire.getRandomTile());
                sleep(randomNum(1900, 2406));
            }
    }

     

    Link to comment
    Share on other sites

    Thanks for your reply. Unfortunately it is not working. 
    Logical: When the inventory is full I want to burn the entire inventory before I go back to woodcutting (which could be done with a While loop). This does not work with the "if" statement, because as soon 1 log have been burned, the other statement (inventory.isfull) will be false, and bot returns to woodcut. 
    Any idea to make the bot loop 27 times (27 logs to be burned) without using a while loop?

    Link to comment
    Share on other sites

    Dont forget the entire script is a loop, so this should be utilized over while loops. Just add a flag for if the inventory is full and unset it when the inventory doesnt contain logs. then use that flag to decide what to do. Each iteration through the script loop will check `FM` and adjust to WC/FM. 

     

            boolean fm;
            if (!Inventory.contains((i) -> i != null && i.getName().toLowerCase().contains("logs")))
                fm = false;
            else
                fm = true;
    
            if (fm) {
                doFiremaking(); // Firemaking logic here
            } else {
                doWoodcutting();  //Woodcutting logic here
            }

     

     

    Link to comment
    Share on other sites

    Thanks for reply.
    I have now changed everything from "while" to "if" statements and implemented flags.

    However, the issue still maintain. The Wrappers "GameObject" still returns values greater than 0, eventho there is nothing on the ground.

    Link to comment
    Share on other sites

    Try something like Stoned said around `GameObjects.getObjectsOnTile(Players.localPlayer().getTile())` Which will return you a list of the items on your current players tile and then print them out to see what is causing the size to be > 0  (This can be done via

    for(GameObject g: GameObjects.getObjectsOnTile(Players.localPlayer().getTile()))
        MethodProvider.logInfo(g.getName());

    Once you know whats causing a size > 0 then we can adjust the filter to return correctly

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • 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.