Jump to content

SwiftFlax


Rah

Recommended Posts

SwiftFlax

 

Current version: N/A

Date started: 29/09/2013

 

Hello reader, I'm creating a script called "SwiftFlax". The script will obviously pick flax, and then proceed to bank them once the bots inventory is full. So far, I have created the picking part of the script. I wish to improve my proficiency with scripting a bot, so I will start with a pretty basic script.

 

If you wish to leave your support, a tip, or anything that could potentially help me, I would greatly appreciate it.

 

So far, I have created a way for the bot to pick the flax. This is all made off the top of my head, I do not have an account for me to test it with because of the bans that took place on three of my accounts last night.

 

I'll leave this here, and build off on it whenever I get a chance to. I believe in open-sourcing your work, to an extent.

 

This is just the class to execute "picking" the flax.

 

I would like to thank exuals for providing the node tutorial. I really like the organization, and this way helps me understand how to structure things properly.

package swiftflax.nodes;

import org.osbot.script.Script;
import org.osbot.script.rs2.model.Entity;
import org.osbot.script.rs2.utility.Area;

import swiftflax.api.Node;

public class PickNode extends Node {

	private Area FLAX_FIELD = new Area(0000, 0000, 0000, 0000); // Get the coordinates.

	private Entity flax;

	public PickNode(Script script) {
		super(script);
	}

	@Override
	public boolean validate() throws InterruptedException {
		return !inventoryIsFull();
	}

	@Override
	public boolean execute() throws InterruptedException {
		return pickFlax();
	}

	private boolean inventoryIsFull() {
		return s.client.getInventory().isFull();
	}

	private boolean playerBusy() {
		return s.client.getMyPlayer().isUnderAttack()
				|| s.client.getMyPlayer().isMoving();
	}

	private boolean inFlaxField() {
		return s.client.getMyPlayer().isInArea(FLAX_FIELD);
	}

	private boolean flaxAvailable() {
		flax = s.closestObjectForName("Flax");

		return flax.exists() && flax.isVisible() && flax.isInArea(FLAX_FIELD) && flax != null;
	}

	private boolean pickFlax() throws InterruptedException {
		flax = s.closestObjectForName("Flax");
		
		if (!playerBusy()) {
			if (inFlaxField()) {
				if (flaxAvailable() && flax.interact("Pick")) {
					return true;
				}
			} else {
				s.log("Not in flax field.");
				// Walk to the flax field.
			}
		} else {
			s.log("Busy.");
			return false;
		}
		return false;
	}

}

  • Like 1
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...