package Guardz; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.Image; import java.io.IOException; import java.net.URL; import java.util.Random; import java.util.concurrent.TimeUnit; import javax.imageio.ImageIO; import org.dreambot.api.methods.Calculations; import org.dreambot.api.methods.map.Area; import org.dreambot.api.methods.skills.Skill; import org.dreambot.api.randoms.RandomEvent; import org.dreambot.api.script.AbstractScript; import org.dreambot.api.wrappers.interactive.GameObject; import org.dreambot.api.script.Category; import org.dreambot.api.script.ScriptManifest; import org.dreambot.api.wrappers.interactive.NPC; @ScriptManifest(name = "Guardzzz",author = "Bonnie", version = 1.0, category = Category.COMBAT) public class creb extends AbstractScript { private long timeBegan; private long timeRan; private Image mainPaint = getImage("https://i.imgur.com/HyHHe5d.png"); private int beginningXp; private int currentXp; private String food = "Monkfish"; private int xpGained; private long startTime; Area Guardz = new Area(3203, 3459, 3223, 3470, 0); Area bennkk = new Area(3181, 3434, 3183, 3438, 0); Area fixxx = new Area(3200, 3453, 3229, 3473, 0); private static final Font font1 = new Font("Arial", 1, 12); public void onPaint(Graphics g) { long runtime = (System.currentTimeMillis() - startTime)/1000; long xpGained = getSkillTracker().getGainedExperience(Skill.STRENGTH); g.setColor(Color.WHITE); g.setFont(font1); g.drawImage(mainPaint, 0, 339, null); g.drawString("XP Gained (Hr): " + xpGained + " (" + (int)(xpGained*(3600/(double)runtime)) + ")", 8, 312); g.drawString("Time running: " + String.format("%02d:%02d:%02d", runtime / 3600, (runtime % 3600) / 60, runtime % 60), 8, 332); } 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; } private Image getImage(String url){ try { return ImageIO.read(new URL(url)); }catch (IOException e){ return null; } } public void onStart() { getRandomManager().disableSolver(RandomEvent.DISMISS); startTime = System.currentTimeMillis(); getSkillTracker().start(); timeBegan = System.currentTimeMillis(); beginningXp = getSkills().getExperience(Skill.STRENGTH); } private void antban(){ Random srand = new Random(); double chances = srand.nextDouble(); if(chances < 0.00023){ log("Antiban; changing camera angle..."); getCamera().rotateToEvent(srand.nextInt()+360,srand.nextInt()+90); } } @Override public int onLoop() { if(getInventory().isEmpty()){ if(!getLocalPlayer().isInCombat()) if(!bennkk.contains(getPlayers().localPlayer().getTile())){ log("inv empty, not im combat, walking to bank"); getWalking().walk(bennkk.getRandomTile()); sleep(1499, 2960); } } if(getLocalPlayer().getHealthPercent() < 42) { if(fixxx.contains(getPlayers().localPlayer().getTile())){ if(!getLocalPlayer().isInCombat()){ if (food != null) { log("normal eat"); getInventory().interact(food, "eat"); } sleep(244,555); } } } if(getLocalPlayer().getHealthPercent() < 25) { if(fixxx.contains(getPlayers().localPlayer().getTile())){ if (food != null) { log("panic eat"); getInventory().interact(food, "eat"); } sleep(2000,2111); } } if(!getWalking().isRunEnabled() && getWalking().getRunEnergy() > Calculations.random(30,50)){ getWalking().toggleRun(); } antban(); if(fixxx.contains(getPlayers().localPlayer().getTile())){ if(!getInventory().isEmpty()){ 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 (Guardz.contains(currentNpc)) { 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; } } } } } if(getInventory().isFull()){ log("Full inv"); if(!Guardz.contains(getPlayers().localPlayer().getTile())){ log("full inv not at guard, walking there"); getWalking().walk(Guardz.getRandomTile()); sleep(1699, 2960); } } if(bennkk.contains(getPlayers().localPlayer().getTile())){ if(!getInventory().isFull()){ log("Found bank, banking"); GameObject benk = getGameObjects().closest("Bank booth"); if(benk != null && benk.interact("Bank")){ if(sleepUntil(() -> getBank().isOpen(), 2070)){ getBank().withdraw(7946, 28); sleep(300, 760); if(getBank().close()){ log("done banking"); } } } } } 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 = "Guard"; //This will be changed with our GUI later on }