Yes your targetTile position was not updating correctly. You must remember that when an enemy (a chicken) dies there is a 2-5 second delay before the dead chicken body disappears and the loot appears on the ground.
I have updated your killMonster() method so that the targetTile always updates correctly and that it loots as soon as your chicken is dead.
private void killMonster(String monsterName) {
//find target marks the spot
target = getNpcs().closest(true, monsterName); // setting true it will find the Real Closest Chicken
targetTile = new Position(target.getX(), target.getY(), 0);
if (!myPlayer().isUnderAttack() && target != null && !target.isUnderAttack() && !target.isAnimating()) {
log("Attacking chicken");
if (target.interact("Attack")) {
log("Wait until the target chicken has 0 hp (waits a max of 30s, instantly stops waiting when the chicken dies though (0 hp)");
new ConditionalSleep(30000) {
@Override
public boolean condition() throws InterruptedException {
return target.getHealthPercent() == 0;
}
}.sleep();
log("Setting the targetTile to where the chicken got 0hp");
targetTile = new Position(target.getX(), target.getY(), 0);
log("The chicken body is still there!");
log("Wait until the target chicken body disappears and the loot appears");
new ConditionalSleep(9500) {
@Override
public boolean condition() throws InterruptedException {
return target == null || !target.exists();
}
}.sleep();
}
}
}
You need your script to respond faster as well, this is a small but very important change, I have changed your onLoop() return from return 4000 to return random(100, 500);
return random(100, 500);
You should also add a chicken cooking method, you want it to cook chicken when:
Your inventory contains Raw chicken
Your inventory is full
I updated your chickenKiller() method with this, I have left the body of cookChicken() blank -- you can code that part yourself, I don't want to do it all for you
public void chickenKiller() {
//I created two areas to where I am able to kill chicken because don't want to enter farm house or outside farmspot and the gate would fuck up everything
if (chickenSpot()[0].contains(myPlayer()) || chickenSpot()[1].contains(myPlayer())){
log("Checking Area");
for (Area area : chickenSpot()) {
if (area.contains(myPlayer())) {
log("Is in farmingSpot will do the following");
if (inventory.contains("Raw chicken") && inventory.isFull()) {
log("Will cook chicken");
statusString = "Cooking Chicken";
// cooking method
cookChicken();
} else {
log("will kill chicken");
statusString = "Killing Chicken";
killMonster("Chicken");
}
}
}} else {
log("Going to FarmSpot");
statusString = "Going to FarmSpot";
walking.webWalk(farmSpot());
}
}
private void cookChicken() {
}