1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Cow Killer - First Bot

Discussion in 'Projects' started by smitty260, Feb 17, 2016.

  1. smitty260

    Joined:
    Feb 15, 2016
    Messages:
    64
    Likes Received:
    9
    Hey guys.

    I've recently got into developing for RuneMate and read the beginner tutorials for it. I've had a fair bit of experience with Java before so most of it isn't that hard. The hard part is learning the API and working out how to code bots from there. The first bot I decided to make was a basic cow killer that kills cows in Burthorpe and banks their hides at Burthorpe bank. It is a very simple bot and isn't even that great in functionality but I want to try and improve it. The GUI is also basic but does its' job. I'm looking for any feedback from the developer community for improvements I can make or any general tips in relation to bot coding.

    There's probably several bugs relating to this bot but I'll be testing it and improving it as I go but I wanted to get it up here first so that I can potentially get some feedback. My test account had already gotten banned from using this bot for a few hours which isn't surprising. I want to implement some antiban methods but I gotta figure out how to go about that first. I'll update this thread with more updated versions when I get to it. I'm trying to get this bot on the store as an open source bot as I will continually improve it until I am happy with it and then I will hopefully try and fulfill any bot requests that seem viable for a beginner bot developer. Anyways, here's my first bot. Be as harsh as you want, doesn't bother me as long as it's useful feedback. Thanks!

    CowKiller.java
    Code (Javascript):
    1.  
    2. package com.smitty260.cowkiller;
    3.  
    4. import java.awt.Color;
    5. import java.awt.Graphics2D;
    6.  
    7. import javafx.application.Platform;
    8.  
    9. import com.runemate.game.api.client.paint.PaintListener;
    10. import com.runemate.game.api.hybrid.location.Area;
    11. import com.runemate.game.api.hybrid.location.Coordinate;
    12. import com.runemate.game.api.hybrid.net.GrandExchange;
    13. import com.runemate.game.api.hybrid.util.StopWatch;
    14. import com.runemate.game.api.script.framework.task.TaskScript;
    15. import com.smitty260.cowkiller.tasks.TaskAntiban;
    16. import com.smitty260.cowkiller.tasks.TaskBank;
    17. import com.smitty260.cowkiller.tasks.TaskBuryBones;
    18. import com.smitty260.cowkiller.tasks.TaskDropJunk;
    19. import com.smitty260.cowkiller.tasks.TaskKill;
    20. import com.smitty260.cowkiller.tasks.TaskPickup;
    21. import com.smitty260.cowkiller.tasks.TaskWalk;
    22.  
    23. public class CowKiller extends TaskScript implements PaintListener {
    24.  
    25.     public static Area bankArea;
    26.     public static Area cowArea;
    27.     public static Coordinate toBank;
    28.     public static Coordinate toCows;
    29.  
    30.     public static String location = null;
    31.     public static boolean buryBones = false;
    32.     public static String status = "Loading..";
    33.     public static int kills = 0;
    34.     public static int cowhides = 0;
    35.  
    36.     private int hidePrice = 0;
    37.  
    38.     private final StopWatch runtime = new StopWatch();
    39.  
    40.     @Override
    41.     public void onStart(String... args) {
    42.         Platform.runLater(() -> new CowKillerGui(this));
    43.         hidePrice = GrandExchange.lookup(1739).getPrice();
    44.         getEventDispatcher().addListener(this);
    45.         setLoopDelay(350, 1000);
    46.     }
    47.  
    48.     public void initialise() {
    49.         if (location == "Burthorpe") {
    50.             bankArea = new Area.Rectangular(new Coordinate(2892, 3533), new Coordinate(2885, 3540));
    51.             cowArea = new Area.Rectangular(new Coordinate(2881, 3492), new Coordinate(2889, 3482));
    52.             toBank = new Coordinate(2889,3536);
    53.             toCows = new Coordinate(2884, 3487);
    54.         } else if (location == "Lumbridge") {
    55.             bankArea = new Area.Rectangular(new Coordinate(3215, 3261), new Coordinate(3211, 3253));
    56.             cowArea = new Area.Polygonal(new Coordinate(3265, 3255), new Coordinate(3251, 3255)
    57.             , new Coordinate(3251, 3272), new Coordinate(3241, 3284), new Coordinate(3241, 3298)
    58.             , new Coordinate(3267, 3298), new Coordinate(3264, 3289));
    59.             toBank = new Coordinate(3213, 3257);
    60.             toCows = new Coordinate(3258, 3266);
    61.         }
    62.    
    63.         add(new TaskAntiban(), new TaskBuryBones(), new TaskPickup(), new TaskKill(),
    64.                 new TaskDropJunk(), new TaskBank(), new TaskWalk());
    65.         TaskAntiban.antiban.start();
    66.         runtime.start();
    67.     }
    68.  
    69.     @Override
    70.     public void onPause() {
    71.         runtime.stop();
    72.     }
    73.  
    74.     @Override
    75.     public void onResume() {
    76.         runtime.start();
    77.     }
    78.  
    79.     @Override
    80.     public void onPaint(Graphics2D g) {
    81.         Color transWhite = new Color(255, 255, 255, 150);
    82.         Color black = Color.BLACK;
    83.    
    84.         g.setColor(transWhite);
    85.         g.fillRect(0,  0, 190, 200);
    86.    
    87.         g.setColor(black);
    88.         g.drawString("Smitty260's Cow Killer v1.0.1", 10, 20);
    89.         g.drawString("Running: " + runtime.getRuntimeAsString(), 10, 40);
    90.         g.drawString("Status: " + status, 10, 60);
    91.         g.drawString("Cows Murdered: " + kills, 10, 80);
    92.         g.drawString("Cows Murdered p/hr: " + (int)(kills * 3600000D / runtime.getRuntime()), 10, 100);
    93.         g.drawString("Corpse Hides Looted: " + cowhides, 10, 120);
    94.         g.drawString("Corpse Hides Looted p/hr: " + (int)(cowhides * 3600000D / runtime.getRuntime()), 10, 140);
    95.         g.drawString("Profit: " + cowhides * hidePrice, 10, 160);
    96.         g.drawString("Profit p/hr: " + (int)(cowhides * hidePrice * 3600000D / runtime.getRuntime()), 10, 180);
    97.     }
    98.  
    99. }
    100.  

    CowKiller.xml
    Code (Text):
    1.  
    2. <manifest>
    3.     <main-class>com.smitty260.cowkiller.CowKiller</main-class>
    4.     <name>Cow Killer</name>
    5.     <tag-line>Kills cows and banks hides.</tag-line><!--Max of 50 chars-->
    6.     <description>A basic cow killer for Burthorpe and Lumbridge cows. Banks hides at a bank.</description><!--Max of 110 chars-->
    7.     <version>1.0.1</version>
    8.     <compatibility>
    9.         <game>RS3</game>
    10.     </compatibility>
    11.     <categories>
    12.         <category>COMBAT</category>
    13.     </categories>
    14.     <!--Required to publish on the bot store-->
    15.     <internal-id>CowKiller</internal-id>
    16.     <!--The rest are optional-->
    17.     <open-source>true</open-source>
    18.     <hidden>false</hidden> <!--If you need to hide it from the bot store for maintenance-->
    19.     <access>public</access>
    20.     <tags>
    21.         <tag>Cow</tag>
    22.         <tag>Kill</tag>
    23.     </tags>
    24.     <resources>
    25.         <resource>/com/smitty260/cowkiller/CowKiller.fxml</resource>
    26.     </resources>
    27. </manifest>

    CowKillerGui.java
    Code (Javascript):
    1.  
    2. package com.smitty260.cowkiller;
    3.  
    4. import java.io.IOException;
    5.  
    6. import com.runemate.game.api.hybrid.util.Resources;
    7.  
    8. import javafx.fxml.FXMLLoader;
    9. import javafx.scene.Parent;
    10. import javafx.scene.Scene;
    11. import javafx.stage.Stage;
    12.  
    13. public class CowKillerGui extends Stage {
    14.  
    15.     public CowKillerGui (CowKiller script) {
    16.         try {
    17.             FXMLLoader loader = new FXMLLoader();
    18.             loader.setController(new CowKillerController(script, this));
    19.             final Parent root = loader.load(Resources.getAsStream("/com/smitty260/cowkiller/CowKiller.fxml"));
    20.             final Scene scene = new Scene(root);
    21.             setTitle("Cow Killer");
    22.             setScene(scene);
    23.         } catch (IOException e) {
    24.             e.printStackTrace();
    25.         }
    26.         show();
    27.     }
    28.  
    29. }
    30.  

    CowKillerController.java
    Code (Javascript):
    1.  
    2. package com.smitty260.cowkiller;
    3.  
    4. import java.net.URL;
    5. import java.util.ResourceBundle;
    6.  
    7. import javafx.event.ActionEvent;
    8. import javafx.event.EventHandler;
    9. import javafx.fxml.FXML;
    10. import javafx.fxml.Initializable;
    11. import javafx.scene.control.Button;
    12. import javafx.scene.control.CheckBox;
    13. import javafx.scene.control.ComboBox;
    14. import javafx.stage.Stage;
    15.  
    16. public class CowKillerController implements Initializable {
    17.  
    18.     @FXML
    19.     private Button btnStart;
    20.  
    21.     @FXML
    22.     private ComboBox<String> cmbLocation;
    23.  
    24.     @FXML
    25.     private CheckBox chkBones;
    26.  
    27.     @FXML
    28.     public void initialize(URL location, ResourceBundle resources) {
    29.         cmbLocation.getItems().addAll("Burthorpe", "Lumbridge");
    30.         cmbLocation.getSelectionModel().selectFirst();
    31.         btnStart.setOnAction(getbtnStartAction());
    32.     }
    33.  
    34.     private final Stage stage;
    35.     private final CowKiller script;
    36.  
    37.     public CowKillerController(CowKiller script, Stage stage) {
    38.         this.script = script;
    39.         this.stage = stage;
    40.     }
    41.  
    42.     private EventHandler<ActionEvent> getbtnStartAction() {
    43.         return event -> {
    44.             CowKiller.buryBones = chkBones.isSelected();
    45.             CowKiller.location = cmbLocation.getSelectionModel().getSelectedItem();
    46.             script.initialise();
    47.             stage.hide();
    48.         };
    49.     }
    50.  
    51. }
    52.  

    TaskKill.java
    Code (Javascript):
    1.  
    2. package com.smitty260.cowkiller.tasks;
    3.  
    4. import com.runemate.game.api.hybrid.entities.GroundItem;
    5. import com.runemate.game.api.hybrid.entities.Npc;
    6. import com.runemate.game.api.hybrid.local.Camera;
    7. import com.runemate.game.api.hybrid.local.hud.interfaces.Inventory;
    8. import com.runemate.game.api.hybrid.region.GroundItems;
    9. import com.runemate.game.api.hybrid.region.Npcs;
    10. import com.runemate.game.api.hybrid.region.Players;
    11. import com.runemate.game.api.hybrid.util.Filter;
    12. import com.runemate.game.api.rs3.local.hud.interfaces.LootInventory;
    13. import com.runemate.game.api.script.Execution;
    14. import com.runemate.game.api.script.framework.task.Task;
    15. import com.smitty260.cowkiller.CowKiller;
    16.  
    17. public class TaskKill extends Task {
    18.  
    19.     @Override
    20.     public void execute() {
    21.         Npc cow = Npcs.newQuery().names("Cow").actions("Attack").filter(new Filter<Npc>(){
    22.  
    23.             @Override
    24.             public boolean accepts(Npc npc) {
    25.                 return npc.getAnimationId() != 23566;
    26.             }
    27.        
    28.         }).results().nearest();
    29.         CowKiller.status = "Murdering..";
    30.  
    31.         if (cow != null) {
    32.             if (!cow.isVisible()) {
    33.                 Camera.turnTo(cow);
    34.             }
    35.         }
    36.    
    37.         if (cow != null){
    38.             if (cow.interact("Attack", "Cow")) {
    39.                 Execution.delayUntil(()->!cow.isValid(), 15000);
    40.                 CowKiller.kills += 1;
    41.             }
    42.         }
    43.     }
    44.  
    45.     @Override
    46.     public boolean validate() {
    47.         return  Players.getLocal().getAnimationId() == -1 && !Inventory.isFull()
    48.                 && !Npcs.newQuery().names("Cow").actions("Attack").results().isEmpty()
    49.                 && (GroundItems.newQuery().names("Cowhide").filter(new Filter<GroundItem>() {            
    50.                     @Override
    51.                     public boolean accepts(GroundItem item) {
    52.                         return CowKiller.cowArea.contains(item.getPosition());
    53.                     }    
    54.                 }).visible().results().isEmpty()
    55.                         || GroundItems.newQuery().names("Bones").filter(new Filter<GroundItem>() {
    56.                             @Override
    57.                             public boolean accepts(GroundItem item) {
    58.                                 return CowKiller.cowArea.contains(item.getPosition());
    59.                             }
    60.                         }).visible().results().isEmpty() && CowKiller.buryBones)
    61.                 && CowKiller.cowArea.contains(Players.getLocal().getPosition())
    62.                 && Inventory.newQuery().names("Raw beef").results().isEmpty()
    63.                 && Inventory.newQuery().names("Bones").results().isEmpty()
    64.                 && !Players.getLocal().isMoving() && !LootInventory.isOpen();
    65.     }
    66.  
    67. }
    68.  

    TaskBank.java
    Code (Javascript):
    1.  
    2. package com.smitty260.cowkiller.tasks;
    3.  
    4. import com.runemate.game.api.hybrid.entities.GameObject;
    5. import com.runemate.game.api.hybrid.entities.Npc;
    6. import com.runemate.game.api.hybrid.local.Camera;
    7. import com.runemate.game.api.hybrid.local.hud.interfaces.Bank;
    8. import com.runemate.game.api.hybrid.local.hud.interfaces.Inventory;
    9. import com.runemate.game.api.hybrid.region.GameObjects;
    10. import com.runemate.game.api.hybrid.region.Npcs;
    11. import com.runemate.game.api.hybrid.region.Players;
    12. import com.runemate.game.api.script.Execution;
    13. import com.runemate.game.api.script.framework.task.Task;
    14. import com.smitty260.cowkiller.CowKiller;
    15.  
    16. public class TaskBank extends Task {
    17.  
    18.  
    19.  
    20.     @Override
    21.     public void execute() {
    22.         CowKiller.status = "Banking..";
    23.    
    24.         if (Bank.isOpen()) {
    25.             if (Bank.depositInventory()) {
    26.                 Execution.delay(1000, 2000);
    27.                 Bank.close();
    28.             }
    29.         } else {
    30.             if (CowKiller.location == "Burthorpe") {
    31.                 Npc bank = Npcs.getLoaded("Gnome Banker").nearest();
    32.                 if (bank != null) {
    33.                     if (!bank.isVisible()) {
    34.                         Camera.turnTo(bank);
    35.                     }
    36.                     bank.interact("Bank", "Gnome Banker");
    37.                 }
    38.             } else if (CowKiller.location == "Lumbridge") {
    39.                 GameObject bank = GameObjects.getLoaded("Bank chest").nearest();
    40.                 if (bank != null) {
    41.                     if (!bank.isVisible()) {
    42.                         Camera.turnTo(bank);
    43.                     }
    44.                     bank.interact("Use", "Bank chest");
    45.                 }
    46.             }
    47.             Execution.delayUntil(()->Bank.isOpen(), 3000);
    48.         }
    49.     }
    50.  
    51.     @Override
    52.     public boolean validate() {
    53.         return Inventory.isFull() && CowKiller.bankArea.contains(Players.getLocal().getPosition());
    54.     }
    55.  
    56. }
    57.  

    TaskPickup.java
    Code (Javascript):
    1.  
    2. package com.smitty260.cowkiller.tasks;
    3.  
    4. import com.runemate.game.api.hybrid.entities.GroundItem;
    5. import com.runemate.game.api.hybrid.local.Camera;
    6. import com.runemate.game.api.hybrid.local.hud.interfaces.Inventory;
    7. import com.runemate.game.api.hybrid.region.GroundItems;
    8. import com.runemate.game.api.hybrid.region.Players;
    9. import com.runemate.game.api.hybrid.util.Filter;
    10. import com.runemate.game.api.rs3.local.hud.interfaces.LootInventory;
    11. import com.runemate.game.api.script.Execution;
    12. import com.runemate.game.api.script.framework.task.Task;
    13. import com.smitty260.cowkiller.CowKiller;
    14.  
    15. public class TaskPickup extends Task {
    16.  
    17.     @Override
    18.     public void execute() {
    19.         CowKiller.status = "Looting corpse..";
    20.         GroundItem item;
    21.         String itemName;
    22.    
    23.         if (CowKiller.buryBones) {
    24.             item = GroundItems.newQuery().names("Cowhide", "Bones").filter(new Filter<GroundItem>() {
    25.  
    26.                 @Override
    27.                 public boolean accepts(GroundItem item) {
    28.                     return CowKiller.cowArea.contains(item.getPosition());
    29.                 }
    30.                
    31.             }).results().nearest();
    32.         } else {
    33.             item = GroundItems.newQuery().names("Cowhide").filter(new Filter<GroundItem>() {
    34.            
    35.                 @Override
    36.                 public boolean accepts(GroundItem item) {
    37.                     return CowKiller.cowArea.contains(item.getPosition());
    38.                 }
    39.                
    40.             }).results().nearest();
    41.         }
    42.    
    43.         itemName = item.getDefinition().getName();
    44.    
    45.         if (item != null) {
    46.             if (!item.isVisible()) {
    47.                 Camera.turnTo(item);
    48.             }
    49.         }
    50.    
    51.         if (LootInventory.isOpen()) {
    52.             if (CowKiller.buryBones) {
    53.                 if (!LootInventory.newQuery().names("Cowhide", "Bones").results().isEmpty()) {
    54.                     if (!LootInventory.newQuery().names("Cowhide").results().isEmpty()) {
    55.                         if (LootInventory.take("Cowhide")) {
    56.                             CowKiller.cowhides += 1;
    57.                         }
    58.                     }
    59.                     if (!LootInventory.newQuery().names("Bones").results().isEmpty()) {
    60.                         LootInventory.take("Bones");
    61.                     }
    62.                     if (LootInventory.newQuery().names("Cowhide", "Bones").results().isEmpty()) {
    63.                         LootInventory.close();
    64.                     }
    65.                 } else {
    66.                     LootInventory.close();
    67.                 }
    68.             } else {
    69.                 if (!LootInventory.newQuery().names("Cowhide").results().isEmpty()) {
    70.                         if (LootInventory.take("Cowhide")) {
    71.                             CowKiller.cowhides += 1;
    72.                     }
    73.                     if (LootInventory.newQuery().names("Cowhide").results().isEmpty()) {
    74.                         LootInventory.close();
    75.                     }
    76.                 } else {
    77.                     LootInventory.close();
    78.                 }
    79.             }
    80.         }
    81.    
    82.         if (item != null) {
    83.             if (item.interact("Take", itemName)) {
    84.                 Execution.delayUntil(()->!item.isValid(), 5000);
    85.                 if (item != null && !item.isValid() && itemName.matches("Cowhide")) {
    86.                     CowKiller.cowhides += 1;
    87.                 }
    88.             }
    89.         }
    90.    
    91.     }
    92.  
    93.     @Override
    94.     public boolean validate() {
    95.         return Players.getLocal().getTarget() == null
    96.                 && (!GroundItems.newQuery().names("Cowhide").filter(new Filter<GroundItem>() {            
    97.                     @Override
    98.                     public boolean accepts(GroundItem item) {
    99.                         return CowKiller.cowArea.contains(item.getPosition());
    100.                     }    
    101.                 }).visible().results().isEmpty()
    102.                         || !GroundItems.newQuery().names("Bones").filter(new Filter<GroundItem>() {
    103.                             @Override
    104.                             public boolean accepts(GroundItem item) {
    105.                                 return CowKiller.cowArea.contains(item.getPosition());
    106.                             }
    107.                         }).visible().results().isEmpty() && CowKiller.buryBones)
    108.                 && !Inventory.isFull()
    109.                 && CowKiller.cowArea.contains(Players.getLocal().getPosition())
    110.                 && !Players.getLocal().isMoving();
    111.     }
    112.  
    113. }
    114.  

    TaskWalk.java
    Code (Javascript):
    1.  
    2. package com.smitty260.cowkiller.tasks;
    3.  
    4. import com.runemate.game.api.hybrid.entities.GameObject;
    5. import com.runemate.game.api.hybrid.local.Camera;
    6. import com.runemate.game.api.hybrid.local.hud.interfaces.Inventory;
    7. import com.runemate.game.api.hybrid.location.Coordinate;
    8. import com.runemate.game.api.hybrid.location.navigation.Traversal;
    9. import com.runemate.game.api.hybrid.location.navigation.web.WebPath;
    10. import com.runemate.game.api.hybrid.region.GameObjects;
    11. import com.runemate.game.api.hybrid.region.Players;
    12. import com.runemate.game.api.hybrid.util.Filter;
    13. import com.runemate.game.api.script.framework.task.Task;
    14. import com.smitty260.cowkiller.CowKiller;
    15.  
    16. public class TaskWalk extends Task {
    17.  
    18.     private boolean needToBank;
    19.     private boolean needToReturn;
    20.     private WebPath walkToBank;
    21.     private WebPath walkToCows;
    22.  
    23.     @Override
    24.     public void execute() {
    25.         if (needToBank) {
    26.             walkToBank = Traversal.getDefaultWeb().getPathBuilder().buildTo(CowKiller.toBank);
    27.             if (walkToBank != null) {
    28.                 CowKiller.status = "Walking to bank..";
    29.                 walkToBank.step(true);
    30.             }
    31.         } else if (needToReturn) {
    32.             walkToCows = Traversal.getDefaultWeb().getPathBuilder().buildTo(CowKiller.toCows);
    33.             if (walkToCows != null) {
    34.                 CowKiller.status = "Walking to murder pen..";
    35.                 if (openGate()) {
    36.                     return;
    37.                 }
    38.                 walkToCows.step(true);
    39.             }
    40.         }
    41.     }
    42.  
    43.     private boolean openGate() {
    44.         GameObject gate = GameObjects.newQuery().names("Gate").within(CowKiller.cowArea).filter(new Filter<GameObject>() {
    45.  
    46.             @Override
    47.             public boolean accepts(GameObject gate) {
    48.                 return gate != null && gate.getDefinition().getActions().contains("Open")
    49.                         && Players.getLocal().getPosition().distanceTo(gate) < 10;
    50.             }
    51.        
    52.         }).results().nearest();
    53.         if (gate == null)
    54.             return false;
    55.         if (!gate.isVisible())
    56.             Camera.turnTo(gate);
    57.         return gate.interact("Open", "Gate");
    58.     }
    59.  
    60.     @Override
    61.     public boolean validate() {
    62.         Coordinate pos = Players.getLocal().getPosition();
    63.         needToBank = Inventory.isFull() && !CowKiller.bankArea.contains(pos);
    64.         needToReturn = !Inventory.isFull() && !CowKiller.cowArea.contains(pos);
    65.         return needToBank || needToReturn;
    66.     }
    67.  
    68. }
    69.  

    TaskDropJunk.java
    Code (Javascript):
    1.  
    2. package com.smitty260.cowkiller.tasks;
    3.  
    4. import com.runemate.game.api.hybrid.local.hud.interfaces.Inventory;
    5. import com.runemate.game.api.hybrid.local.hud.interfaces.SpriteItem;
    6. import com.runemate.game.api.hybrid.region.Players;
    7. import com.runemate.game.api.script.Execution;
    8. import com.runemate.game.api.script.framework.task.Task;
    9. import com.smitty260.cowkiller.CowKiller;
    10.  
    11. public class TaskDropJunk extends Task {
    12.  
    13.     @Override
    14.     public void execute() {
    15.         SpriteItem junk;
    16.         CowKiller.status = "Dropping crap..";
    17.    
    18.         if (!Inventory.newQuery().names("Raw beef").results().isEmpty()) {
    19.             junk = Inventory.newQuery().names("Raw beef").results().first();
    20.             if (junk != null)
    21.                 junk.interact("Drop", "Raw beef");
    22.         } else {
    23.             junk = Inventory.newQuery().names("Bones").results().first();
    24.             if (junk != null)
    25.                 junk.interact("Drop", "Bones");
    26.         }
    27.         Execution.delayUntil(()->!junk.isValid(), 2000);
    28.     }
    29.  
    30.     @Override
    31.     public boolean validate() {
    32.         return !Inventory.newQuery().names("Raw beef").results().isEmpty() ||
    33.                 !Inventory.newQuery().names("Bones").results().isEmpty()&&
    34.                 Players.getLocal().getTarget() == null;
    35.     }
    36.  
    37. }
    38.  

    TaskAntiban.java
    Code (Javascript):
    1.  
    2. package com.smitty260.cowkiller.tasks;
    3.  
    4. import com.runemate.game.api.hybrid.entities.GroundItem;
    5. import com.runemate.game.api.hybrid.input.Mouse;
    6. import com.runemate.game.api.hybrid.local.Camera;
    7. import com.runemate.game.api.hybrid.local.hud.interfaces.InterfaceWindows;
    8. import com.runemate.game.api.hybrid.local.hud.interfaces.Inventory;
    9. import com.runemate.game.api.hybrid.local.hud.interfaces.SpriteItem;
    10. import com.runemate.game.api.hybrid.region.GroundItems;
    11. import com.runemate.game.api.hybrid.util.StopWatch;
    12. import com.runemate.game.api.hybrid.util.calculations.Random;
    13. import com.runemate.game.api.script.Execution;
    14. import com.runemate.game.api.script.framework.task.Task;
    15. import com.smitty260.cowkiller.CowKiller;
    16.  
    17. public class TaskAntiban extends Task {
    18.  
    19.     public static StopWatch antiban = new StopWatch();
    20.     int interval = 0;
    21.  
    22.     public TaskAntiban() {
    23.         interval = Random.nextInt(30, 60);
    24.     }
    25.  
    26.     @Override
    27.     public void execute() {
    28.         CowKiller.status = "Antiban.. ing..";
    29.         Execution.delay(1000, 3000);
    30.         int action = Random.nextInt(1, 5);
    31.    
    32.         switch (action) {
    33.         case 1:
    34.             int yaw = Random.nextInt(0, 360);
    35.             double pitch = Random.nextDouble(0.1, 0.6);
    36.             Camera.turnTo(yaw, pitch);
    37.             Execution.delay(1000, 3000);
    38.             break;
    39.         case 2:
    40.             int item = Random.nextInt(1, 3);
    41.             if (item == 1) {
    42.                 SpriteItem randItem = Inventory.newQuery().results().random();
    43.                 if (randItem != null) {
    44.                     Mouse.move(randItem);
    45.                 }
    46.             }
    47.             Execution.delay(1000, 3000);
    48.             if (item == 2) {
    49.                 GroundItem randItem = GroundItems.newQuery().results().random();
    50.                 if (randItem != null) {
    51.                     Mouse.move(randItem);
    52.                 }
    53.             }
    54.             Execution.delay(1000, 3000);
    55.             break;
    56.         case 3:
    57.             InterfaceWindows.getSkills().open();
    58.             Execution.delay(1000, 3000);
    59.             break;
    60.         case 4:
    61.             InterfaceWindows.getMagic().open();
    62.             Execution.delay(1000, 3000);
    63.             break;
    64.         }
    65.    
    66.         if (!InterfaceWindows.getInventory().isOpen()) {
    67.             InterfaceWindows.getInventory().open();
    68.         }
    69.    
    70.         antiban.reset();
    71.         interval = Random.nextInt(30, 60);
    72.     }
    73.  
    74.     @Override
    75.     public boolean validate() {
    76.         return (interval * 1000) <= (int)antiban.getRuntime();
    77.     }
    78.  
    79. }
    80.  

    TaskBuryBones.java
    Code (Javascript):
    1.  
    2. package com.smitty260.cowkiller.tasks;
    3.  
    4. import com.runemate.game.api.hybrid.local.hud.interfaces.Inventory;
    5. import com.runemate.game.api.hybrid.local.hud.interfaces.SpriteItem;
    6. import com.runemate.game.api.hybrid.region.Players;
    7. import com.runemate.game.api.script.Execution;
    8. import com.runemate.game.api.script.framework.task.Task;
    9. import com.smitty260.cowkiller.CowKiller;
    10.  
    11. public class TaskBuryBones extends Task {
    12.  
    13.     @Override
    14.     public void execute() {
    15.         SpriteItem bones = Inventory.newQuery().names("Bones").results().random();
    16.         CowKiller.status = "Burying corpse..";
    17.    
    18.         if (bones != null) {
    19.             if (bones.interact("Bury", "Bones"))
    20.                 Execution.delayUntil(()->!bones.isValid(), 3000);
    21.         }
    22.     }
    23.  
    24.     @Override
    25.     public boolean validate() {
    26.         return Players.getLocal().getTarget() == null && CowKiller.buryBones
    27.                 && !Inventory.newQuery().names("Bones").results().isEmpty()
    28.                 && !Players.getLocal().isMoving();
    29.     }
    30.  
    31. }
    32.  

    Updates
    v1.0
    - Created a simple antiban task
    - Changed the traversal method from WebPath to RegionPath
    - Minor changes

    v1.0.1
    - Added a new location: Lumbridge
    - Added ability to bury bones
    - Added a startup GUI (for multiple locations and bones support)
    - Added more null checks (I think all are covered)
    - Minor improvements
    - Added to bot store!

    What's Next?
    - Refactor code to make the actions performed smoother
    - Make the antiban better
    - Improved GUI: better looking, ability to hide/show it, skill tracking in another tab of the GUI
    - Change GUI from AWT to JFX
    - Make player open gate at Lumbridge murder pen if the loot/cow is on the other side

    Known Bugs

    - Probably
     
    #1 smitty260, Feb 17, 2016
    Last edited: Mar 3, 2016
  2. VAG

    VAG

    Joined:
    Apr 21, 2015
    Messages:
    142
    Likes Received:
    28
    Love the fact people think that human-like actions like hovering on random item's, checking defence xp when doing firemaking actually are antiban..
    Other than that, your code looks fairly decent, good luck.
     
  3. Derk

    Derk 12 year old normie

    Joined:
    Jan 8, 2015
    Messages:
    2,766
    Likes Received:
    1,339
    A few tips:

    AWT/SWING is going to be deprecated in Spectre, rendering your paint useless. JFX is going to be the new platform for progress managing.

    Your bot doesn't involve any null checking. Things like NPC's and gameobjects are very prone to null, so check if != null before interacting with it.
     
  4. smitty260

    Joined:
    Feb 15, 2016
    Messages:
    64
    Likes Received:
    9
    Well I wasn't sure how to make an antiban hahaha.

    Oh cool. Great news haha. When I re-design the GUI I'll use JFX. I wasn't sure how to use JFX for GUIs as I had only used Swing before haha. With the latest version (which I haven't put up yet) I've done null checks for most of (if not all) the NPCs and GameObjects I think. :)
     
  5. Derk

    Derk 12 year old normie

    Joined:
    Jan 8, 2015
    Messages:
    2,766
    Likes Received:
    1,339
    Code (Javascript):
    1. if (cow.interact("Attack", "Cow")) { //stuff }
    I would null check cow before interacting, that's what I'm saying. Also a tip for local player related code, store Player.getLocal() as Player player or something, and when you call it just check if player != null. Out of experience it also nulls a lot somehow.
     
  6. smitty260

    Joined:
    Feb 15, 2016
    Messages:
    64
    Likes Received:
    9
    Yeah I've changed most of that now like this for example

    Code (Javascript):
    1. if (cow != null){
    2.             if (cow.interact("Attack", "Cow")) {
    3.                 Execution.delayUntil(()->!cow.isValid(), 15000);  
    4.                 CowKiller.kills += 1;
    5.             }  
    6.         }
    Thank you for the tip. I'll try and use that when I can. :)
     
    Derk likes this.
  7. Derk

    Derk 12 year old normie

    Joined:
    Jan 8, 2015
    Messages:
    2,766
    Likes Received:
    1,339
    You really should join the dev chat, a lot of people willing to share information about API and just generally nice people in there: Slack
     
  8. smitty260

    Joined:
    Feb 15, 2016
    Messages:
    64
    Likes Received:
    9
    Didn't even know there was one. I definitely will. Thank you.
     
  9. Blazer285

    Joined:
    Mar 4, 2016
    Messages:
    10
    Likes Received:
    0
    Anti ban is logging out randomly or going afk for a while and why bit cows one of the more watched areas in runescape I suggest hitting in oolag what ever that place is called low ban rate there since almost no one goes there
     
  10. smitty260

    Joined:
    Feb 15, 2016
    Messages:
    64
    Likes Received:
    9
    The antiban shouldn't logout. The only thing that logs the player out is the break handler. I just did the areas I did because they're just the main cow spots. Not sure what spot you're talking about haha.
     
  11. Blazer285

    Joined:
    Mar 4, 2016
    Messages:
    10
    Likes Received:
    0
    Talking about this area Gu'Tanoth has the lowest ban rate there
     
  12. smitty260

    Joined:
    Feb 15, 2016
    Messages:
    64
    Likes Received:
    9
    You mean the cows north of the Yanille wall? I could add that in but I need a members character first. Lol. Working on getting a bond for one of my chars so I can code some P2P features.
     
  13. Blazer285

    Joined:
    Mar 4, 2016
    Messages:
    10
    Likes Received:
    0
    Good job :) I dont code to much nxt will ruin it and think out side the box for scripts bots don't do what people already did
     

Share This Page

Loading...