scriptersteve Posted February 21, 2018 Share Posted February 21, 2018 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 Quote Link to comment Share on other sites More sharing options...
Alek Posted February 21, 2018 Share Posted February 21, 2018 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 1 Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted February 21, 2018 Share Posted February 21, 2018 null checks ... Quote Link to comment Share on other sites More sharing options...
d0zza Posted February 21, 2018 Share Posted February 21, 2018 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. Quote Link to comment Share on other sites More sharing options...
Butters Posted February 22, 2018 Share Posted February 22, 2018 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. Quote Link to comment Share on other sites More sharing options...
scriptersteve Posted February 22, 2018 Author Share Posted February 22, 2018 (edited) 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 What's better than closest? I've always used that just because it can take a filter as an input? Edited February 22, 2018 by scriptersteve Quote Link to comment Share on other sites More sharing options...
scriptersteve Posted February 22, 2018 Author Share Posted February 22, 2018 Note to self, don't leave the scouting bot until 5 mins before the pk trip starts cus u code like a bellend Quote Link to comment Share on other sites More sharing options...
liverare Posted February 22, 2018 Share Posted February 22, 2018 (edited) 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. In said function, you're not checking to see whether Callisto is valid (null checks). 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. 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. 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 February 22, 2018 by liverare Quote Link to comment Share on other sites More sharing options...