Popymon24 Posted July 29, 2016 Share Posted July 29, 2016 I wanted to make a script for OSBot, and decided that I wanted to make a script that fished at barbarian village and also cook the fish before dropping them. When I got to making the cooking part, I got stuck because I couldn't use interact on the fire like I could the fishing spots. Any help or touchups of what I have done are gladly welcomed! import org.osbot.rs07.api.model.Entity; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import java.awt.*; @ScriptManifest(author = "You", info = "My first script", name = "Tea thiever", version = 0, logo = "") public class main extends Script { @Override public void onStart() { log("Let's get started!"); } private enum State { FISH, COOK, DROP }; private State getState() { Entity fishingSpot = objects.closest("Fishing Spot"); if(inventory.isEmptyExcept(123)) return State.FISH; Entity fire = objects.closest("fire"); if(inventory.isFull()) return State.COOK; return State.DROP; } @Override public int onLoop() throws InterruptedException { switch(getState()){ case FISH: Entity fishingSpot = objects.closest("Fishing Spot"); fishingSpot.interact("Lure"); break; case COOK: Entity fire = objects.closest("fire"); fire.interact("Cook") break; case DROP: inventory.dropAll(331, 332, 333, 334, 25976); break; } return random(200, 300); } @Override public void onExit() { log("Thanks for running my Tea Thiever!"); } @Override public void onPaint(Graphics2D g) { } } Quote Link to comment Share on other sites More sharing options...
Deceiver Posted July 29, 2016 Share Posted July 29, 2016 (edited) fishing spot is npc, change ur code to npc objects are blue text when right clicked npcs are yellow Edited July 29, 2016 by deceiver 1 Quote Link to comment Share on other sites More sharing options...
Popymon24 Posted July 29, 2016 Author Share Posted July 29, 2016 fishing spot is npc, change ur code to npc objects are blue text when right clicked npcs are yellow But to cook on the fire you need to select the item you want to cook then use it on the fire. Also, how would I do this until my inventory is empty? Can you provide some example code? Quote Link to comment Share on other sites More sharing options...
Deceiver Posted July 29, 2016 Share Posted July 29, 2016 http://osbot.org/api/org/osbot/rs07/api/Inventory.html and just sleep until your inventory is full 1 Quote Link to comment Share on other sites More sharing options...
Popymon24 Posted July 29, 2016 Author Share Posted July 29, 2016 http://osbot.org/api/org/osbot/rs07/api/Inventory.html and just sleep until your inventory is full I'm sorry for being such a noob, but I don't see anything to select an item. What would do that? Quote Link to comment Share on other sites More sharing options...
Juggles Posted July 29, 2016 Share Posted July 29, 2016 (edited) To select item, use: inventory.interact("Use", "Name of Fish"); Use on the fire. I think fire is an object? Not sure I have never cooked. getObject.closest("Name of whatever fire is").interact("Use"); You can use a widget to cook if (getWidget.isVisible(#,#) { getWidgets().interact(#,# "Cooked All"); } And what do you mean until inventory is empty? Like when you drop after cooking? getInventory.dropAllExcept("Fishing rod Name"); Edited July 29, 2016 by lg_juggles Quote Link to comment Share on other sites More sharing options...
Popymon24 Posted July 29, 2016 Author Share Posted July 29, 2016 To select item, use: inventory.interact("Use", "Name of Fish"); Use on the fire. I think fire is an object? Not sure I have never cooked. getObject.closest("Name of whatever fire is").interact("Use"); And what do you mean until inventory is empty? Like when you drop after cooking? getInventory.dropAllExcept("Fishing rod Name"); I meant until all the fish were cooked. Thank you so much! Quote Link to comment Share on other sites More sharing options...
Juggles Posted July 29, 2016 Share Posted July 29, 2016 (edited) I meant until all the fish were cooked. Thank you so much! You want to sleep until inventory contains 27 cooked fish (fishing rod is 1 space) or until you are in dialogue from leveling up. new ConditionalSleep(60000) { @Override public boolean condition() throws InterruptedException { return getInventory.getAmount("Name of fish")>=27 || getDialogue.inDialogue; } }.sleep(); You can use a widget to cook if (getWidget.isVisible(#,#) { getWidgets().interact(#,# "Cooked All"); } Edited July 29, 2016 by lg_juggles 1 Quote Link to comment Share on other sites More sharing options...
Popymon24 Posted July 29, 2016 Author Share Posted July 29, 2016 You want to sleep until inventory contains 27 cooked fish (fishing rod is 1 space) or until you are in dialogue from leveling up. new ConditionalSleep(60000) { @Override public boolean condition() throws InterruptedException { return getInventory.getAmount("Name of fish")>=27 || getDialogue.inDialogue; } }.sleep(); You can use a widget to cook if (getWidget.isVisible(#,#) { getWidgets().interact(#,# "Cooked All"); } I have no idea how to use widgets. This is my first script, I've barely ever programmed before, and only in C#. Quote Link to comment Share on other sites More sharing options...
Juggles Posted July 29, 2016 Share Posted July 29, 2016 Settings<Options<Debug<Tick Widgets on Now when you hover over things, it will give you numbers from a box.Find the #s it gives you and use them in if (getWidget.isVisible(#,#)) { getWidgets().interact(#,# "Cooked All"); } Quote Link to comment Share on other sites More sharing options...
Popymon24 Posted July 29, 2016 Author Share Posted July 29, 2016 Settings<Options<Debug<Tick Widgets on Now when you hover over things, it will give you numbers from a box. Find the #s it gives you and use them in if (getWidget.isVisible(#,#)) { getWidgets().interact(#,# "Cooked All"); } The getWidgets and getWidget both have red lined underneath. Quote Link to comment Share on other sites More sharing options...
Juggles Posted July 29, 2016 Share Posted July 29, 2016 (edited) The getWidgets and getWidget both have red lined underneath. add this import import org.osbot.rs07.api.ui.RS2Widget; I code on Mac so this is what I do Whenever something is red, see if you need to add the import. Click on the red line, hold Option(ALT on windows?) and press enter it will add the import. Edited July 29, 2016 by lg_juggles Quote Link to comment Share on other sites More sharing options...
Popymon24 Posted July 29, 2016 Author Share Posted July 29, 2016 (edited) add this import import org.osbot.rs07.api.ui.RS2Widget; I code on Mac so this is what I do Whenever something is red, see if you need to add the import. Click on the red line, hold Option(ALT on windows?) and press enter it will add the import. i already had it imported. This is my code for the COOK state: case COOK: Entity fire = objects.closest("fire"); inventory.interact("Use", "Trout"); fire.interact("Use"); if (getWidget.isVisible(307,2)) { getWidgets().interact(307,2 "Cooked All"); } break; getWidget, interact, and "Cooked all" both have red lines. It is supposed to recognize the fire, select the trout, right click and click use on the fire, see if the widget is available, then select cook all. i already had it imported. This is my code for the COOK state: case COOK: Entity fire = objects.closest("fire"); inventory.interact("Use", "Trout"); fire.interact("Use"); if (getWidget.isVisible(307,2)) { getWidgets().interact(307,2 "Cooked All"); } break; getWidget, interact, and "Cooked all" both have red lines. It is supposed to recognize the fire, select the trout, right click and click use on the fire, see if the widget is available, then select cook all. I fixed the code. RS2Widget cookMenu = widgets.get(307,4); if(cookMenu != null && cookMenu.isVisible()) cookMenu.interact("Cook All"); I compiled it, and it does nothing. Here's my code: import org.osbot.rs07.api.model.Entity; import org.osbot.rs07.api.ui.RS2Widget; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import java.awt.*; @ScriptManifest(author = "You", info = "My first script", name = "Tea thiever", version = 0, logo = "") public class main extends Script { @Override public void onStart() { log("Let's get started!"); } private enum State { FISH, COOK, DROP }; private State getState() { if(inventory.isEmptyExcept(310, 17794, 309, 17795, 123, 17796)) return State.FISH; if(inventory.isFull()) return State.COOK; return State.DROP; } @Override public int onLoop() throws InterruptedException { switch(getState()){ case FISH: Entity fishingSpot = objects.closest("Fishing Spot"); fishingSpot.interact("Lure"); break; case COOK: Entity fire = objects.closest("fire"); inventory.interact("Use", "Trout"); fire.interact("Use"); RS2Widget cookMenu = widgets.get(307,4); if(cookMenu != null && cookMenu.isVisible()) cookMenu.interact("Cook All"); break; case DROP: inventory.dropAll(331, 332, 333, 334, 25976); break; } return random(200, 300); } @Override public void onExit() { log("Thanks for running my first script!"); } @Override public void onPaint(Graphics2D g) { } } Edited July 29, 2016 by Popymon24 Quote Link to comment Share on other sites More sharing options...
Muffins Posted July 29, 2016 Share Posted July 29, 2016 learn some basic java before attempting to write a script, we aren't here to write the full thing for you. you can't just copy and paste a tutorial skeleton and change a few things and expect it to work. 3 Quote Link to comment Share on other sites More sharing options...
Juggles Posted July 29, 2016 Share Posted July 29, 2016 (edited) 1) Few problems in your script, it will keep clicking the fishing spot bc you aren't checking if you are fishing. Check if your player is animating or not for this. 2) YOu don't check if you've done the previous steps, you will just keep looping non stop. 3) You're missing brackets on your widgets 4) Why are you dropping 4 items? 5) Your script literally is just linear right now. Look into conditional sleeps and using if/else statements to check if you're doing an action. 6) Do the first few modules Code Academy to learn the basics of Java first. It will help you in the long wrong. 7) Use pastebin, code is ugly on OsBot and not formatted 8) Shouldn't "fire" be capitalized? Edited July 29, 2016 by lg_juggles 1 Quote Link to comment Share on other sites More sharing options...