LoudPacks Posted February 4, 2016 Posted February 4, 2016 (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 February 4, 2016 by LoudPacks 4
Jim Lahey Posted February 4, 2016 Posted February 4, 2016 Thanks. Will definitely need this if I make a cb script.
inlustra Posted March 13, 2016 Posted March 13, 2016 (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 March 13, 2016 by inlustra 1