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.

Storing NPC that player is currently fighting from a distance?

Featured Replies

Hi there,

currently wrapping up a script, in which my player is in ranged combat with an NPC from a distance, so I cant store which exact NPC is closest, as normally this npc is medium-long range. As of now my code looks something along the lines of

private list<npc> npcName;

npcName = script.getNpcs().filter(isNPCDangerous());

private static boolean isNPCDangerous(NPC npc) {
        if( script.myPlayer().isInteracting(npc) && npc.getName().equals("NPC name") && !npc.isUnderAttack())
            return false;
        if (npc.getName().equals("NPC name") && script.myPlayer().isInteracting(npc) || npc.getName().equals("NPC name") && !script.myPlayer().isInteracting(npc) && !npc.isUnderAttack())
            return true;
        else
            return false;
    }

Currently NPCs that are not under attack are included as dangerous when I am in combat with a different NPC, as well as NPCs that are under attack by another player but are in a long animation, or are not being attacked back

Edited by ospaul

I believe the problem is your second if statement. The mix of && and || is confusing and I don't think it works the way you are thinking it does. Try looking into ways to change that.

For example, maybe something like this where it groups the statements:

if ((npc.getName().equals("NPC name") && script.myPlayer().isInteracting(npc)) || (npc.getName().equals("NPC name") && !script.myPlayer().isInteracting(npc) && !npc.isUnderAttack()))

 

EDIT: Your second if statement is actually really confusing. I just realized it contradicts itself so it'll always return true.

Edited by Heist

  • Author

Code got a bit mixed up while transposing from memory, I reduced it to a single if statement and it works now. Brand new to OSBot api so I over complicated

Just an fyi (not sure if this is what you're referring to in previous comment) but your if conditions are redundant.

This:

private static boolean isNPCDangerous(NPC npc) {
        if( script.myPlayer().isInteracting(npc) && npc.getName().equals("NPC name") && !npc.isUnderAttack())
            return false;
        if (npc.getName().equals("NPC name") && script.myPlayer().isInteracting(npc) || npc.getName().equals("NPC name") && !script.myPlayer().isInteracting(npc) && !npc.isUnderAttack())
            return true;
        else
            return false;
    }

should just be ->

private static boolean isNPCDangerous(NPC npc) {
        return (npc.getName().equals("NPC name") && script.myPlayer().isInteracting(npc) || npc.getName().equals("NPC name") && !script.myPlayer().isInteracting(npc) && !npc.isUnderAttack())
    }
  • Author
28 minutes ago, Mom said:

Just an fyi (not sure if this is what you're referring to in previous comment) but your if conditions are redundant.

This:


private static boolean isNPCDangerous(NPC npc) {
        if( script.myPlayer().isInteracting(npc) && npc.getName().equals("NPC name") && !npc.isUnderAttack())
            return false;
        if (npc.getName().equals("NPC name") && script.myPlayer().isInteracting(npc) || npc.getName().equals("NPC name") && !script.myPlayer().isInteracting(npc) && !npc.isUnderAttack())
            return true;
        else
            return false;
    }

should just be ->


private static boolean isNPCDangerous(NPC npc) {
        return (npc.getName().equals("NPC name") && script.myPlayer().isInteracting(npc) || npc.getName().equals("NPC name") && !script.myPlayer().isInteracting(npc) && !npc.isUnderAttack())
    }

Yeah that’s close to what I came up with,  it was a long day haha

Create an account or sign in to comment

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.