Jump to content

[NOOB] Check Health


Recommended Posts

Posted (edited)

Checks if your health is above x%:

private boolean healthAbovePercent(double p) {
		boolean flag = false;
		double dynamicLvl = getSkills().getDynamic(Skill.HITPOINTS);
		double staticLvl = getSkills().getStatic(Skill.HITPOINTS);
		if (dynamicLvl >= staticLvl * p) {
			flag = true;
		}
		return flag;
	}

Note: don't flame I like to post basic snippets to help beginning scripters. Being able to search for simple snippets makes it easier to learn at the beginning.

Edited by LoudPacks
  • Like 4
  • 1 month later...
Posted (edited)

Thanks, just getting into RS Script development myself and this kind of API specificity would have probably taken a couple of minutes to find.

 

You could improve your code! No need to declare the flag variable.

private boolean healthAbovePercent(double p) {
	double dynamicLvl = getSkills().getDynamic(Skill.HITPOINTS);
	double staticLvl = getSkills().getStatic(Skill.HITPOINTS);
	return dynamicLvl >= staticLvl * p;
}

Why not take it one step further?


private boolean healthAbovePercent(double p) {
	return skillAbovePercent(Skill.Hitpoints);
}

private boolean skillAbovePercent(Skill skill, double p) {
	double dynamicLvl = getSkills().getDynamic(skill);
	double staticLvl = getSkills().getStatic(skill);
	return dynamicLvl >= staticLvl * p;
}
Edited by inlustra
  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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