You don't have to inverse the bool value in the first if statement just use != operator instead of ==, it will make it easier to read.
Ex. - if (getInventory.getAmount("Redberries") != 3)
You should also remove the for loop and allow the script to re-loop to re-trigger this action. I have found that scripts are much easier to debug/maintain if there is only 1 action happening per loop.
When interacting with something you should wrap it in an if statement so you will only activate your sleep call if the interaction was successful.
Ex. - if (redberries.interact("Pick-from"))
Now for the problem of it not picking the required amount, that is down to the current logic of the script.
If we take a look at this line
RS2Object redberries = getObjects().closest("Redberry bush");
And than look at how you are using that variable
for (int i=0; i<4; i++) {
int berryCount = i;
redberries.interact("Pick-from");
Sleep.sleepUntil(() -> getInventory().getAmount("Redberries") == berryCount + 1, 5000);
}
You can see that in the loop you are not updating the redberries variable to another available bush, so you are trying to pick berries from the same bush even though you have already picked from there.
To fix that you would simply move where you set the variable to inside the loop, but again I don't recommend using for/while loops in scripts except for certain circumstances such as different dropping methods. Also you should always do a null check before using the variable. With the for loop, if i = 0 than, you would do i < 3, to perform an action 3 times, since i is starting at 0. No need to set berrycount == i, just use i.
for (int i = 0; i < 3; i++)
{
RS2Object redberries = getObjects().closest("Redberry bush");
if (redberries != null) {
if (redberries.interact("Pick-from")) {
Sleep.sleepUntil(() -> getInventory().getAmount("Redberries") == (i + 1), 5000);
}
}
}
Let me know if you have any questions 🙂