domp Posted October 28, 2016 Author Share Posted October 28, 2016 import java.awt.Color; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.util.Objects; import org.osbot.rs07.api.Inventory; import org.osbot.rs07.api.map.Position; import org.osbot.rs07.api.model.Entity; import org.osbot.rs07.api.model.Player; import org.osbot.rs07.api.ui.MagicSpell; import org.osbot.rs07.api.ui.Skill; import org.osbot.rs07.api.ui.Spells; import org.osbot.rs07.api.ui.Spells.NormalSpells; import org.osbot.rs07.api.ui.Tab; import org.osbot.rs07.api.util.ExperienceTracker; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; @ScriptManifest(author = "Domp", info = "Tree Farming", logo = "@", name = "TP", version = 0.1) public class TP extends Script { public TP(String name){ this.willowtree = Objects.requireNonNull(willowtree); } // learn to use areas public Position[] vpath = { new Position(3213, 3436, 0), new Position(3225, 3457, 0), new Position(3228, 3457, 0) }; public Position[] gpath = { new Position(3218, 3451, 0), new Position(3206, 3454, 0), new Position(3199, 3459, 0), new Position(3196, 3468, 0), new Position(3196, 3485, 0), new Position(3186, 3494, 0), new Position(3186, 3505, 0) }; public Position[] lpath = { new Position(3204, 3217, 0), new Position(3195, 3218, 0), new Position(3193, 3229, 0) }; public Position[] tpath = { new Position(2966, 3388, 0), new Position(2963, 3402, 0), new Position(2957, 3417, 0), new Position(2949, 3430, 0), new Position(2946, 3444, 0), new Position(2938, 3451, 0), new Position(2936, 3441, 0) }; public Position[] fpath = { new Position(2975, 3379, 0), new Position(2988, 3372, 0), new Position(2998, 3374, 0) }; String willowtree = "Willow Tree"; final String WILLOW_TREE = "Willow Tree"; final String WILLOW_LOG = "Willow logs"; // final Area BANK_AREA = new Area(x,y,topleft,topright); private ExperienceTracker expTracker; private long start; @[member=Override] public void onStart() { log("starting tree farming!!"); this.expTracker = getExperienceTracker(); this.expTracker.start(Skill.FARMING); this.start = System.currentTimeMillis(); } private static enum State { Varrock, Gnome, Lumby, Falador, Taverly, Done; public String toString() { String s = name().toLowerCase().replaceAll("_", " "); return s.substring(0, 1).toUpperCase().concat(s.substring(1, s.length())); } } // if(player.getPosition() == new Position(3228, 3457, 0)) <----could work // for a check // if player position = last location // teleport to next tree patch return.nextstate int check = new Integer(0); private State getState() { // need to fix this to correctly return states... if (getInventory().contains(new String[] { "Rune axe" })) { check++; return State.Varrock; } if (check == 1) { // or use a check on the amount of empty pots in check++; // invent return State.Gnome; } if (check == 2) { check++; return State.Lumby; } if (check == 3) { // change int x check++; return State.Taverly; } if (check == 4) { return State.Falador; } return State.Done; } // code in loop Entity willow = closestObjectForName(WILLOW_TREE); @[member=Override] public int onLoop() throws InterruptedException { State result = getState(); log(result); switch (result) { case Varrock: if (getInventory().isFull()) { getInventory().dropForNameThatContains("Willow"); getInventory().dropForNameThatContains("Empty plant pot"); } else { castSpell(Spells.NormalSpells.VARROCK_TELEPORT); sleep(random(300, 600)); getWalking().webWalk(vpath); getCamera().toEntity(willow); log(check + "varrock"); /* * if(!open(Tab.MAGIC)){ open(Tab.MAGIC); * castSpell(Spells.NormalSpells.VARROCK_TELEPORT);// tele * sleep(random(25, 100)); getWalking().webWalk(vpath); } */ if (willow != null) { if (willow.isVisible()) { // basic woodcutter if (!this.myPlayer().isAnimating()) { if (!getInventory().isFull()) {// for future use if (!this.myPlayer().isMoving()) { willow.interact("Check-health"); sleep(random(500, 700)); willow.interact("Chop down"); sleep(random(25, 75)); } else if (!willow.isVisible()) { if (!this.myPlayer().isAnimating()) { if (!getInventory().isFull()) {// add a full // inv // check... // drop // willows // if // inv // reaches // full objects.closest("Tree stump").interact("Dig"); } else { objects.closest("Dead tree").interact("Dig"); sleep(random(500, 700)); getInventory().dropForNameThatContains("willow"); } } } } } } } } // code using supercompost and planting tree. look up using mouse // entity with entity break; case Gnome: // tele Entity spirit = closestObjectForName("Spirit tree"); getWalking().webWalk(gpath); getCamera().toEntity(spirit); objects.closest("Spirit tree").interact("Travel"); break; case Lumby: { if (!open(Tab.MAGIC)) { open(Tab.MAGIC); castSpell(Spells.NormalSpells.LUMBRIDGE_TELEPORT); getWalking().webWalk(lpath); } log(check + "lumbridge"); } break; case Falador: { // tele if (!open(Tab.MAGIC)) { castSpell(Spells.NormalSpells.FALADOR_TELEPORT); getWalking().webWalk(fpath); } log(check + "fally"); } break; case Taverly: { // tele if (!open(Tab.MAGIC)) { castSpell(Spells.NormalSpells.FALADOR_TELEPORT); getWalking().webWalk(tpath); } log(check + "taverly"); } break; case Done: stop(); default: } return random(600); } private Entity closestObjectForName(String WILLOW_TREE) { // TODO Auto-generated method stub return willow;//FIX THIS FUCKING NULL } private boolean open(Tab magic) { // TODO Auto-generated method stub return true; } @SuppressWarnings("unused") private void castSpell(MagicSpell spell) { // TODO Auto-generated method stub NormalSpells vartele = Spells.NormalSpells.VARROCK_TELEPORT; } public final boolean toEntity(Entity willow) { return false; } // code executed at the end @[member=Override] public void onExit() { log("Done farming"); } @[member=Override] public void onPaint(Graphics2D graphics) { State state1 = getState(); Graphics2D g = graphics; g.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF)); if (this.expTracker != null) { g.setColor(Color.WHITE); g.drawString("Time till level " + (getSkills().getStatic(Skill.FARMING) + 1) + ": " + formatTime(this.expTracker.getTimeToLevel(Skill.FARMING)), 10, 250); g.drawString("Exp: " + this.expTracker.getGainedXP(Skill.FARMING) + " (" + this.expTracker.getGainedXPPerHour(Skill.FARMING) + " / hour)", 10, 270); g.drawString("Level: " + getSkills().getStatic(Skill.FARMING) + " (Gained: " + this.expTracker.getGainedLevels(Skill.FARMING) + ")", 10, 290); } g.setColor(Color.CYAN); g.drawString("Status: " + state1.toString(), 10, 310); g.drawString("Runtime: " + (this.start == -1L ? "Idle" : formatTime(System.currentTimeMillis() - this.start)), 10, 330); } private String formatTime(long ms) { long s = ms / 1000L; long m = s / 60L; long h = m / 60L; s %= 60L; m %= 60L; h %= 24L; return String.format("%02d:%02d:%02d", new Object[] { Long.valueOf(h), Long.valueOf(m), Long.valueOf(s) }); } } Added some of your guises suggestions. Changed private Entity to return willow; instead of return null; Does this make the difference? I also set int check as a new Integer instead of not giving it a value. Spent the whole day today thinking about this and didnt get much progress. Ahh 7 hours later and I barely got any further Wish me luck Quote Link to comment Share on other sites More sharing options...
Alek Posted October 28, 2016 Share Posted October 28, 2016 It was better the way you had it before, primitives are better. int check = new Integer(0); This still does nothing because willow is null: private Entity closestObjectForName(String WILLOW_TREE) { // TODO Auto-generated method stub return willow;//FIX THIS FUCKING NULL } Actually, how is your script even compiling? Your method doesn't have access to "Entity willow".What is this? public TP(String name){ this.willowtree = Objects.requireNonNull(willowtree); } You're assigning a generic to a string? Just delete this altogether. Why are you writing your own custom methods for things that already exist in the API: @SuppressWarnings("unused") private void castSpell(MagicSpell spell) { // TODO Auto-generated method stub NormalSpells vartele = Spells.NormalSpells.VARROCK_TELEPORT; } The reason I'm having a hard time believing that you wrote this is because you wrote a ton of code without testing it until now? When was this script last working? 3 Quote Link to comment Share on other sites More sharing options...
Team Cape Posted October 28, 2016 Share Posted October 28, 2016 (edited) public TP(String name){ this.willowtree = Objects.requireNonNull(willowtree); } remove this private static enum State { Varrock, Gnome, Lumby, Falador, Taverly, Done; public String toString() { String s = name().toLowerCase().replaceAll("_", " "); return s.substring(0, 1).toUpperCase().concat(s.substring(1, s.length())); } } remove the static modifier. enums are static by nature int check = new Integer(0); just do int check = 0, and put it inside of the getState() loop. not outside. Entity willow = closestObjectForName(WILLOW_TREE); put that in onLoop(). also this is just gonna return a null. i still dont get why you're using this objects.closest("Tree stump").interact("Dig"); objects.closest("Dead tree").interact("Dig"); getCamera().toEntity(spirit); objects.closest("Spirit tree").interact("Travel"); all of those need null checks private Entity closestObjectForName(String WILLOW_TREE) { // TODO Auto-generated method stub return willow;//FIX THIS FUCKING NULL } just implement this private boolean open(Tab magic) { // TODO Auto-generated method stub return true; } what is this? just use the api method private void castSpell(MagicSpell spell) { // TODO Auto-generated method stub NormalSpells vartele = Spells.NormalSpells.VARROCK_TELEPORT; } api method... public final boolean toEntity(Entity willow) { return false; } ????????????????????????????? it's ironic that you have lengthy explanations for what's right in your script, but no explanation for methods that do nothing (???) These are all of the generic issues - i havent looked at the script logic at all yet you might want to try an easier script as your first... i did a simple nature chest script that was incredibly difficult for me at the time, for example, last august, and recently, i've been able to do scripts like wintertodt, multiple progressive levelers, agility pyramid, etc that all work fantastically. take yourself 1 step at a time m8. you're trying to fly an airplane before you've even gotten your learner's permit Edited October 28, 2016 by Imateamcape 1 Quote Link to comment Share on other sites More sharing options...
Explv Posted October 28, 2016 Share Posted October 28, 2016 All require an @Override (forums "tagging" system screw up what i'm trying to write >_>) like You don't need @ Override. It simply improves readability and provides some benefit with compiler checking. It is recommended but not required. Quote Link to comment Share on other sites More sharing options...
Token Posted October 28, 2016 Share Posted October 28, 2016 Post this on stackoverflow with osbot tag, I don't think anyone on this forum can make this script work 2 Quote Link to comment Share on other sites More sharing options...
PlagueDoctor Posted October 29, 2016 Share Posted October 29, 2016 GL with your learning! As TeamCape said, make sure you have the basics down before you try some super hard shit. Even if it feels kinda pointless to write a script that you're not going to use, its probably still worthwhile as it will help you have a good understanding of how to make things work. 1 Quote Link to comment Share on other sites More sharing options...