July 3, 20178 yr How to detect if attacked NPC is dead? I wrote some code, but its awful... private void killFireGiant(RS2Object fireGiant) { fireGiant.interact(ATTACK); while (fireGiant.exists()) { } } Is there any way to avoid loop ? Edited July 3, 20178 yr by Efpkaf
July 5, 20178 yr public void attackNpc(){ NPC npc = getNpcs().closest("Fire Giant"); if (getMap().canReach(npc) && npc.getHealthPercent() > 0 && npc.hasAction("Attack") && !npc.isUnderAttack()) { state = "State: Searching for monsters to kill"; if (npc != null) { if (npc.interact("Attack")) { state = "State: Attacking " + npc.getName(); new ConditionalSleep(3000, 500) { @Override public boolean condition() throws InterruptedException { return !npc.exists() || npc.isUnderAttack(); } }.sleep(); } } } }
July 6, 20178 yr please read the api http://osbot.org/api what i'd suggest is a combonation of checking it's animation != getAnimationStanding() AND isHitBarVisible() AND HEALTH PERCENT <=0 that's just from reading the api for 10 seconds. https://osbot.org/api/org/osbot/rs07/api/model/Character.html
July 6, 20178 yr On 7/3/2017 at 9:18 PM, Efpkaf said: How to detect if attacked NPC is dead? I wrote some code, but its awful... private void killFireGiant(RS2Object fireGiant) { fireGiant.interact(ATTACK); while (fireGiant.exists()) { } } Is there any way to avoid loop ? Firstly a "Fire Giant" is an NPC, not an RS2Object. To avoid a while loop is simple, you just have to think of your script as one big loop. Store the fire giant you are currently attacking in a global variable, so you can check if it is dead and attack a new one if true: private NPC fireGiant; @Override public int onLoop() throws InterruptedException { if (fireGiant == null || !fireGiant.exists() || fireGiant.getHealthPercent() == 0) { attackFireGiant(); } return 200; } private void attackFireGiant() { fireGiant = getNpcs().closest(npc -> npc.getName().equals("Fire Giant") && getMap().canReach(npc) && npc.isAttackable()); if (fireGiant != null && fireGiant.interact("Attack")) { new ConditionalSleep(5000) { @Override public boolean condition() throws InterruptedException { return !fireGiant.isAttackable() || myPlayer().isInteracting(fireGiant); } }.sleep(); } }