- import org.powerbot.concurrent.Task;
- import org.powerbot.concurrent.strategy.Condition;
- import org.powerbot.concurrent.strategy.Strategy;
- import org.powerbot.game.api.ActiveScript;
- import org.powerbot.game.api.Manifest;
- import org.powerbot.game.api.methods.Calculations;
- import org.powerbot.game.api.methods.Walking;
- import org.powerbot.game.api.methods.interactive.Players;
- import org.powerbot.game.api.methods.node.SceneEntities;
- import org.powerbot.game.api.methods.tab.Inventory;
- import org.powerbot.game.api.util.Filter;
- import org.powerbot.game.api.util.Time;
- import org.powerbot.game.api.wrappers.Tile;
- import org.powerbot.game.api.wrappers.node.SceneObject;
- @Manifest(authors = { "Thomas0013" }, name = "T Chopepr", description = "Chops down trees", version = 1.0)
- public class TChop extends ActiveScript{
- private static final int[] LOG = {1521};
- Tile destinationTile = new Tile(3281, 3415, 0);
- @Override
- protected void setup() {
- final Chop chop = new Chop();
- final Strategy chopAction = new Strategy(chop, chop);
- final Walk walk = new Walk();
- final Strategy walkAction = new Strategy(walk, walk);
- final Drop drop = new Drop();
- final Strategy dropAction = new Strategy(drop, drop);
- provide(chopAction);
- provide(walkAction);
- provide(dropAction);
- }
- private class Chop implements Task, Condition {
- @Override
- public void run() {
- SceneObject tree = SceneEntities.getNearest(new Filter<SceneObject>() {
- public boolean accept(SceneObject entity) {
- return entity.getId() == 38732; //need to fill in the correct id of the entity you want
- }
- });
- if (tree != null) {
- if (tree.isOnScreen()) {
- tree.interact("Chop");
- Time.sleep(1000);
- }
- }
- }
- @Override
- public boolean validate() {
- return Inventory.getCount() < 28 && Players.getLocal().getAnimation() == -1;
- }
- }
- private class Walk implements Task, Condition {
- SceneObject tree = SceneEntities.getNearest(new Filter<SceneObject>() {
- public boolean accept(SceneObject entity) {
- return entity.getId() == 38732; //need to fill in the correct id of the entity you want
- }
- });
- @Override
- public void run() {
- while (!tree.isOnScreen()) {
- Walking.walk(destinationTile);
- Time.sleep(1500);
- }
- }
- @Override
- public boolean validate() {
- return tree != null && Calculations.distanceTo(tree) > 15;
- }
- }
- private class Drop implements Task, Condition {
- @Override
- public void run() {
- Inventory.getItem(LOG).getWidgetChild().interact("Drop");
- }
- @Override
- public boolean validate() {
- return Inventory.getCount() == 28;
- }
- }
- }