Jump to content

need help finding a good way to make a if statement to a state more reliable.


Twin

Recommended Posts

Had no idea getInteracting was a method, that should fix this actually.

 

Nope, didn't fix it. Still having the issue where it will use the steel bar on the furnace every 10-20 seconds depending on when the sleep ends.

Will not work.

getInteracting() returns a Character.

 

Welp im an idiot lol could have sworn that said isInteracting, well like acted the same way.

Link to comment
Share on other sites

More than likely you're doing this because the player stops animating in between smelting and the bot goes and attempts to smelt again? Just monitor your last smithing xp gain and if it was over a certain threshold then you know you have to smith.

 

this post did not show up for me for some reason! did not mean to ignore it. This is exactly what I meant, how would I go about doing that? I make an integer of my smithing experience and then what? kind of lost of what to do there.

Link to comment
Share on other sites

this post did not show up for me for some reason! did not mean to ignore it. This is exactly what I meant, how would I go about doing that? I make an integer of my smithing experience and then what? kind of lost of what to do there.

I have moderated content on here cause I'm an asshole so my posts need to be approved by mods.

import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;

/**
 * Created with IntelliJ IDEA
 * User: Anthony
 * Date: 6/8/2014
 */

public class XPListener extends Thread {

	private boolean running;
	private int lastXpGain;
	private long lastXpGainTime;
	private Script sI;
	private Skill skill;

	public XPListener(Script sI, Skill skill) {
		this.running = true;
		this.sI = sI;
		this.skill = skill;
	}

	@Override
	public void run() {
		while (running) {
			int oldXp = sI.skills.getExperience(skill);
			try {
				Thread.sleep(600);
			}
			catch (InterruptedException e) {
			}
			int newXp = sI.skills.getExperience(skill);
			if (oldXp != newXp) {
				lastXpGain = newXp - oldXp;
				lastXpGainTime = System.currentTimeMillis();
			}
		}
	}

	public void setRunning(boolean running) {
		this.running = running;
	}

	public Skill getSkill() {
		return skill;
	}

	public int getLastXpGain() {
		return lastXpGain;
	}

	public long getLastXpGainTime() {
		return lastXpGainTime;
	}

}
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * Created with IntelliJ IDEA
 * User: Anthony
 * Date: 6/8/2014
 */

public class XPTracker {

	private Script sI;
	private Set<XPListener> xpListeners;

	public XPTracker(Script sI) {
		this.sI = sI;
		this.xpListeners = new HashSet<>();
	}

	public void startTrackingSkills(Skill... skills) {
		for (Skill s : skills) {
			XPListener listener = new XPListener(sI, s);
			listener.start();
			xpListeners.add(listener);
		}
	}

	public void stopTrackingSkills(Skill... skills) {
		Iterator<XPListener> iterator = xpListeners.iterator();
		for (Skill s : skills) {
			while (iterator.hasNext()) {
				XPListener l = iterator.next();
				if (l.getSkill() == s) {
					l.setRunning(false);
					iterator.remove();
					break;
				}
			}
		}
	}

	public int getLastXpGainForSkill(Skill skill) {
		int returnValue = -1;
		for (XPListener l : xpListeners) {
			if (l.getSkill() == skill) {
				returnValue = l.getLastXpGain();
				break;
			}
		}
		return returnValue;
	}

	public long getLastXpGainTimeForSkill(Skill skill) {
		long returnValue = -1;
		for (XPListener l : xpListeners) {
			if (l.getSkill() == skill) {
				returnValue = l.getLastXpGainTime();
				break;
			}
		}
		return returnValue;
	}

	public Set<XPListener> getXpListeners() {
		return xpListeners;
	}

}

Code is shit I wrote it awhile ago (it's not even a listener lol idk why I called it that). Create and register like so:

XPTracker tracker = new XPTracker(this);

tracker.startTrackingSkills(Skill.FLETCHING);

The check using tracker methods:

tracker.getLastXpGainTimeForSkill(Skill.FLETCHING) // returns milliseconds since last xp gain
  • Like 1
Link to comment
Share on other sites

 

I have moderated content on here cause I'm an asshole so my posts need to be approved by mods.

import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;

/**
 * Created with IntelliJ IDEA
 * User: Anthony
 * Date: 6/8/2014
 */

public class XPListener extends Thread {

	private boolean running;
	private int lastXpGain;
	private long lastXpGainTime;
	private Script sI;
	private Skill skill;

	public XPListener(Script sI, Skill skill) {
		this.running = true;
		this.sI = sI;
		this.skill = skill;
	}

	@Override
	public void run() {
		while (running) {
			int oldXp = sI.skills.getExperience(skill);
			try {
				Thread.sleep(600);
			}
			catch (InterruptedException e) {
			}
			int newXp = sI.skills.getExperience(skill);
			if (oldXp != newXp) {
				lastXpGain = newXp - oldXp;
				lastXpGainTime = System.currentTimeMillis();
			}
		}
	}

	public void setRunning(boolean running) {
		this.running = running;
	}

	public Skill getSkill() {
		return skill;
	}

	public int getLastXpGain() {
		return lastXpGain;
	}

	public long getLastXpGainTime() {
		return lastXpGainTime;
	}

}
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * Created with IntelliJ IDEA
 * User: Anthony
 * Date: 6/8/2014
 */

public class XPTracker {

	private Script sI;
	private Set<XPListener> xpListeners;

	public XPTracker(Script sI) {
		this.sI = sI;
		this.xpListeners = new HashSet<>();
	}

	public void startTrackingSkills(Skill... skills) {
		for (Skill s : skills) {
			XPListener listener = new XPListener(sI, s);
			listener.start();
			xpListeners.add(listener);
		}
	}

	public void stopTrackingSkills(Skill... skills) {
		Iterator<XPListener> iterator = xpListeners.iterator();
		for (Skill s : skills) {
			while (iterator.hasNext()) {
				XPListener l = iterator.next();
				if (l.getSkill() == s) {
					l.setRunning(false);
					iterator.remove();
					break;
				}
			}
		}
	}

	public int getLastXpGainForSkill(Skill skill) {
		int returnValue = -1;
		for (XPListener l : xpListeners) {
			if (l.getSkill() == skill) {
				returnValue = l.getLastXpGain();
				break;
			}
		}
		return returnValue;
	}

	public long getLastXpGainTimeForSkill(Skill skill) {
		long returnValue = -1;
		for (XPListener l : xpListeners) {
			if (l.getSkill() == skill) {
				returnValue = l.getLastXpGainTime();
				break;
			}
		}
		return returnValue;
	}

	public Set<XPListener> getXpListeners() {
		return xpListeners;
	}

}

Code is shit I wrote it awhile ago (it's not even a listener lol idk why I called it that). Create and register like so:

XPTracker tracker = new XPTracker(this);

tracker.startTrackingSkills(Skill.FLETCHING);

The check using tracker methods:

tracker.getLastXpGainTimeForSkill(Skill.FLETCHING) // returns milliseconds since last xp gain

I'm getting a weird error where smithXP.startTrackingSkills(Skill.SMITHING); is saying that it wants an @ before start and and @ sign instead of a semi colon, other than that everything looks good, Thanks for this by the way! I would have had no clue on how to write a class/method for something like that.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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