Jump to content

Lumbridge Home Teleport Snippet


Botre

Recommended Posts

Wrote this mainly for the cooldown timer.

setCooldown(Message message) goes in the onMessage method of the script instance you use it in.

Constructive feedback is appreciated as always!

public class LumbridgeHomeTeleporter {

	private Script script;
	private int cooldown;

	public LumbridgeHomeTeleporter(final Script script) {
		this.script = script;
		Thread cooldownTimer = new Thread(new Runnable() {
			public void run() {
				while (true) {
					try {
						MethodProvider.sleep(60000);
						if (cooldown > 0) {
							--cooldown;
						}
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		});
		cooldownTimer.start();
	}

	public void teleport() throws InterruptedException {
		if (this.cooldown == 0 && this.script.skills.getDynamic(Skill.MAGIC) > 0) {
			Timer timer = new Timer();
			if (this.script.magic.castSpell(Spell.HOME_TELEPORT)) {
				while (this.cooldown == 0 && !this.script.map.canReach(LocationArea.LUMBRIDGE_TELEPORT_AREA.getArea().getRandomPosition(0)) && timer.getElapsed() < 10000) {
					MethodProvider.sleep(600);
				}
			}
		}
	}

	public void setCooldown(Message message) {
		if (message.getType().equals(Message.MessageType.GAME) && message.getMessage().toLowerCase().contains("you need to wait another")) {
			String match = null;
			Pattern pattern = Pattern.compile("[0-9]+");
			Matcher matcher = pattern.matcher(message.getMessage());
			while (matcher.find()) {
				match = matcher.group();
			}
			this.cooldown = Integer.parseInt(match);
		}
	}

	public int getCooldown() {
		return this.cooldown;
	}

}

h

  • Like 2
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...