February 19, 20179 yr So I'm trying to make a combat script. If another player is in combat with the closest monster to me how do I make my script attack the next closest monster? I've tried making a function to do this: public NPC closestAttackable() { List<NPC> npcs = getNpcs().getAll(); for (i = 0; i < npcs.size(); i++) { if (!npcs.get(i).isUnderAttack() && myPlayer().getArea(7).contains(npcs.get(i))) { return npcs.get(i); } } return null; } but this seems to always return null, any advice? Edited February 19, 20179 yr by d0zza
February 19, 20179 yr I'd personally use a filter for this, not a for loop. something like: npcname = npcs.closest(n -> n.getName().equals("npcname") && areawithnpcs.contains(n) && !n.isHitBarVisible() && n.getHealthPercent() > 0 && !n.isUnderAttack()); if(npcname!= null && !myPlayer().isUnderAttack() && !myPlayer().isMoving()) { npcname.interact("Attack"); }
February 19, 20179 yr Optional<NPC> getAll = getNpcs().getAll().stream().filter(n -> !n.isUnderAttack() && n.getHealthPercent() > 0 && n.getName().equals("X")).findFirst(); if(getAll().get != null) { for(Player player : getPlayers().getAll()) { if(player != myPlayer() && !player.isInteracting(getAll().get()) { getAll().get().interact("Attack") cond sleep } } } probs a bad way to do it but idk if you dont use the optional you can do the same java stream but add .orElse(null) at the end
February 20, 20179 yr I just set a field variable for the filter such as below private Predicate<NPC> npcFilter = n -> n != null && myPlayer().getArea(6).contains(n) && n.getName().contains("name") && n.hasAction("Attack") && n.isAttackable() && !n.isUnderAttack(); NPC npc = s.npcs.getAll().stream().filter(npcFilter).findFirst().get(); if (npc.interact("Attack")) { new ConditionalSleep(6500, 500) { @Override public boolean condition() throws InterruptedException { return combat.isFighting() || myPlayer().isInteracting(npc); } }.sleep(); //max sleep 6.5s, recheck every 500ms. Stops sleeping if fighting or interacting with the filtered npc }
February 20, 20179 yr I just set a field variable for the filter such as below private Predicate<NPC> npcFilter = n -> n != null && myPlayer().getArea(6).contains(n) && n.getName().contains("name") && n.hasAction("Attack") && n.isAttackable() && !n.isUnderAttack(); NPC npc = s.npcs.getAll().stream().filter(npcFilter).findFirst().get(); if (npc.interact("Attack")) { new ConditionalSleep(6500, 500) { @Override public boolean condition() throws InterruptedException { return combat.isFighting() || myPlayer().isInteracting(npc); } }.sleep(); //max sleep 6.5s, recheck every 500ms. Stops sleeping if fighting or interacting with the filtered npc } Edit: It'd also be useful to add map#canReach to the Predicate and sort the NPCs in the stream by distance .sorted((n1, n2) -> Integer.compare(s.map.realDistance(n1), s.map.realDistance(n2)))
February 20, 20179 yr On 2/19/2017 at 8:35 AM, d0zza said: So I'm trying to make a combat script. If another player is in combat with the closest monster to me how do I make my script attack the next closest monster? I've tried making a function to do this: but this seems to always return null, any advice? Not too sure what everyone else in this thread is smoking, all you need is: NPC cow = getNpcs().closest(npc -> npc.getName().startsWith("Cow") && npc.isAttackable()); The isAttackable() method in the Character class returns true if: It is multiway combat and the character has health > 0 OR The character has health > 0 and is not under attack OR The character is interacting with your player Edited February 20, 20179 yr by Explv
February 20, 20179 yr Some of the code suggested here is way over the top lol. Could be done so much more simple like Explv's suggestion Edited February 20, 20179 yr by Shudsy
Create an account or sign in to comment