I don't feel like I'm learning much by just remaking the same fisher/miner/woodcutter as the tutorials, so I like to try and make something that's a bit more demanding. With that being said, this is my failed attempt at an auto fighter for some cows...Script just stands there no matter what changes I've made (posted source is after 3-4 revisions/attempts). And I didn't originally use ID's for anyone that's going to post about it.
public class main extends Script {
private static final int[] COW_ID = { 2808,
2806, 2805 };
private enum State {
IN_COMBAT, ATTACKING, IDLE
};
private State getState() {
if(myPlayer().isAnimating())
return State.IN_COMBAT;
if(myPlayer().isMoving())
return State.ATTACKING;
return State.IDLE;
}
@Override
public void onStart() {
log("Let's get started!");
}
@Override
public int onLoop() throws InterruptedException {
switch (getState()) {
case ATTACKING:
if(!myPlayer().isUnderAttack()){
NPC cow = npcs.closest(COW_ID);
if (cow.isAttackable()) {
cow.interact("Attack-Cow");
}
}
break;
case IN_COMBAT:
sleep(random(300, 400));
break;
case IDLE:
sleep(random(50, 200));
break;
}
return random(200, 300);
}
@Override
public void onExit() {
log("Thanks for running my cow killer!");
}
}
Thanks in advanced.