bzmake 0 Posted April 19, 2015 Hello Dreambot users, I'm trying to learn to script for Dreambot and using it's API. How do I make my bot look for a NPC (monster) and return the state to ATTACK it? or something like : private state ATTACK(){ if (getLocalPlayer().myPlayer().isInCombat()) { //find npc NPC cow = getNpcs().getClosest(new Filter<NPC>() { I'm so confused
Zawy 1012 Posted April 19, 2015 In your onLoop() switch(getState()) { case ATTACK: if (getLocalPlayer().myPlayer().isInCombat()) { NPC cow = getNpcs().getClosest(Cow); //checks if cow isnt null and cow is on screen if(cow!=null && cow.isOnScreen()) { cow.interact("Attack"); } break; } Something like that
bzmake 0 Author Posted April 19, 2015 In your onLoop() switch(getState()) { case ATTACK: if (getLocalPlayer().myPlayer().isInCombat()) { NPC cow = getNpcs().getClosest(Cow); //checks if cow isnt null and cow is on screen if(cow!=null && cow.isOnScreen()) { cow.interact("Attack"); } break; } Something like that Thanks! will try it out! Can I ask you to review my script maybe?
Zawy 1012 Posted April 19, 2015 Thanks! will try it out! Can I ask you to review my script maybe? Sure.
Fran 99 Posted April 19, 2015 I'd recommend to first take a read at this link: http://www.tutorialspoint.com/java/java_decision_making.htm How do I make my bot look for a NPC (monster) and return the state to ATTACK it? //This is how you will get the NPC in-game NPC cow = getNpcs().closest("Cow"); //To attack it cow.interact("Attack"); Also for your player, you can directly call getLocalPlayer(), or getPlayers().myPlayer(), instead of calling getLocalPlayer().myPlayer(). Another thing to point out is to watch out the condition in the if: private state ATTACK(){ if (!getLocalPlayer().isInCombat()) { //if my player is NOT in combat, then I will want to interact w/ an NPC //find npc and attack it NPC cow = getNpcs().getClosest("Cow") cow.interact("Attack"); //to avoid getting the player do a lot of clicks to attack the monster, you can add a sleep condiiton sleepUntil(new Condition(){ @Override public boolean verify() { return getLocalPlayer().isInCombat(); } }, 3000); //the amount of milliseconds the player will wait to click the monster again} } For the sleepUntil & other methods, check here: http://dreambot.org/javadocs/org/dreambot/api/methods/MethodProvider.html Then you could add an Else statement, and add some sleeps there (that would be while your player is certainly in combat)
Vlad 216 Posted April 19, 2015 In your onLoop() switch(getState()) { case ATTACK: if (!getLocalPlayer().myPlayer().isInCombat()) { NPC cow = getNpcs().getClosest(Cow); //checks if cow isnt null and cow is on screen if(cow!=null && cow.isOnScreen()) { cow.interact("Attack"); } break; } Something like that Fixed that for you. Nice explanation @Fran. =)
Zawy 1012 Posted April 19, 2015 Fixed that for you. Nice explanation @Fran. =) Shouldn't copied his code xD
Recommended Posts
Archived
This topic is now archived and is closed to further replies.