Nosta 0 Share Posted October 3, 2020 Hey! I'm new to botting and I'm trying to make a Firemaking bot. I'm currently stuck at checking if the tile which I am standing on contains a "Fire". To check this, I'd like to refer to the tile that GetLocalPlayer() is currently standing on, but I cannot find it in the documentation? How do I get the tile which GetLocalPlayer() is standing on? Shouldn't it be something like this?: new Tile tile = Tile.getLocalPlayer(); Thanks for any insight you might be able to provide me with! Have a great day Link to comment Share on other sites More sharing options...
Uplift 7 Share Posted October 3, 2020 No offense, but I think you need to go and learn the basics of Java. Once you have a grasp on that you'll be able to figure out what is wrong with that line. Link to comment Share on other sites More sharing options...
Nosta 0 Author Share Posted October 3, 2020 Hi Uplift, thank you for the reply, I actually enjoy learning the basics of Java like this. I'll post an update here, this is what I've got so far: case FIREMAKINGFIRST: playerTile = getLocalPlayer().getTile(); GameObjects[] objectList = {getObjectsOnTile(playerTile)}; for(int i = 0; i < Objects.length; i++) { if (Objects[i].getName().equals("Fire")) { //Move to another tile, this one already has a fire. } } break; Obviously it's not functional yet I still need to bend the words right, so to say hehe. Feel free to help me out 😇 Link to comment Share on other sites More sharing options...
Uplift 7 Share Posted October 3, 2020 for(int i = 0; i < Objects.length; i++) { Objects has not been defined, unless it is defined outside of your scope you've shown if (Objects[i].getName().equals("Fire")) { Objects is not an array, as above it's not decleared. GameObjects[] objectList = {getObjectsOnTile(playerTile)}; I'm assuming getObjectsOnTile is supposed to return an array, so you shouldn't have to put it in, otherwise if it is returning one Object the array length will always be one and defeats the purpose playerTile = getLocalPlayer().getTile(); Has playerTile been decleared out of what you've shown? Are you using an IDE? It should be telling you those errors? Link to comment Share on other sites More sharing options...
Nosta 0 Author Share Posted October 3, 2020 Hi again Uplift, thank you for your elaborate responce! Following your suggestions and notes I've learned a lot and got it to work! Thank you once again mate As to your question, yes, playerTile is declared further up in my code 😇 Here is the working code: case FIREMAKINGFIRST: playerTile = getLocalPlayer().getTile(); GameObject[] objectList = GameObjects.getObjectsOnTile(playerTile); for(int i = 0; i < objectList.length; i++) { if (objectList[i].getName().equals("Fire")) { //Move to another tile, this one already has a fire. } } break; I saw you also responded to my question in the normal chat on the front page of the site, thank you for this also. If you PM me your paypal I'll gladly tip you for your time! Have a great day. Link to comment Share on other sites More sharing options...
Uplift 7 Share Posted October 3, 2020 6 minutes ago, Nosta said: Hi again Uplift, thank you for your elaborate responce! Following your suggestions and notes I've learned a lot and got it to work! Thank you once again mate As to your question, yes, playerTile is declared further up in my code 😇 Here is the working code: case FIREMAKINGFIRST: playerTile = getLocalPlayer().getTile(); GameObject[] objectList = GameObjects.getObjectsOnTile(playerTile); for(int i = 0; i < objectList.length; i++) { if (objectList[i].getName().equals("Fire")) { //Move to another tile, this one already has a fire. } } break; I saw you also responded to my question in the normal chat on the front page of the site, thank you for this also. If you PM me your paypal I'll gladly tip you for your time! Have a great day. That looks much better. Good job! Link to comment Share on other sites More sharing options...
TheCloakdOne 389 Share Posted October 3, 2020 if you wanted to use lambdas you could also simplify the code to this: Tile lpt = Players.localPlayer().getTile(); boolean fireOnTile = GameObjects.closest((g) -> g != null && g.getTile().equals(lpt) && g.getName().equals("Fire")) != null; if (fireOnTile) { //Move } // Tile is ok Link to comment Share on other sites More sharing options...
Nosta 0 Author Share Posted October 3, 2020 Hi TheCloakedOne, thank you for the responce! I've further improved my code with your suggestions, thank you so much! I've got one question in responce, at the end of the lambdas it says && f.getName().equals("Fire")) != null; What does the !=null here do? Does it check if "GameObjects.closest" is not equal to null just as we check if "f" is not equal to null? I'm very thankful for the responces! Thanks you guys case FIREMAKINGFIRST: log("Making 1 Fire"); playerTile = getLocalPlayer().getTile(); boolean fireOnTile = GameObjects.closest((f) -> f != null && f.getTile().equals(playerTile) && f.getName().equals("Fire")) != null; GameObject[] objectList = GameObjects.getObjectsOnTile(playerTile); if (fireOnTile) { log("Tile not occupied - lighting fire"); if(!Tabs.isOpen(Tab.INVENTORY)){ Tabs.openWithMouse(Tab.INVENTORY); } Inventory.interact("Tinderbox", "Use"); sleep(randomNum(500, 1000)); Inventory.interact("Logs", "Use"); sleep(randomNum(1000, 1500)); log("Waiting for the logs to be lighted, program will wait 25-30 seconds for this to succeed."); sleepUntil(() -> !getLocalPlayer().isAnimating(), randomNum(25000, 30000)); } log("Tile occupied, moving to new tile"); Walking.walk(fireMakingArea.getRandomTile()); sleep(randomNum(1000, 1500)); //Wait for player to start moving sleepUntil(() -> !getLocalPlayer().isMoving(), randomNum(5000,7000)); break; Link to comment Share on other sites More sharing options...
TheCloakdOne 389 Share Posted October 3, 2020 So `fireOnTile` should return false when there are no (aka null) fires on the players tile so we have just inversed that logic. Ive adjusted your code slightly to ensure its checking the correct object, things i would suggest you could look at improving would be: * Most dreambot methods return a boolean to say if the action was performed or not (like Inventory.interact) so you should add in checks to ensure when your interacting with the tinderbox/logs it was successful before continuing. * You can check if the tinderbox is selected with Inventory.isItemSelected() * random sleeps arent great as you cant gaurentee the action has completed within that random time, try and use sleepUntil wherever you can for a more fluid script * Try breaking each "case" block into its own function, it will help maintain readabilty as your script gets larger when using switch loops case FIREMAKINGFIRST: log("Making 1 Fire"); playerTile = getLocalPlayer().getTile(); boolean fireOnTile = GameObjects.closest((f) -> f != null && f.getTile().equals(playerTile) && f.getName().equals("Fire")) != null; if (fireOnTile) { //If there is a fire on the tile, lets move away log("Tile occupied, moving to new tile"); Walking.walk(fireMakingArea.getRandomTile()); sleepUntil(() -> getLocalPlayer().isMoving(), randomNum(1000,1500)); //Wait until we are moving sleepUntil(() -> !getLocalPlayer().isMoving(), randomNum(5000,7000)); //Wait until we are no longer moving } log("Tile not occupied - lighting fire"); if(!Tabs.isOpen(Tab.INVENTORY)){ Tabs.openWithMouse(Tab.INVENTORY); } Inventory.interact("Tinderbox", "Use"); sleep(randomNum(500, 1000)); Inventory.interact("Logs", "Use"); sleep(randomNum(1000, 1500)); log("Waiting for the logs to be lighted, program will wait 25-30 seconds for this to succeed."); sleepUntil(() -> !getLocalPlayer().isAnimating(), randomNum(25000, 30000)); break; Link to comment Share on other sites More sharing options...
Nosta 0 Author Share Posted October 3, 2020 Thank you so much for the elaborate responce TheCloakdOne! 💙 I learned so much from your input and I've ajusted my code as to your suggestions: *I'm now using a boolean check to see if I completed the action that I wanted. *I converted the Case to a Function, enabling me to run it from outside the function/case and re-use the code. public void lightFireSingle() { while(true) { log("lightFireSingle runs"); if(!Inventory.contains("Logs")){ log("Stopped lightFireSingle from running, no logs found in inventory."); break; } shouldBreak = false; log("Making 1 Fire"); playerTile = getLocalPlayer().getTile(); boolean fireOnTile = GameObjects.closest((f) -> f != null && f.getTile().equals(playerTile) && f.getName().equals("Fire")) != null; if (fireOnTile) { log("Tile occupied, moving to new tile"); Walking.walk(fireMakingArea.getRandomTile()); sleepUntil(() -> getLocalPlayer().isMoving(), randomNum(1000, 1500)); sleepUntil(() -> !getLocalPlayer().isMoving(), randomNum(5000,7000)); shouldBreak = false; } log("Tile not occupied - lighting fire"); if(!Tabs.isOpen(Tab.INVENTORY)){ Tabs.openWithMouse(Tab.INVENTORY); } Inventory.interact("Tinderbox", "Use"); sleep(randomNum(1000, 1500)); selectionComplete = Inventory.isItemSelected(); if(selectionComplete) { log("Successfully selected Tinderbox to use."); Inventory.interact("Logs", "Use"); log("Waiting for the logs to be lighted, program will wait 25-30 seconds for this to succeed."); sleepUntil(() -> !getLocalPlayer().isAnimating(), randomNum(25000, 30000)); if(!getLocalPlayer().isAnimating()) { shouldBreak = true; } }else { log("Did not select Tinderbox successfully."); shouldBreak = false; } if(shouldBreak == true) { break; } } } If you don't mind me tipping you for your time, please PM me your paypal and I'll send you a gift for helping me to learn Thanks once again! I really appreciate it! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.