Skip to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Progression Bar

Featured Replies

My current progression bar isn't working correctly, it's shortening instead of widening

gif: http://i.imgur.com/VV7g5JA.gifv

 

here is the code:

	/**
	 * Calculates the length of the progress bar
	 * 
	 * @return - the progress bar length
	 */
	public int calculateLength()
	{
		int value = 0;
		int alphaFactor = 165;
		
		int baseXp = skills.getDynamic(Skill.WOODCUTTING);
		int currentXp = skills.getExperience(Skill.WOODCUTTING);
		int nextLevel = skills.getExperienceForLevel(
				skills.getStatic(Skill.WOODCUTTING) + 1
				);
		
		currentXp -= nextLevel;
		currentXp += baseXp;
		value = currentXp;
		
		return Math.abs(value) / alphaFactor;
	}

i want it to increase in size

 

 

fixed:

	/**
	 * Calculates the length of the progress bar
	 * 
	 * @return - the progress bar length
	 */
	public int calculateLength()
	{
		int value = 0;
		int alphaFactor = 165;
		
		int baseXp = skills.getExperienceForLevel(
				skills.getStatic(Skill.WOODCUTTING));
		int currentXp = skills.getExperience(Skill.WOODCUTTING);
		int nextLevel = skills.getExperienceForLevel(
				skills.getStatic(Skill.WOODCUTTING) + 1
				);
		logger.debug("baseXp "+ baseXp);
		logger.debug("currentXp "+ currentXp);
		logger.debug("nextLevel "+ nextLevel);
		int levelXp = nextLevel - baseXp;
		logger.debug("level xp "+ levelXp);
		value =  (nextLevel - currentXp) -(currentXp - baseXp);
		logger.debug("new value "+value);
		return Math.abs(value - levelXp) / alphaFactor;
	}

Edited by optimumrsps

My current progression bar isn't working correctly, it's shortening instead of widening

gif: http://i.imgur.com/VV7g5JA.gifv

 

here is the code:

	/**
	 * Calculates the length of the progress bar
	 * 
	 * @return - the progress bar length
	 */
	public int calculateLength()
	{
		int value = 0;
		int alphaFactor = 165;
		
		int baseXp = skills.getDynamic(Skill.WOODCUTTING);
		int currentXp = skills.getExperience(Skill.WOODCUTTING);
		int nextLevel = skills.getExperienceForLevel(
				skills.getStatic(Skill.WOODCUTTING) + 1
				);
		
		currentXp -= nextLevel;
		currentXp += baseXp;
		value = currentXp;
		
		return Math.abs(value) / alphaFactor;
	}

i want it to increase in size

look at your baseXp

  • Author

look at your baseXp

 

I'm pretty sure dynamic didn't mean anything unless i was using dragon axe using the special, changed it and still the same error. Thanks though for spotting that out

Edited by optimumrsps

I'm pretty sure dynamic didn't mean anything unless i was using dragon axe using the special, changed it and still the same error. Thanks though for spotting that out

Dynamic gives you your current level, not experience

I'll post this in the snippet section a little later, but here's something I just whipped up which should cover everything you need for progress bars smile.png

 

Class:

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.geom.Rectangle2D;

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

public class ProgressBar {

	/**
	 * @author © Apaec
	 * @since 17 Jun 2016
	 * @file ProgressBar.java
	 */

	Script s;
	Graphics g;
	String name;
	Skill skill;
	boolean frame;
	int x, y, width, height;
	Color red = new Color(255, 0, 0, 150);
	Color green = new Color(0, 255, 0, 150);
	Font font;

	int[] XP = { 0, 83, 174, 276, 388, 512, 650, 801, 969, 1154, 1358, 1584,
			1833, 2107, 2411, 2746, 3115, 3523, 3973, 4470, 5018, 5624, 6291,
			7028, 7842, 8740, 9730, 10824, 12031, 13363, 14833, 16456, 18247,
			20224, 22406, 24815, 27473, 30408, 33648, 37224, 41171, 45529,
			50339, 55649, 61512, 67983, 75127, 83014, 91721, 101333, 111945,
			123660, 136594, 150872, 166636, 184040, 203254, 224466, 247886,
			273742, 302288, 333804, 368599, 407015, 449428, 496254, 547953,
			605032, 668051, 737627, 814445, 899257, 992895, 1096278, 1210421,
			1336443, 1475581, 1629200, 1798808, 1986068, 2192818, 2421087,
			2673114, 2951373, 3258594, 3597792, 3972294, 4385776, 4842295,
			5346332, 5902831, 6517253, 7195629, 7944614, 8771558, 9684577,
			10692629, 11805606, 13034431, 200000000 };

	public ProgressBar(Script script, Graphics graphics, String name,
			Skill skill, boolean frame, int transparency, Font font, int x,
			int y, int width, int height) {
		this.s = script;
		this.g = graphics;
		this.name = name;
		this.skill = skill;
		this.frame = frame;
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
		this.red = new Color(255, 0, 0, transparency);
		this.green = new Color(0, 255, 0, transparency);
		this.font = font;
	}

	public int getCurrentExperience() {
		return s.getSkills().getExperience(skill)
				- XP[s.getSkills().getStatic(skill) - 1];
	}

	public int getTargetExperience() {
		return XP[s.getSkills().getStatic(skill)]
				- XP[s.getSkills().getStatic(skill) - 1];
	}

	public int getRemainingExperience() {
		return XP[s.getSkills().getStatic(skill) + 1]
				- s.getSkills().getExperience(skill);
	}

	public int getPercentage(int current, int total) {
		return current * 100 / total;
	}

	public int getWidth(int percentage, int totalWidth) {
		return percentage * totalWidth / 100;
	}

	public void draw() {
		
		// Current percentage
		g.setColor(green);
		g.fillRect(x, y, getWidth(getPercentage(getCurrentExperience(),getTargetExperience()), width), height);

		// Remaining percentage
		g.setColor(red);
		g.fillRect(x + getWidth(getPercentage(getCurrentExperience(), getTargetExperience()), width), y, width
				- getWidth(getPercentage(getCurrentExperience(), getTargetExperience()), width), height);

		// Frame
		if (frame) {
			g.setColor(Color.BLACK);
			g.drawRect(x, y, width, height);
		}

		// Setting text font and colour
		g.setColor(Color.WHITE);
		g.setFont(font);

		// The text which we want to show on the progress bar
		String text = name + " (" + s.getSkills().getStatic(skill) + "): "
				+ getPercentage(getCurrentExperience(), getTargetExperience())
				+ "%";

		// Create a bounding box around the text
		FontMetrics metrics = g.getFontMetrics(font);
		Rectangle2D rect = metrics.getStringBounds(text, g);
		int textHeight = (int) (rect.getHeight());
		int textWidth = (int) (rect.getWidth());

		// Get the text x and y co-ordinates relative to the progress bar
		int xText = (width - textWidth) / 2;
		int yText = (height - textHeight) / 2 + metrics.getAscent();

		// Draw text over progress bar
		g.drawString(text, x + xText, y + yText);
		
	}
}

Implementation (in onPaint class):

ProgressBar bar = new ProgressBar(this, g, "Ranged", Skill.RANGED,
				true, 150, new Font("Gulim", 0, 14), 10, 200, 200, 25);
		bar.draw();

Examples:

 

a58v7Co.png

 

FbOMUDh.png

 

iJhxJ2r.png

 

Hope that helps,

~apa

 

Edit: I didn't see skills has experienceToLevel, so you can always tidy the code in that respect.

Edited by Apaec

  • Author

I'll post this in the snippet section a little later, but here's something I just whipped up which should cover everything you need for progress bars smile.png

 

Class:

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.geom.Rectangle2D;

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

public class ProgressBar {

	/**
	 * @author © Apaec
	 * @since 17 Jun 2016
	 * @file ProgressBar.java
	 */

	Script s;
	Graphics g;
	String name;
	Skill skill;
	boolean frame;
	int x, y, width, height;
	Color red = new Color(255, 0, 0, 150);
	Color green = new Color(0, 255, 0, 150);
	Font font;

	int[] XP = { 0, 83, 174, 276, 388, 512, 650, 801, 969, 1154, 1358, 1584,
			1833, 2107, 2411, 2746, 3115, 3523, 3973, 4470, 5018, 5624, 6291,
			7028, 7842, 8740, 9730, 10824, 12031, 13363, 14833, 16456, 18247,
			20224, 22406, 24815, 27473, 30408, 33648, 37224, 41171, 45529,
			50339, 55649, 61512, 67983, 75127, 83014, 91721, 101333, 111945,
			123660, 136594, 150872, 166636, 184040, 203254, 224466, 247886,
			273742, 302288, 333804, 368599, 407015, 449428, 496254, 547953,
			605032, 668051, 737627, 814445, 899257, 992895, 1096278, 1210421,
			1336443, 1475581, 1629200, 1798808, 1986068, 2192818, 2421087,
			2673114, 2951373, 3258594, 3597792, 3972294, 4385776, 4842295,
			5346332, 5902831, 6517253, 7195629, 7944614, 8771558, 9684577,
			10692629, 11805606, 13034431, 200000000 };

	public ProgressBar(Script script, Graphics graphics, String name,
			Skill skill, boolean frame, int transparency, Font font, int x,
			int y, int width, int height) {
		this.s = script;
		this.g = graphics;
		this.name = name;
		this.skill = skill;
		this.frame = frame;
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
		this.red = new Color(255, 0, 0, transparency);
		this.green = new Color(0, 255, 0, transparency);
		this.font = font;
	}

	public int getCurrentExperience() {
		return s.getSkills().getExperience(skill)
				- XP[s.getSkills().getStatic(skill) - 1];
	}

	public int getTargetExperience() {
		return XP[s.getSkills().getStatic(skill)]
				- XP[s.getSkills().getStatic(skill) - 1];
	}

	public int getRemainingExperience() {
		return XP[s.getSkills().getStatic(skill) + 1]
				- s.getSkills().getExperience(skill);
	}

	public int getPercentage(int current, int total) {
		return current * 100 / total;
	}

	public int getWidth(int percentage, int totalWidth) {
		return percentage * totalWidth / 100;
	}

	public void draw() {
		
		// Current percentage
		g.setColor(green);
		g.fillRect(x, y, getWidth(getPercentage(getCurrentExperience(),getTargetExperience()), width), height);

		// Remaining percentage
		g.setColor(red);
		g.fillRect(x + getWidth(getPercentage(getCurrentExperience(), getTargetExperience()), width), y, width
				- getWidth(getPercentage(getCurrentExperience(), getTargetExperience()), width), height);

		// Frame
		if (frame) {
			g.setColor(Color.BLACK);
			g.drawRect(x, y, width, height);
		}

		// Setting text font and colour
		g.setColor(Color.WHITE);
		g.setFont(font);

		// The text which we want to show on the progress bar
		String text = name + " (" + s.getSkills().getStatic(skill) + "): "
				+ getPercentage(getCurrentExperience(), getTargetExperience())
				+ "%";

		// Create a bounding box around the text
		FontMetrics metrics = g.getFontMetrics(font);
		Rectangle2D rect = metrics.getStringBounds(text, g);
		int textHeight = (int) (rect.getHeight());
		int textWidth = (int) (rect.getWidth());

		// Get the text x and y co-ordinates relative to the progress bar
		int xText = (width - textWidth) / 2;
		int yText = (height - textHeight) / 2 + metrics.getAscent();

		// Draw text over progress bar
		g.drawString(text, x + xText, y + yText);
		
	}
}

Implementation (in onPaint class):

ProgressBar bar = new ProgressBar(this, g, "Ranged", Skill.RANGED,
				true, 150, new Font("Gulim", 0, 14), 10, 200, 200, 25);
		bar.draw();

Examples:

 

a58v7Co.png

 

FbOMUDh.png

 

iJhxJ2r.png

 

Hope that helps,

~apa

 

Edit: I didn't see skills has experienceToLevel, so you can always tidy the code in that respect.

 

Thanks a lot mate, i'll just use yours man

	int[] XP = { 0, 83, 174, 276, 388, 512, 650, 801, 969, 1154, 1358, 1584,
			1833, 2107, 2411, 2746, 3115, 3523, 3973, 4470, 5018, 5624, 6291,
			7028, 7842, 8740, 9730, 10824, 12031, 13363, 14833, 16456, 18247,
			20224, 22406, 24815, 27473, 30408, 33648, 37224, 41171, 45529,
			50339, 55649, 61512, 67983, 75127, 83014, 91721, 101333, 111945,
			123660, 136594, 150872, 166636, 184040, 203254, 224466, 247886,
			273742, 302288, 333804, 368599, 407015, 449428, 496254, 547953,
			605032, 668051, 737627, 814445, 899257, 992895, 1096278, 1210421,
			1336443, 1475581, 1629200, 1798808, 1986068, 2192818, 2421087,
			2673114, 2951373, 3258594, 3597792, 3972294, 4385776, 4842295,
			5346332, 5902831, 6517253, 7195629, 7944614, 8771558, 9684577,
			10692629, 11805606, 13034431, 200000000 };

 

Nooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo sad.pngsad.pngsad.pngsad.pngsad.png

  • Author

Noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo sad.pngsad.pngsad.pngsad.pngsad.png

 

That's what i was thinking, theres already a getExperienceForLevel

Nooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo sad.pngsad.pngsad.pngsad.pngsad.png

 

 

That's what i was thinking, theres already a getExperienceForLevel

 

As I said, I didn't realise the skills api had this ;p

How do people know all of this code to put in a script. Idk what to do after Putting in skeleton. LOL.

How do people know all of this code to put in a script. Idk what to do after Putting in skeleton. LOL.

 

They knew the Java language beforehand probably :boge:

 

  • 2 months later...

I'll post this in the snippet section a little later, but here's something I just whipped up which should cover everything you need for progress bars smile.png

 

Class:

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.geom.Rectangle2D;

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

public class ProgressBar {

	/**
	 * @[member=Author X]© Apaec
	 * @since 17 Jun 2016
	 * @file ProgressBar.java
	 */

	Script s;
	Graphics g;
	String name;
	Skill skill;
	boolean frame;
	int x, y, width, height;
	Color red = new Color(255, 0, 0, 150);
	Color green = new Color(0, 255, 0, 150);
	Font font;

	int[] XP = { 0, 83, 174, 276, 388, 512, 650, 801, 969, 1154, 1358, 1584,
			1833, 2107, 2411, 2746, 3115, 3523, 3973, 4470, 5018, 5624, 6291,
			7028, 7842, 8740, 9730, 10824, 12031, 13363, 14833, 16456, 18247,
			20224, 22406, 24815, 27473, 30408, 33648, 37224, 41171, 45529,
			50339, 55649, 61512, 67983, 75127, 83014, 91721, 101333, 111945,
			123660, 136594, 150872, 166636, 184040, 203254, 224466, 247886,
			273742, 302288, 333804, 368599, 407015, 449428, 496254, 547953,
			605032, 668051, 737627, 814445, 899257, 992895, 1096278, 1210421,
			1336443, 1475581, 1629200, 1798808, 1986068, 2192818, 2421087,
			2673114, 2951373, 3258594, 3597792, 3972294, 4385776, 4842295,
			5346332, 5902831, 6517253, 7195629, 7944614, 8771558, 9684577,
			10692629, 11805606, 13034431, 200000000 };

	public ProgressBar(Script script, Graphics graphics, String name,
			Skill skill, boolean frame, int transparency, Font font, int x,
			int y, int width, int height) {
		this.s = script;
		this.g = graphics;
		this.name = name;
		this.skill = skill;
		this.frame = frame;
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
		this.red = new Color(255, 0, 0, transparency);
		this.green = new Color(0, 255, 0, transparency);
		this.font = font;
	}

	public int getCurrentExperience() {
		return s.getSkills().getExperience(skill)
				- XP[s.getSkills().getStatic(skill) - 1];
	}

	public int getTargetExperience() {
		return XP[s.getSkills().getStatic(skill)]
				- XP[s.getSkills().getStatic(skill) - 1];
	}

	public int getRemainingExperience() {
		return XP[s.getSkills().getStatic(skill) + 1]
				- s.getSkills().getExperience(skill);
	}

	public int getPercentage(int current, int total) {
		return current * 100 / total;
	}

	public int getWidth(int percentage, int totalWidth) {
		return percentage * totalWidth / 100;
	}

	public void draw() {
		
		// Current percentage
		g.setColor(green);
		g.fillRect(x, y, getWidth(getPercentage(getCurrentExperience(),getTargetExperience()), width), height);

		// Remaining percentage
		g.setColor(red);
		g.fillRect(x + getWidth(getPercentage(getCurrentExperience(), getTargetExperience()), width), y, width
				- getWidth(getPercentage(getCurrentExperience(), getTargetExperience()), width), height);

		// Frame
		if (frame) {
			g.setColor(Color.BLACK);
			g.drawRect(x, y, width, height);
		}

		// Setting text font and colour
		g.setColor(Color.WHITE);
		g.setFont(font);

		// The text which we want to show on the progress bar
		String text = name + " (" + s.getSkills().getStatic(skill) + "): "
				+ getPercentage(getCurrentExperience(), getTargetExperience())
				+ "%";

		// Create a bounding box around the text
		FontMetrics metrics = g.getFontMetrics(font);
		Rectangle2D rect = metrics.getStringBounds(text, g);
		int textHeight = (int) (rect.getHeight());
		int textWidth = (int) (rect.getWidth());

		// Get the text x and y co-ordinates relative to the progress bar
		int xText = (width - textWidth) / 2;
		int yText = (height - textHeight) / 2 + metrics.getAscent();

		// Draw text over progress bar
		g.drawString(text, x + xText, y + yText);
		
	}
}

Implementation (in onPaint class):

ProgressBar bar = new ProgressBar(this, g, "Ranged", Skill.RANGED,
				true, 150, new Font("Gulim", 0, 14), 10, 200, 200, 25);
		bar.draw();

Examples:

 

a58v7Co.png

 

FbOMUDh.png

 

iJhxJ2r.png

 

Hope that helps,

~apa

 

Edit: I didn't see skills has experienceToLevel, so you can always tidy the code in that respect.

 

You havent posted in the Snippet section yet :boge:

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.