eleax Posted March 12, 2015 Posted March 12, 2015 (edited) What would the code be for randomizing attack targets? To even create two attack targets would I first have to make a variable as the closest npc, and then make another with the condition variableone !=null? Edited March 12, 2015 by eleax
Botre Posted March 12, 2015 Posted March 12, 2015 (edited) Here's a Java 8 way to do it: Predicate<NPC> predicate = o -> (o != null && o.exists() && o.getName().equals("Rat") && getMap().canReach(o)); List<NPC> potential = getNpcs().getAll().stream().filter(predicate).collect(Collectors.toList()); NPC target = potential.size() > 0 ? potential.get(random.nextInt(potential.size())) : null; Edited March 12, 2015 by Botre 2
eleax Posted March 12, 2015 Author Posted March 12, 2015 Here's a Java 8 way to do it: Predicate<NPC> predicate = o -> (o != null && o.exists() && o.getName().equals("Rat") && getMap().canReach(o)); List<NPC> potential = getNpcs().getAll().stream().filter(predicate).collect(Collectors.toList()); NPC target = potential.size() > 0 ? potential.get(random.nextInt(potential.size())) : null; my scripting knowledge is not enough to understand how that works lol. im really just familiar with the simple commands like npc.closest and like npc.interact