Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Dead NPC

Featured Replies

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 by Efpkaf

    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();
                }
            }
        }
    }

 

You can use if (!npc.isAnimating()) to check if an npc is dying

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();
    }
}

 

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.