MySQLi Posted June 23, 2017 Share Posted June 23, 2017 Hey guys, just working on my first script, I've ran into another issue I can't seem to figure out. Spoiler import org.osbot.rs07.api.model.Entity; import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.utility.ConditionalSleep; import java.awt.*; @ScriptManifest(author = "MySQLi", info = "Basic Chicken Killer", name = "SqlChickenKiller", version = 1.0, logo = "") public class Main extends Script { @Override public void onStart() { log("Script made by MySQLi, Enjoy!"); } //What are we going to do in our script private enum State{ KILL,WAIT,LOOT }; //Declare our conditions private State getState(){ Entity chicken = getNpcs().closest("Chicken"); if(chicken != null && chicken.interact("Attack")) { new ConditionalSleep(5000){ public boolean condition2(){ return myPlayer().isAnimating() || !chicken.exists(); } @Override public boolean condition() throws InterruptedException { // TODO Auto-generated method stub return false; } }.sleep(); } Entity bones = getGroundItems().closest("Bones"); if(bones != null && bones.interact("Take")) { new ConditionalSleep(5000){ public boolean condition(){ return myPlayer().isAnimating() || !bones.exists(); } }.sleep(); Entity feather = getGroundItems().closest("Feather"); if(feather != null && feather.interact("Take")) { new ConditionalSleep(5000){ public boolean condition(){ return false; } }.sleep(); } } if (bones != null) return State.LOOT; if (feather != null) return State.LOOT; if(chicken != null) return State.KILL; return State.WAIT; } @Override public int onLoop() throws InterruptedException { switch (getState()){ case LOOT: Entity bones = getGroundItems().closest("Bones"); Entity feather = getGroundItems().closest("Feather"); if(bones != null) { bones.interact("Take"); if(feather != null){ feather.interact("Take"); } } break; case KILL: Entity chicken = getNpcs().closest("Chicken"); if(chicken != null) { chicken.interact("Attack"); } break; case WAIT: sleep(random(500, 700)); break; } return random(200, 300); } @Override public void onExit() { log("Thank you, come again!"); } @Override public void onPaint(Graphics2D g) { } } Where I'm; if (feather != null) return state.LOOT; It's saying feather cannot be resolved to a variable, although I have it declared, can anyone tell me what I did wrong? Quote Link to comment Share on other sites More sharing options...
Viston Posted June 23, 2017 Share Posted June 23, 2017 (edited) Feather shouldn't be entity. It's a GroundItem. Also, I believe it's "Feathers" not "Feather" So like this: GroundItem feather = getGroundItems().closest("Feathers"); 16 minutes ago, MySQLi said: Entity chicken = getNpcs().closest("Chicken"); Chicken is an NPC not Entity. Same goes for bones. It's a GroundItem Edited June 23, 2017 by Visty Quote Link to comment Share on other sites More sharing options...
MySQLi Posted June 23, 2017 Author Share Posted June 23, 2017 7 minutes ago, Visty said: Feather shouldn't be entity. It's a GroundItem. Also, I believe it's "Feathers" not "Feather" So like this: GroundItem feather = getGroundItems().closest("Feathers"); Chicken is an NPC not Entity. I fixed that, but it still doesn't fix my issue, thank you for pointing that out though. Quote Link to comment Share on other sites More sharing options...
Viston Posted June 23, 2017 Share Posted June 23, 2017 (edited) 8 minutes ago, MySQLi said: I fixed that, but it still doesn't fix my issue, thank you for pointing that out though. A better way imo to use states, is by creating a method for each state. In your case, make a method like public void Loot() {} //In this method you put everything you need. Then in your getStates say like if (this & that) { return State.Loot; } Then in your onLoop say like case LOOT: Loot(); break; public enum State { WALK_TO_OAKS } public int onLoop() throws InterruptedException { s = getState(); switch (s) { case WALK_TO_OAKS: Walk_To_Oak(); break; } public void Walk_To_Oak() throws InterruptedException { paint.status = "Going To Oak Trees..."; getWalking().walkPath(Arrays.asList(Oak_Path)); } This is an example in one of my scripts that uses States. Because tbf, reading that code gives me headaches, I can't see Because you are simply repeating your States on your onLoop. Edited June 23, 2017 by Visty Quote Link to comment Share on other sites More sharing options...
MySQLi Posted June 23, 2017 Author Share Posted June 23, 2017 2 minutes ago, Visty said: A better way imo to use states, is by creating a method for each state. In your case, make a method like public void Loot() {} //In this method you put everything you need. Then in your getStates say like if (this & that) { return State.Loot; } Then in your onLoop say like case LOOT: Loot(); break; I just did that, It is working now. I must of had a small error somewhere that I wasn't picking up. Thanks, I appreciate it. When you're implementing sleeps, what time do you usually use? 5000 MS works for me, I one hit chickens, if you figure a level 3 fighting chickens, what do you image a good wait time is? Or is there another check without using waits to just check if the player is currently fighting, or looting? Quote Link to comment Share on other sites More sharing options...
Viston Posted June 23, 2017 Share Posted June 23, 2017 (edited) 10 minutes ago, MySQLi said: I just did that, It is working now. I must of had a small error somewhere that I wasn't picking up. Thanks, I appreciate it. When you're implementing sleeps, what time do you usually use? 5000 MS works for me, I one hit chickens, if you figure a level 3 fighting chickens, what do you image a good wait time is? Or is there another check without using waits to just check if the player is currently fighting, or looting? I would use a conditionalSleep to check whether my player is under attack. I'm not too familiar with looting tbf, haven't worked with it yet. But I think you can do conditionalSleep then check in the inventory. Edited June 23, 2017 by Visty Quote Link to comment Share on other sites More sharing options...
Adept Posted June 23, 2017 Share Posted June 23, 2017 25 minutes ago, Visty said: Feather shouldn't be entity. It's a GroundItem. Also, I believe it's "Feathers" not "Feather" So like this: GroundItem feather = getGroundItems().closest("Feathers"); Chicken is an NPC not Entity. Same goes for bones. It's a GroundItem I'd suggest you read about inheritance and familiarise yourself with the API before you starting throwing claims about what is what. Both GroundItem and NPC implement Entity. Quote Link to comment Share on other sites More sharing options...
Viston Posted June 23, 2017 Share Posted June 23, 2017 16 minutes ago, Adept said: I'd suggest you read about inheritance and familiarise yourself with the API before you starting throwing claims about what is what. Both GroundItem and NPC implement Entity. My bad brudda, you can take over then Quote Link to comment Share on other sites More sharing options...
Chris Posted June 23, 2017 Share Posted June 23, 2017 just use onLoop bro 1 Quote Link to comment Share on other sites More sharing options...
HeyImJamie Posted June 23, 2017 Share Posted June 23, 2017 34 minutes ago, Adept said: I'd suggest you read about inheritance and familiarise yourself with the API before you starting throwing claims about what is what. Both GroundItem and NPC implement Entity. Why're you so bipolar. Quote Link to comment Share on other sites More sharing options...
Adept Posted June 23, 2017 Share Posted June 23, 2017 2 minutes ago, HeyImJamie said: Why're you so bipolar. l0l would you prefer to be corrected or continue living in ignorance?oh wait, I know the answer I appreciate it when ppl point out my mistakes. You'll start making mistakes too once you start writing your own code Quote Link to comment Share on other sites More sharing options...
HeyImJamie Posted June 23, 2017 Share Posted June 23, 2017 31 minutes ago, Adept said: l0l would you prefer to be corrected or continue living in ignorance?oh wait, I know the answer I appreciate it when ppl point out my mistakes. You'll start making mistakes too once you start writing your own code Considering actually learning Java as a language is neither my career choice nor something I actually give two shitsticks about, as long as I pull in an income to avoid having to slave while at Uni, ignorance is bliss. (Also still awaiting for my own special :spoonfeed: emote ) 1 Quote Link to comment Share on other sites More sharing options...