I'm uncertain if there's a rule where if you place loot[0].interact(2); into a boolean if it'll even run that.
Also I believe for this line of code
if (!Players.getMyPlayer().isInCombat()) {
if (loot.length > 0) {
if (loot[0].distanceTo() <= 15) {
loot[0].interact(2);
Time.sleep(500);
}
}
}
return !Players.getMyPlayer().isInCombat();
}
Instead of if (!Players.getMyPlayer().isInCombat()) {, just have
public boolean activate() {
return !Players.getMyPlayer().isInCombat();
}
Because what this says is if !Players.getMyPlayer().isInCombat();, it'll run the execute() code, if it's false it'll do nothing.
You'll want to make a separate class file for looting. For example,
public class Loot implements Strategy {
public boolean activate() {
}
public void execute() {
}
}
Then back at your main class you would add strategies.add(new Loot()); to it, to ensure it runs the code and is provided by the main class your using to run the strategies.
So for your loot class file it would look like,
public class Loot implements Strategy {
public boolean activate() {
for (GroundItem b : GroundItems.getNearest(217, 211, 219, 2485, 985, 988, 987)) {
return b != null && !Players.getMyPlayer().isInCombat();
}
return false;
// So in this instance, the code above would return true for when b != null and when your player is not in combat. B != null meaning it can see the item is there on the ground and has a value not equal to null.
}
@Override
public void execute() {
GroundItem[] loot = GroundItems.getNearest(989,6199,20343);
if (!Players.getMyPlayer().isInCombat()) {
if (loot.length > 0) {
if (loot[0].distanceTo() <= 15) {
loot[0].interact(2);
Time.sleep(500);
}
}
}
}
I hope this helps somewhat. If I said anything wrong I hope a experienced programmer corrects it 😝