Hello OSBot.
Recently, I've been working with paints and noticed that with paints that require large calculations and things of that nature, the paint actually lags the bot.
The solution is to use a thread which updates the data periodically.
For instance, say you want to display range xp:
One might calculate how much range xp is gained per paint update. BAD.
public void onPaint(Graphics g) {
drawString("Range XP Gained: " + this.client.getSkills().getExperience(Skill.RANGED) - this.INITIAL_RANGE_XP,0,0);
}You can see that it calculates this EVERY time paint is called. I believe it is based on the current FPS.The correct way to do it is using a thread.
Here is your onLoop() -
public void onLoop() {
if (this.start == false) {
this.paintUpdater = new PaintUpdater(this.client, this);
this.paintThread = new Thread(this.paintUpdater);
this.paintThread.start();
this.start = true;
}
return 1000;
}
Here is your thread class -
public class PaintUpdater implements Runnable {
public Client client;
public Script script;
public int INITIAL_RANGE_XP;
public int range_xp_gained;
public boolean run = true;
public PaintUpdater(Client c, Script s) {
this.client = c;
this.script = s;
this.INITIAL_RANGE_XP = c.getSkills().getExperience(Skill.RANGED);
}
public void run() {
while (this.run) {
try {
update();
Thread.sleep(200);
} catch (InterruptedException e) { }
}
}
public void update() {
this.range_xp_gained = this.client.getSkills().getExperience(Skill.RANGED) - this.INITIAL_RANGE_XP;
}
public int getRangeXPGained() {
return this.range_xp_gained;
}
public void stop() {
this.run = false;
}
}
and here is your paint -
public void onPaint(Graphics g) {
drawString("Range XP Gained: " + this.paintUpdater.getRangeXPGained(),0,0);
}
The rest is up to you to make it work how you please!