qbots 239 Share Posted September 10, 2015 Making a combat script is kind of trivial if you know what you are doing, but for those of you who are new to scripting this may help you. Step 1: Finding the proper NPC to kill import org.dreambot.api.script.AbstractScript; import org.dreambot.api.script.Category; import org.dreambot.api.script.ScriptManifest; import org.dreambot.api.wrappers.interactive.NPC; @ScriptManifest(name = "TutCombat",author = "qbots", version = 1.0, category = Category.COMBAT) public class Combat extends AbstractScript { @Override public int onLoop() { currentNpc = getNpcs().closest(npc -> npc != null && npc.getName() != null && npc.getName().equals(npcName) && !npc.isInCombat() && npc.getInteractingCharacter() == null); if(currentNpc != null) { log("We have found a " + currentNpc.getName() + " to kill!"); } return 100; } private NPC currentNpc; //Let's make this a global variable so we dont have to create a new one each loop public String npcName = "Giant rat"; //This will be changed with our GUI later on } Step 2: Killing our target import org.dreambot.api.script.AbstractScript; import org.dreambot.api.script.Category; import org.dreambot.api.script.ScriptManifest; import org.dreambot.api.wrappers.interactive.NPC; @ScriptManifest(name = "TutCombat",author = "qbots", version = 1.0, category = Category.COMBAT) public class Combat extends AbstractScript { @Override public int onLoop() { currentNpc = getNpcs().closest(npc -> npc != null && npc.getName() != null && npc.getName().equals(npcName) && !npc.isInCombat() && npc.getInteractingCharacter() == null); if(currentNpc != null) { //does the npc exist? if(!getLocalPlayer().isInCombat() && getLocalPlayer().getInteractingCharacter() == null) { //Make sure we aren't in combat or interacting with something if(currentNpc.interact("Attack")) { //currentNpc will return true if we succesfully attacked the rat, if that happens we want to wait a bit to make sure we are in combat sleepUntil(() -> getLocalPlayer().isInCombat() || getLocalPlayer().getInteractingCharacter() != null, 2000); //Wait a max of 2 seconds or until we are in combat } return 100; } else { return 100; } } return 100; } private NPC currentNpc; //Let's make this a global variable so we dont have to create a new one each loop public String npcName = "Giant rat"; //This will be changed with our GUI later on } More will come soon. Next will be eating! Link to comment Share on other sites More sharing options...
QuakedM8 58 Share Posted September 10, 2015 Nice man! Keep it up Link to comment Share on other sites More sharing options...
the0fox 0 Share Posted September 10, 2015 Hey man thanks for the tutorial i have a question on this line currentNpc = getNpcs().closest(npc -> npc != null && npc.getName() != null && npc.getName().equals(npcName) && !npc.isInCombat() && npc.getInteractingCharacter() == null); so if i wanted to find rats for example it would be like this? currentNpc = getNpcs().closest(npc -> npc != null && npc.getName() != null && npc.getName().equals(Rat) && !npc.isInCombat() && npc.getInteractingCharacter() == null); Link to comment Share on other sites More sharing options...
qbots 239 Author Share Posted September 10, 2015 Hey man thanks for the tutorial i have a question on this line currentNpc = getNpcs().closest(npc -> npc != null && npc.getName() != null && npc.getName().equals(npcName) && !npc.isInCombat() && npc.getInteractingCharacter() == null); so if i wanted to find rats for example it would be like this? currentNpc = getNpcs().closest(npc -> npc != null && npc.getName() != null && npc.getName().equals(Rat) && !npc.isInCombat() && npc.getInteractingCharacter() == null); No, you would simple change the variable at the bottom of the script. For example: public string npcName = "Rat"; Link to comment Share on other sites More sharing options...
Club 32 Share Posted September 10, 2015 I dont think having beginners do lambda expressions is a very good idea. Never the less, good job on the tutorial Link to comment Share on other sites More sharing options...
qbots 239 Author Share Posted September 10, 2015 I dont think having beginners do lambada expressions is a very good idea. Never the less, good job on the tutorial This is moreso a "Show people how combat works" Lambdas r better so might as well show them how to use them Link to comment Share on other sites More sharing options...
Club 32 Share Posted September 10, 2015 This is moreso a "Show people how combat works" Lambdas r better so might as well show them how to use them Yeah i agree that Lambdas are better, but so is using the Task system for doing various things. My point is that if your target audience doesn't know how to make a combat script, they probably wont understand lambda expressions. Sorry if i sound like a dick. I just read this in a sassy tone and it makes me sound like a dick xD Link to comment Share on other sites More sharing options...
qbots 239 Author Share Posted September 11, 2015 Yeah i agree that Lambdas are better, but so is using the Task system for doing various things. My point is that if your target audience doesn't know how to make a combat script, they probably wont understand lambda expressions. Sorry if i sound like a dick. I just read this in a sassy tone and it makes me sound like a dick xD wasnt being sassy lol. just saying i guess i can add in how to do it without lambdas Link to comment Share on other sites More sharing options...
Club 32 Share Posted September 11, 2015 wasnt being sassy lol. just saying i guess i can add in how to do it without lambdas yeah just like a regular filter would be dope Link to comment Share on other sites More sharing options...
Vlad 216 Share Posted September 11, 2015 This is moreso a "Show people how combat works" Lambdas r better so might as well show them how to use them IMO you should know what it looks like and how it works and before applying lambdas and then start learning and applying them. :3 Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.