if(cow.getHealth()<8)//im assuming you named the npc variable for cow cow.
//basically this will check the cows health, and if its under 8 it won't attack it.
{
cow.interact("Attack");
}
you can add an extra check as well like if(cow.getHealth()<8&&!cow.isUnderAttack)
that way you can have 2 checks to see, if the cow doesn't have damage and if the cow is not underattack. if you want to add a third check, you can use a message listenter to get the phrase in the chatbox "NPC is already under attack" or whatever by doing
@Override
public void onMessage(Message message) throws InterruptedException
{
if(message.getMessage().toString().contains("Already under attack."))//make sure this has the exact phrase, case sensetive and all
{
log("This cow is already under attack!");
//then have your character move somewhere else or have it do another action after it gets this.
}
}
I'm not the best with the osbot api/java in general but this should help a bit, apaec will probably be able to give you more advice though.
I misread your question my bad, gonna leave that there though incase anyone else is curious.
What you can do is make an area of the cowpen you're killing the cows in, and then you can do something like
Area COWPEN = new Area(top right x, top right y, bottom left x, bottom left y);
if(cow.isUnderAttack)
{
localWalker.walk(COWPEN.getRandomPosition(0));//will get a random area in the cow pen to run off to, then will kill cows that aren't under attack, or keep doing this until it finds one.
}
Defiantly better ways, but this is something that will work.