Jump to content

[NOOB] Check Health


LoudPacks

Recommended Posts

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
Link to comment
Share on other sites

  • 1 month later...

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