Jump to content

ChadMcBro

Members
  • Posts

    4
  • Joined

  • Last visited

  • Feedback

    0%

Profile Information

  • Gender
    Male

ChadMcBro's Achievements

Newbie

Newbie (1/10)

1

Reputation

  1. Having done some tests and updates I realized I had simply over done it with the logic checking. In the end what works best for checking of you are in combat: (in my experience) Sleep.sleepUntil(() -> (!api.getCombat().isFighting() && !currentTarget.exists()), random(10000,15000)); Where I am doing this massive sleep, (random because I am paranoid), as temporary use for some sort of other logic to replace this in the future.
  2. Thanks :), also wow... how did I not realize that... However, that does make me wonder, I do want to do some kind of conditional sleep rather than an while loop or something to just keep going while in combat, just to avoid situation where it might mess this up. But I also eventually want to use this attack task to kill higher leveled monsters and therefore the time for a kill will get longer and longer. Any suggestions? Or is a conditional sleep just not optimal for this kind of application?
  3. I thought it would be a good exercise to create a task based script that kills and loots chaos druids. However, my attack task seems to always be bugging out on me. Occasionally ending the conditional sleep when it is not complete. The script is overall me learning some java and programming through many of the discussion posts on here. package tasks; import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.script.MethodProvider; import utils.Sleep; import utils.Vals; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; import static org.osbot.rs07.script.MethodProvider.random; public class Attack extends Task { public Attack(MethodProvider api) { super(api); } NPC currentTarget; @Override public boolean canProcess() { return Vals.combatReady && !Vals.inCombat; } @Override public void process() throws InterruptedException { Vals.combatReady = false; // Check if any npc is targeting me List<NPC> druidsFocusingMe = api.npcs.getAll().stream() .filter(npc -> api.myPlayer().equals(npc.getInteracting())) .filter(npc -> npc.getName().equals("Chaos druid")) .sorted(Comparator.comparingInt(npc -> api.getMap().realDistance(npc))) .collect(Collectors.toList()); if (!druidsFocusingMe.isEmpty()){ //There is a druid targeting me currentTarget = druidsFocusingMe.get(0); api.log("COMBAT STATE 1: NPC is attempting to attack"); Sleep.sleepUntil(() -> !api.myPlayer().isUnderAttack(), 3000); api.sleep(random(500,1000)); // If the druid could not reach me go attack it if (!api.getCombat().isFighting() && !((api.myPlayer().isInteracting(currentTarget) && currentTarget.isInteracting(api.myPlayer())))) { if (currentTarget.interact("Attack")){ api.log("NPC stuck, attacking NPC targetting me"); Sleep.sleepUntil(() -> (api.myPlayer().isInteracting(currentTarget) && currentTarget.isInteracting(api.myPlayer())), 5000); if (api.getCombat().isFighting()){ api.log("(1) Attack success, in combat"); Vals.combatReady = false; Vals.inCombat = true; } //AN error has occured else{ api.log("(1) Was unable to get into combat, retrying"); api.sleep(random(1000,2000)); Vals.combatReady = true; } } } else { api.log("(0) Attack success, in combat"); Vals.inCombat = true; Vals.combatReady = false; } } //Else if still not in combat else if (!Vals.inCombat) { NPC chaosDruid = api.getNpcs().closest(Vals.CHAOS_DRUID); api.log("COMBAT STATE2: Attacking nearest NPC"); currentTarget = chaosDruid; if (chaosDruid.interact("Attack")){ Sleep.sleepUntil(() -> (api.myPlayer().isInteracting(chaosDruid) && chaosDruid.isInteracting(api.myPlayer())), 5000); if (api.getCombat().isFighting()) { api.log("(2) Attack success, in combat"); Vals.inCombat = true; Vals.combatReady = false; } //An error has occured else{ api.log("(2) Was unable to get into combat, retrying"); api.sleep(random(1000,2000)); Vals.combatReady = true; } } } if (Vals.inCombat){ Sleep.sleepUntil(() -> (!api.myPlayer().isUnderAttack() && !api.getCombat().isFighting() && !api.myPlayer().isAnimating() && currentTarget.getHealthPercent()==0 && !currentTarget.exists() && currentTarget == null), 5000); api.sleep(random(250,550)); api.log("No longer in combat"); Vals.inCombat = false; Vals.readyToLoot = true; } } } I was too lazy to start a GUI so all of my error checking is done through the terminal/logger. I would love some feedback, I can also post the rest of the code if anyone is interested, but it is fairly basic banking and looting.
  4. Hey, I was wondering how far you got on this? I don't think implementing this with some natural mouse movement libraries is all that difficult but I am hesitant on whether or not it will see any results.
×
×
  • Create New...