Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package scripts.rangeguild;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import java.io.IOException;
- import java.net.URL;
- import javax.imageio.ImageIO;
- import org.tribot.api.General;
- import org.tribot.api.Timing;
- import org.tribot.api.input.Mouse;
- import org.tribot.api.util.abc.ABCUtil;
- import org.tribot.api2007.Camera;
- import org.tribot.api2007.ChooseOption;
- import org.tribot.api2007.Equipment;
- import org.tribot.api2007.Game;
- import org.tribot.api2007.Interfaces;
- import org.tribot.api2007.Inventory;
- import org.tribot.api2007.NPCChat;
- import org.tribot.api2007.NPCs;
- import org.tribot.api2007.Objects;
- import org.tribot.api2007.Player;
- import org.tribot.api2007.Skills;
- import org.tribot.api2007.Skills.SKILLS;
- import org.tribot.api2007.Walking;
- import org.tribot.api2007.types.RSInterface;
- import org.tribot.api2007.types.RSItem;
- import org.tribot.api2007.types.RSNPC;
- import org.tribot.api2007.types.RSObject;
- import org.tribot.api2007.types.RSTile;
- import org.tribot.script.Script;
- import org.tribot.script.ScriptManifest;
- import org.tribot.script.interfaces.Painting;
- @ScriptManifest(authors = { "Genka" }, category = "Ranged", name = "GRangeGuild")
- public class Main extends Script implements Painting{
- private int startXp = Skills.getXP(SKILLS.RANGED);
- private ABCUtil abc = new ABCUtil();
- private long time = System.currentTimeMillis();
- private RSTile tile = new RSTile(2672, 3418);
- private boolean running = true;
- @Override
- public void run() {
- while(running) {
- if(hasCoins()) {
- if(Player.getPosition().distanceTo(tile) < 3) {
- if(!competitionStarted()) {
- startCompetition();
- } else if(setCamera()){
- train();
- }
- } else if(!Player.isMoving()) {
- Walking.walkTo(new RSTile(tile.getX() + General.random(-1, 1), tile.getY() + General.random(-1, 1)));
- }
- } else {
- System.out.println("Out of coins. Stopping");
- running = false;
- }
- sleep(10, 50);
- }
- }
- private boolean hasCoins() {
- RSItem[] coins = Inventory.find("Coins");
- if(coins.length > 0) {
- if(coins[0].getStack() > 199) {
- return true;
- }
- }
- return false;
- }
- private boolean setCamera() {
- if(Camera.getCameraAngle() > 48) {
- Camera.setCameraAngle(General.random(30, 48));
- long t = System.currentTimeMillis();
- while(Timing.timeFromMark(t) < 1500 && Camera.getCameraAngle() > 48) {
- sleep(10, 250);
- }
- }
- if(Camera.getCameraRotation() < 260 || Camera.getCameraRotation() > 340) {
- Camera.setCameraRotation(General.random(270, 340));
- long t = System.currentTimeMillis();
- while(Timing.timeFromMark(t) < 1500 && Camera.getCameraAngle() < 260) {
- sleep(10, 250);
- }
- }
- return Camera.getCameraAngle() < 49 && (Camera.getCameraRotation() > 259 && Camera.getCameraRotation() < 341);
- }
- private void train() {
- if(!isInterfaceOpen()) {
- doTimedActions();
- }
- if(!isInterfaceOpen() && !ChooseOption.isOpen()) {
- if(Equipment.isEquipped("Bronze arrow")) {
- clickTarget();
- } else {
- equipArrows();
- }
- } else if((isInterfaceOpen() || Timing.timeFromMark(time) > 3000) && ChooseOption.isOpen()) {
- fireAt();
- } else if(isInterfaceOpen()) {
- closeInterface();
- }
- }
- private void closeInterface() {
- RSInterface face = Interfaces.get(325, 89);
- if(face != null) {
- face.click("Close");
- sleep(10, 400);
- }
- }
- private void fireAt() {
- if(ChooseOption.select("Fire-at")) {
- long t = System.currentTimeMillis();
- while(Timing.timeFromMark(t) < 1500 && isInterfaceOpen()) {
- sleep(10, 250);
- }
- clickTarget();
- time = System.currentTimeMillis();
- }
- }
- private void equipArrows() {
- RSItem arrows[] = Inventory.find("Bronze arrow");
- if(arrows.length > 0) {
- arrows[0].click("Wield");
- long t = System.currentTimeMillis();
- while(Timing.timeFromMark(t) < 1500 && !Equipment.isEquipped("Bronze arrow")) {
- sleep(10, 250);
- }
- }
- }
- private boolean competitionStarted() {
- return Game.getSetting(156) != 0;
- }
- private void clickTarget() {
- RSObject[] target = Objects.getAt(new RSTile(2679, 3426, 0));
- if(target.length > 0) {
- if(target[0].hover()) {
- sleep(10, 100);
- Mouse.click(3);
- }
- }
- }
- private boolean isInterfaceOpen() {
- return Interfaces.get(325) != null;
- }
- private void startCompetition() {
- if(NPCChat.getName() == null && NPCChat.getOptions() == null) {
- talkToGuard();
- } else if (NPCChat.getName() != null) {
- NPCChat.clickContinue(true);
- } else if (NPCChat.getOptions() != null) {
- NPCChat.selectOption("Sure, I'll give it a go." , true);
- }
- }
- private void talkToGuard() {
- RSNPC[] judge = NPCs.find("Competition Judge");
- if(judge.length > 0) {
- if(judge[0].click("Talk-to")) {
- long t = System.currentTimeMillis();
- while(Timing.timeFromMark(t) < 1500 && NPCChat.getName() == null) {
- sleep(10, 500);
- }
- }
- }
- }
- private void doTimedActions() {
- if (abc.shouldCheckTabs()) {
- abc.checkTabs();
- }
- if (abc.shouldCheckXP()) {
- abc.checkXP();
- }
- if (abc.shouldExamineEntity()) {
- abc.examineEntity();
- }
- if (abc.shouldMoveMouse()) {
- abc.moveMouse();
- }
- if (abc.shouldPickupMouse()) {
- abc.pickupMouse();
- }
- if (abc.shouldRightClick()) {
- abc.rightClick();
- }
- if (abc.shouldRotateCamera()) {
- abc.rotateCamera();
- }
- if (abc.shouldLeaveGame()) {
- abc.leaveGame();
- }
- }
- //START: Code generated using Enfilade's Easel
- private Image getImage(String url) {
- try {
- return ImageIO.read(new URL(url));
- } catch(IOException e) {
- return null;
- }
- }
- private final Color color1 = new Color(255, 255, 255);
- private final Font font1 = new Font("Arial", 0, 10);
- private final Image img1 = getImage("https://i.imgur.com/bRetzk3.png");
- public void onPaint(Graphics g1) {
- double multiplier = getRunningTime() / 3600000.0D;
- int xpPerHour = (int) ((Skills.getXP(SKILLS.RANGED) - startXp) / multiplier);
- Graphics2D g = (Graphics2D)g1;
- g.drawImage(img1, 277, 345, null);
- g.setFont(font1);
- g.setColor(color1);
- g.drawString("Runtime: " + Timing.msToString(getRunningTime()), 366, 409);
- g.drawString("Range level: " + Skills.getActualLevel(SKILLS.RANGED), 366, 421);
- g.drawString("XP: " + (Skills.getXP(SKILLS.RANGED) - startXp) + " (" + xpPerHour + ")", 366, 433);
- }
- //END: Code generated using Enfilade's Easel
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement