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.

monster detection

Featured Replies

I want to detect if a monster has spawned or not:

If the monster has spawned method is fine, if monster has not spawned goes ape-shit and crashes client:

public boolean getCallisto(){
    boolean b = false;
    NPC Callisto = getNpcs().closest(npc -> npc.getName().equals("Callisto"));
    if(Callisto.isVisible()){
        b = true;
    }

    return b;
}

 

not sure why, but assume there is a better way to detect if an NPC is present or not

Why are you using closest? Also you are not null checking, I wouldn't trust you to write a chicken killer yet alone Callisto :( 

Edit: It was a joke, didn't mean to come off as a personal attack :feels: 

When the monster is spawned the NPC Callisto is not null, however when it isn't spawned it is null, which means you're calling .isVisible() on a null object. This is the reason why your client crashes, have a null check as well in your code.

public boolean getCallisto(){
    boolean b = false;
    NPC Callisto = getNpcs().closest(npc -> npc.getName().equals("Callisto"));
    if(Callisto != null && Callisto.hasAction("Attack")) {
        b = true;
    }

    return b;
}

To illustrate what people are telling here. ALWAYS NULL CHECK.

Also, if spawning takes a while, also a good idea to check if it has the Attack option or any other stuff that's relevant.

  • Author

oh fair I had the null check in my method that called it, not this method. Guess i needed it in both. Now I look at my other scripts i do always nullcheck in the getMonster function rather than function calling it so idk why i didn't this time. Thanks for replies

11 hours ago, Alek said:

Why are you using closest? Also you are not null checking, I wouldn't trust you to write a chicken killer yet alone Callisto :( 

Edit: It was a joke, didn't mean to come off as a personal attack :feels: 

What's better than closest? I've always used that just because it can take a filter as an input?

Edited by scriptersteve

  1. Your function is called getCallisto, but you're returning whether you see Callisto, not whether you've got him. There's plenty more information to gain from an NPC object, such as location, health, etc. But you're not returning that. Instead, you're returning just a bool.
  2. In said function, you're not checking to see whether Callisto is valid (null checks).
  3. You're using a Lambda expression to filter for an NPC by it's name only. That's putting a hat on a hat, when NPCS#getClosest will already let you find NPCs by their name.
  4. In your function, you get Callisto then you check whether Callisto is visible on your screen. I'm certain you intended to check whether Callisto is valid, not visible.
  5. Your entire function seems wholly redundant. Again, just find Callisto and store it as a local variable (outside onLoop), then check whether Callisto is valid (null check) and then do whatever it is you intend to do.

Example:

	NPC callisto;
	
	@Override
	public int onLoop() {
		
		if (callisto != null && callisto.exists()) {
		
			/* TODO: Callisto exists - what now? */
		
		} else {
		
			/* Find Callisto */
			
			callisto = npcs.closest("Callisto");
		}
		
		return 250;
	}

You can expand upon this by only searching for Callisto if your player is located near Callisto (distance check/area check/X,Y check). That way, you're not wasting time searching for Callisto while you're at the Grand Exchange, for instance.

Edited by liverare

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.