ItsPeaches 0 Share Posted June 11, 2017 So I just started learning how to script this week. Currently working on a simple cow killer. Heres what i got so far package core; import java.awt.Color; import java.awt.Graphics; import java.util.concurrent.TimeUnit; import org.dreambot.api.methods.Calculations; import org.dreambot.api.methods.map.Area; import org.dreambot.api.methods.skills.Skill; import org.dreambot.api.methods.tabs.Tab; 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(author = "itspeaches", name = "Cow Killer", version = 1.1, description = "Kills cows south of Falador, banks hides", category = Category.COMBAT) public class Main extends AbstractScript { public int currentstate = 3; //GUI variables public String weapon; public boolean Cowhides; //Paint variables private long timeBegan; private long timeRan; private int beginningXP; private int currentXp; private int xpGained; //Areas public Area cows = new Area(3023, 3313, 3043, 3300); public Area lumbridge = new Area(3217, 3224, 3226, 3214); //On Start public void onStart() { //GUI variables weapon = "Event rpg"; Cowhides = false; currentstate = 3; beginningXP = getSkills().getExperience(Skill.STRENGTH); log("Thank you for killing the cows"); timeBegan = System.currentTimeMillis(); } private enum State { FIGHT, DEATHWALK, BANK, WAIT }; private State getState() { if (currentstate == 1) return State.FIGHT; if (currentstate == 2) return State.BANK; if(currentstate == 3) return State.DEATHWALK; return State.WAIT; } public void onExit() { } @SuppressWarnings({ "deprecation" }) @Override public int onLoop() { switch (getState()) { case FIGHT: //If weapon is in inventory, wield it if(getInventory().contains(weapon)){ getInventory().interact(weapon, "Wield"); } //We're in lumbridge switch to deathwalk if(lumbridge.contains(getLocalPlayer())){ log("we're in lumbridge, deathwalking back"); currentstate = 3; break; } //We're in combat, short sleep and antiBan if(getPlayers().myPlayer().isInCombat()){ log("in combat, sleeping"); sleep(Calculations.random(300, 1258)); antiBan(); }else{ //if we're doing cowhides, loot them if(Cowhides == true){ if(getGroundItems().closest("Cowhide") != null){ log("cowhide spotted, looting"); getGroundItems().closest("Cowhide").interact("Take"); sleepUntil(() -> getLocalPlayer().isStandingStill(), Calculations.random(1200, 3000));} } //select the cow and attack NPC cow; cow = getNpcs().closest(npc -> npc != null && npc.getName() != null && npc.getName().equals("Cow") && !npc.isInCombat() && npc.getInteractingCharacter() == null); if(cow != null && !cow.isInCombat() && !getPlayers().myPlayer().isInCombat()){ log("cows here, trying to attack"); cow.interact("Attack"); } } //if inventory is full, bank if(getInventory().isFull()){ log("inventory is full, switching to bank state"); currentstate = 2; } break; case BANK: if(getInventory().isFull()){ log("walking to nearest bank"); getBank().openClosest(); sleep(455, 2241); antiBan(); } if(getBank().isOpen()){ log("bank is open, depositing cowhide"); getBank().depositAll("Cowhide"); sleep(100); getBank().close(); } if(!getInventory().contains("Cowhide")){ log("no cowhides detected, switching to deathwalk to walk back"); currentstate = 3; } break; case DEATHWALK: getWalking().walk(cows.getRandomTile()); antiBan(); sleepUntil(() -> getLocalPlayer().isStandingStill(), Calculations.random(1200, 5000)); if(cows.contains(getLocalPlayer())){ currentstate = 1; } break; case WAIT: break; } return Calculations.random(500, 600); } public void antiBan() { int random = Calculations.random(1, 250); if (random == 1) { if (!getTabs().isOpen(Tab.STATS)) { getTabs().open(Tab.STATS); getSkills().hoverSkill(Skill.STRENGTH); sleep(Calculations.random(1000, 2000)); getTabs().open(Tab.INVENTORY); } } else if (random <= 10) { if (!getTabs().isOpen(Tab.INVENTORY)) { getTabs().open(Tab.INVENTORY); } } else if (random <= 15) { getCamera().rotateToTile(cows.getRandomTile()); } else if (random <= 20) { getCamera().rotateToEntity(getLocalPlayer()); } else if (random <= 88) { if (getMouse().isMouseInScreen()) { if (getMouse().moveMouseOutsideScreen()) { sleep(Calculations.random(1500, 3000)); } } } } public void onPaint(Graphics g) { g.setColor(Color.CYAN); g.fillRect(1, 1, 175, 60); currentXp = getSkills().getExperience(Skill.STRENGTH); xpGained = currentXp - beginningXP; timeRan = System.currentTimeMillis() - this.timeBegan; g.setColor(Color.WHITE); g.drawString("Strenght xp gained: " + xpGained, 1, 40); g.drawString("RunTime: " + ft(timeRan), 1, 15); } //timer stuff private String ft(long duration) { String res = ""; long days = TimeUnit.MILLISECONDS.toDays(duration); long hours = TimeUnit.MILLISECONDS.toHours(duration) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration)); long minutes = TimeUnit.MILLISECONDS.toMinutes(duration) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS .toHours(duration)); long seconds = TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS .toMinutes(duration)); if (days == 0) { res = (hours + ":" + minutes + ":" + seconds); } else { res = (days + ":" + hours + ":" + minutes + ":" + seconds); } return res; } } Before I get going and really into this, how am I doing so far? Good start? What should be done differently? How should i go about my goals or solve my problems? all my java knowledge is self taught. Goals: Implement a more unique antiban. Make a GUI with location selection (including random location on death), weapon input, combat style, and looting cowhides or not. Better paint (lowest priority). Current problems: Started using eclipse window builder for the GUI. Use things like a check box, if its selected set a boolean like lootcowhides to true. however, don't know how to access that variable from my main class to check if its true or not. Sometimes on the deathwalk it'll stop randomly in lumbridge castle. Link to comment Share on other sites More sharing options...
Hashtag 8699 Share Posted June 11, 2017 Hey, be sure to check this thread https://dreambot.org/forums/index.php/topic/8530-scripting-101/. It has instructions on how to create guis and paints for example. Because of your post looks like this for me, I wont comment on that (hard to read it). Link to comment Share on other sites More sharing options...
ItsPeaches 0 Author Share Posted June 11, 2017 You guys rock! thank you both, got my GUI up and working correctly in no time. Not quoting the post since it is very long and I am fairly busy at the moment, but I've read that you do not know how to access the data from the GUI, I can explain that with a pretty rough example but I hope it will help you to understand. public class Main extends AbstractScript { private boolean isLoot; @Override public void onStart() { GUIClassName gui = new GUIClassName("Example"); isLoot = gui.isLoot(); } @Override public int onLoop() { return 0; } private class GUIClassName extends JFrame { private JCheckBox isLoot; GUIClassName(String title) { super(title); add(isLoot = new JCheckBox("Loot hides")); //TODO other fancy ui code } boolean isLoot() { return isLoot.isSelected(); } } } Hey, be sure to check this thread https://dreambot.org/forums/index.php/topic/8530-scripting-101/. It has instructions on how to create guis and paints for example. Because of your post looks like this for me, I wont comment on that (hard to read it). Weird that it came up like that O_o. Thanks for your time! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.