Jump to content

Awesome Java Code Snippets


Divine

Recommended Posts

Here are some awesome, useful snippets:

 

DistanceToPoint (Distance from character to point, can be used for finding the closest thing to the character at any distance):

	private int distanceToPoint(int pointX,int pointY) {
		return (int) Math.sqrt(Math.pow(this.client.getMyPlayer().getX() - pointX, 2) + Math.pow(this.client.getMyPlayer().getY() - pointY, 2));
	} 

 Get XP for Level:

	public int getXPForLevel(int level) {
		int points = 0;
		int output = 0;
		for (int lvl = 1; lvl <= level; lvl++) {
			points += Math.floor((double)lvl + 300.0 * Math.pow(2.0, (double)lvl / 7.0));
			if (lvl >= level)
				return output;
			output = (int)Math.floor(points / 4);
		}
		return 0;
	}

Get Level for XP:

	public int getLevelForXP(int exp) {
		int points = 0;
		int output = 0;
		if (exp > 13034430)
			return 99;
		for (int lvl = 1; lvl <= 99; lvl++) {
			points += Math.floor((double) lvl + 300.0
					* Math.pow(2.0, (double) lvl / 7.0));
			output = (int) Math.floor(points / 4);
			if (output >= exp) {
				return lvl;
			}
		}
		return 0;
	}
Edited by Divine
Link to comment
Share on other sites

 

Here are some awesome, useful snippets:

 

DistanceToPoint (Distance from character to point, can be used for finding the closest thing to the character at any distance):

	private int distanceToPoint(int pointX,int pointY) {
		return (int) Math.sqrt(Math.pow(this.client.getMyPlayer().getX() - pointX, 2) + Math.pow(this.client.getMyPlayer().getY() - pointY, 2));
	} 

 Get XP for Level:

	public int getXPForLevel(int level) {
		int points = 0;
		int output = 0;
		for (int lvl = 1; lvl <= level; lvl++) {
			points += Math.floor((double)lvl + 300.0 * Math.pow(2.0, (double)lvl / 7.0));
			if (lvl >= level)
				return output;
			output = (int)Math.floor(points / 4);
		}
		return 0;
	}

Get Level for XP:

	public int getLevelForXP(int exp) {
		int points = 0;
		int output = 0;
		if (exp > 13034430)
			return 99;
		for (int lvl = 1; lvl <= 99; lvl++) {
			points += Math.floor((double) lvl + 300.0
					* Math.pow(2.0, (double) lvl / 7.0));
			output = (int) Math.floor(points / 4);
			if (output >= exp) {
				return lvl;
			}
		}
		return 0;
	}

ALL OF THIS IS USELESS

 

Plus all of these snippets are from rsps servers

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