Here's an example of checking health percentage, and eating if below a threshold:
private int getHpPercent() {
int staticHp = getSkills().getStatic(Skill.HITPOINTS);
int dynamicHp = getSkills().getDynamic(Skill.HITPOINTS);
int hpPercent = 100 * (dynamicHp / staticHp);
return hpPercent;
}
// --- in your onLoop somewhere --- //
// ...
int hpThreshold = 50; // 50% for example
if (getHpPercent() < hpThreshold) {
log("Man, I could really use a lobster rn");
String foodToEat = "Lobster";
if (getInventory().contains(foodToEat)) {
if (getInventory().interact("Eat", foodToEat)) {
log("Man, that was a tasty lobster!");
}
}
}
// ...
How skills work:
Good luck
-Apa
Edit: I've had a look at your code, it looks like you're trying to do too much in one go! If this is your first script, start of in stages. Here's what I would do from here on:
Maybe try a simple side project, for example making a very basic woodcutting script. This will help you get the hang of some inventory/rs2object basics
If you're super keen on fleshcrawlers, build the script in stages. First do the eating. Then the fighting. Then the banking. Don't try and do it all at once
Send me a PM if/when you get stuck, i'm always happy to help. It's a super steep learning curve, but if you know a bit of programming already (no, CSS or HTML won't help you here ahah), then you're in a good shape.
Once you feel confident with the API, start branching out and learning about Java itself, object orientation and the concepts involved. It's much easier to learn this stuff when you have the basic syntax down!