Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package scripts;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import org.tribot.api.Timing;
- import org.tribot.api.General;
- import org.tribot.api2007.Screen;
- import org.tribot.api2007.types.RSTile;
- import org.tribot.api.DynamicClicking;
- import org.tribot.api.input.Mouse;
- import org.tribot.api.types.generic.Condition;
- import org.tribot.api2007.Camera;
- import org.tribot.api2007.Combat;
- import org.tribot.api2007.Equipment;
- import org.tribot.api2007.GameTab;
- import org.tribot.api2007.Inventory;
- import org.tribot.api2007.Login;
- import org.tribot.api2007.NPCs;
- import org.tribot.api2007.Objects;
- import org.tribot.api2007.Player;
- import org.tribot.api2007.Skills;
- import org.tribot.api2007.Walking;
- import org.tribot.api2007.GameTab.TABS;
- import org.tribot.api2007.types.RSItem;
- import org.tribot.api2007.types.RSNPC;
- import org.tribot.api2007.types.RSObject;
- import org.tribot.script.Script;
- import org.tribot.script.ScriptManifest;
- import org.tribot.script.interfaces.Painting;
- import org.tribot.script.interfaces.Pausing;
- import org.tribot.script.interfaces.RandomEvents;
- @ScriptManifest(authors = { "Okokokok" }, category = "ok_StarterPack", name = "ok_StarterCombat")
- public class ok_StarterCombat extends Script implements Painting, Pausing, RandomEvents {
- boolean paused;
- private double version = 1.00;
- private String weapon = "Training sword",
- armourPiece1 = "Training shield";
- private final String goblinName = "Goblin",
- goblinOption = "Attack",
- doorName = "Door",
- openOption = "Open",
- closeOption = "Close";
- public RSArea deathArea = new RSArea(new RSTile(3216, 3208, 0), new RSTile(3226, 3224, 0)),
- walkArea = new RSArea(new RSTile(3216, 3208, 0), new RSTile(3266, 3244, 0)),
- combatArea = new RSArea(new RSTile(3243, 3244, 0), new RSTile(3249, 3249, 0));
- private final RSTile[] goblinPath = new RSTile[] {new RSTile(3228, 3218, 0),
- new RSTile(3234, 3222, 0),
- new RSTile(3239, 3225, 0),
- new RSTile(3246, 3226, 0),
- new RSTile(3252, 3226, 0),
- new RSTile(3254, 3230, 0),
- new RSTile(3252, 3235, 0),
- new RSTile(3247, 3239, 0),
- new RSTile(3246, 3242, 0)};
- private RSTile openDoorTile = new RSTile(3246, 3243, 0),
- closeDoorTile = new RSTile(3246, 3244, 0);
- // MISC METHODS
- public boolean waitFor(Condition c, long timeout) {
- Timer t = new Timer(timeout);
- while (t.isRunning()) {
- if (c.active()) {
- return true;
- }
- sleep(60, 80);
- }
- return false;
- }
- public boolean loggedOut() {
- return (Login.getLoginState() == Login.STATE.LOGINSCREEN)
- && (!Screen.getColorAt(100, 200).equals(new Color(0, 0, 0)));
- }
- public boolean logout() {
- if (Login.getLoginState() == Login.STATE.INGAME)
- {
- Login.logout();
- for(int x = 0; x < 6; x++)
- {
- if(loggedOut())
- {
- return true;
- }
- sleep(490,510);
- }
- }
- return false;
- }
- public void antiBan(int rotation) {
- int number = General.random(1, 500);
- sleep(200);
- switch (number) {
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- Camera.setCameraRotation(Camera.getCameraRotation() + rotation);
- break;
- case 20:
- case 21:
- case 22:
- case 23:
- case 24:
- case 25:
- case 26:
- case 27:
- case 28:
- case 29:
- case 30:
- case 31:
- Camera.setCameraRotation(Camera.getCameraRotation() + rotation);
- sleep(200);
- break;
- case 50:
- GameTab.open(TABS.INVENTORY);
- sleep(200);
- break;
- case 75:
- case 76:
- break;
- case 89:
- case 90:
- case 91:
- case 92:
- case 93:
- case 94:
- Camera.setCameraAngle(Camera.getCameraRotation() + rotation);
- sleep(200, 400);
- break;
- case 95:
- case 96:
- case 97:
- case 98:
- case 99:
- case 100:
- Camera.setCameraAngle(Camera.getCameraRotation() + rotation);
- sleep(200, 400);
- break;
- }
- }
- // EQUIPMENT METHODS
- private boolean haveItemEquipped(final String itemName){
- RSItem[] item = Equipment.find(itemName);
- return item != null && item.length > 0;
- }
- private boolean haveItemsEquipped(String weaponWorn, String armourWorn1){
- RSItem[] weaponWorn2 = Equipment.find(weaponWorn);
- RSItem[] armourPieceOne = Equipment.find(armourWorn1);
- return weaponWorn2 != null && weaponWorn2.length > 0 && armourPieceOne != null && armourPieceOne.length > 0;
- }
- private void equipItems(final String itemName){
- RSItem[] item = Inventory.find(itemName);
- if (item != null && item.length > 0){
- if (item[0].click("Wield") || item[0].click("Wear")){
- waitFor(new Condition(){
- @Override
- public boolean active(){
- return haveItemEquipped(itemName);
- }
- }, 8000);
- }
- }
- }
- // INVENTORY METHODS
- private boolean checkInvent(){
- RSItem[] invent = Inventory.getAll();
- return invent != null && invent.length > 0;
- }
- private void dropAll(){
- if (checkInvent()){
- Inventory.dropAllExcept();
- }
- }
- // COMBAT METHODS
- private RSTile npcPosition(){
- RSNPC[] npc = NPCs.findNearest(goblinName);
- if (npc != null && npc.length > 0){
- return npc[0].getPosition();
- }
- return null;
- }
- private void fightNPC(String npcName){
- final RSNPC[] npc = NPCs.findNearest(npcName);
- if (npc != null && npc.length > 0 && npc[0].isOnScreen() && combatArea.contains(npcPosition())){
- if (DynamicClicking.clickRSNPC(npc[0], goblinOption)){
- waitFor(new Condition(){
- @Override
- public boolean active(){
- return !Combat.isUnderAttack() && !npc[0].isInCombat() && !Player.isMoving();
- }
- }, 5000);
- }
- }
- }
- // DOOR METHODS}
- private boolean closeToDoor(){
- RSObject[] door = Objects.findNearest(5, doorName);
- RSTile myPos = Player.getPosition();
- if (door != null && door.length > 0){
- if (doorPosition().distanceTo(myPos) < 5){
- return true;
- }
- }
- return false;
- }
- private RSTile doorPosition(){
- RSObject[] door = Objects.findNearest(5, doorName);
- if (door != null && door.length > 0){
- return door[0].getPosition();
- }
- return null;
- }
- private boolean findDoorClosed(){
- RSObject[] door = Objects.findNearest(7, doorName);
- if (door != null && door.length > 0){
- if (doorPosition().equals(closeDoorTile)){
- return true;
- }
- }
- return false;
- }
- private void openDoor(String doorName){
- RSObject[] door = Objects.findNearest(5, doorName);
- if (door != null && door.length > 0){
- if (doorPosition().equals(closeDoorTile)){
- if (DynamicClicking.clickRSObject(door[0], openOption)){
- waitFor(new Condition(){
- @Override
- public boolean active(){
- return doorPosition().equals(openDoorTile);
- }
- }, 15000);
- }
- }
- }
- }
- private void closeDoor(String doorName){
- RSObject[] door = Objects.findNearest(5, doorName);
- if (door != null && door.length > 0){
- if (doorPosition().equals(openDoorTile)){
- if (DynamicClicking.clickRSObject(door[0], closeOption)){
- waitFor(new Condition(){
- @Override
- public boolean active(){
- return doorPosition().equals(closeDoorTile);
- }
- }, 15000);
- }
- }
- }
- }
- // WALKING METHODS
- private void walkCombatArea(){
- if (!Player.isMoving()){
- if (Walking.walkPath(goblinPath)){
- waitFor(new Condition(){
- @Override
- public boolean active(){
- return closeToDoor();
- }
- }, 3000);
- }
- }
- }
- private void walkHut(){
- final RSTile myPos = Player.getPosition();
- if (!findDoorClosed() && !Player.isMoving()){
- if (Walking.walkTo(new RSTile(3247, 3246, 0))){
- waitFor(new Condition(){
- @Override
- public boolean active(){
- return !Player.isMoving() && combatArea.contains(myPos);
- }
- }, 5000);
- }
- }
- }
- // STATES
- public enum State{
- EQUIPING_WEAPONS, WALKING_TO_COMBAT_AREA,
- FIGHTING, LOGING_OUT, OPENING_DOOR,
- WALKING_IN_HUT, CLOSING_DOOR, DROPPING;
- }
- private State getState(){
- RSTile myPos2 = Player.getPosition();
- if (deathArea.contains(myPos2) && !combatArea.contains(myPos2)){
- if (haveItemsEquipped(weapon, armourPiece1)){
- return State.WALKING_TO_COMBAT_AREA;
- }
- if (!haveItemsEquipped(weapon, armourPiece1)){
- return State.EQUIPING_WEAPONS;
- }
- }
- if (combatArea.contains(myPos2) && !walkArea.contains(myPos2)){
- if (!haveItemsEquipped(weapon, armourPiece1)){
- return State.EQUIPING_WEAPONS;
- }
- if (checkInvent() && haveItemsEquipped(weapon, armourPiece1)){
- return State.DROPPING;
- }
- if (findDoorClosed() && !checkInvent() && haveItemsEquipped(weapon, armourPiece1)){
- return State.FIGHTING;
- }
- if (!findDoorClosed() && !checkInvent() && haveItemsEquipped(weapon, armourPiece1)){
- return State.CLOSING_DOOR;
- }
- }
- if (walkArea.contains(myPos2)){
- if (!closeToDoor() && !combatArea.contains(myPos2)){
- return State.WALKING_TO_COMBAT_AREA;
- }
- if (closeToDoor() && findDoorClosed() && !combatArea.contains(myPos2)){
- return State.OPENING_DOOR;
- }
- if (closeToDoor() && !findDoorClosed() && !combatArea.contains(myPos2)){
- return State.WALKING_IN_HUT;
- }
- }
- return State.LOGING_OUT;
- }
- @Override
- public void onPause() {
- paused = true;
- while (paused){
- sleep(200, 300);
- }
- }
- @Override
- public void onResume() {
- paused = false;
- sleep(100, 200);
- }
- private static final long startTime = System.currentTimeMillis();
- Font font = new Font("Calibri", Font.BOLD, 16);
- private State SCRIPT_STATE = getState();
- @SuppressWarnings("deprecation")
- private final int startXP = Skills.getXP("hitpoints");
- private int START_XP;
- @SuppressWarnings("deprecation")
- @Override
- public void onPaint(Graphics g) {
- long timeRan = System.currentTimeMillis() - startTime;
- double multiplier = timeRan / 3600000D;
- int xpGained = Skills.getXP("hitpoints") - START_XP;
- double totalXPGained = (xpGained / 4 * 10) + xpGained;
- g.setFont(font);
- g.setColor(new Color(255, 255, 255));
- g.drawString("ok_StarterCombat V" + version, 558, 220);
- g.drawString("Action: " + SCRIPT_STATE, 558, 235);
- g.drawString("Time running: " + Timing.msToString(timeRan), 558, 250);
- g.drawString("XP Gained p/h: " + (int) (totalXPGained / multiplier), 558, 265);
- g.drawString("XP Gained: " + (int) totalXPGained, 558, 280);
- g.drawString("Kills p/h: " + (int)((totalXPGained / 16.6625) / multiplier), 558, 295);
- g.drawString("Kills done: " + (int) (totalXPGained / 16.6625), 558, 310);
- }
- @SuppressWarnings("deprecation")
- @Override
- public void run() {
- println("Started ok_StarterCombat from the StarterPack");
- START_XP = startXP;
- super.setRandomSolverState(true);
- Walking.setControlClick(true);
- while(true){
- if (loggedOut()) {
- super.setLoginBotState(active);
- } else {
- while (!loggedOut()) {
- SCRIPT_STATE = getState();
- int mSpeed = General.random(180, 200);
- Mouse.setSpeed(mSpeed);
- Walking.setControlClick(true);
- switch (SCRIPT_STATE) {
- case EQUIPING_WEAPONS:
- equipItems(weapon);
- sleep(150, 200);
- equipItems(armourPiece1);
- sleep(150, 200);
- break;
- case FIGHTING:
- int rotation5 = General.random(90, 200);
- antiBan(rotation5);
- fightNPC(goblinName);
- sleep(150, 200);
- break;
- case LOGING_OUT:
- logout();
- stopScript();
- break;
- case WALKING_TO_COMBAT_AREA:
- walkCombatArea();
- sleep(150, 200);
- break;
- case OPENING_DOOR:
- openDoor(doorName);
- sleep(150, 200);
- break;
- case WALKING_IN_HUT:
- walkHut();
- sleep(150, 200);
- break;
- case CLOSING_DOOR:
- closeDoor(doorName);
- sleep(150, 200);
- case DROPPING:
- dropAll();
- sleep(150, 200);
- }
- }
- }
- }
- }
- @Override
- public void onRandom(RANDOM_SOLVERS arg0) {
- paused = true;
- }
- @Override
- public boolean randomFailed(RANDOM_SOLVERS arg0) {
- paused = false;
- return false;
- }
- @Override
- public void randomSolved(RANDOM_SOLVERS arg0) {
- sleep(2000, 3000);
- paused = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement