Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.osbot.rs07.api.Inventory;
- import org.osbot.rs07.api.model.GroundItem;
- import org.osbot.rs07.api.ui.Skill;
- import org.osbot.rs07.script.Script;
- import org.osbot.rs07.script.ScriptManifest;
- import java.awt.*;
- import java.io.IOException;
- import java.net.URL;
- import java.util.concurrent.TimeUnit;
- import javax.imageio.ImageIO;
- import java.awt.event.*;
- import javax.swing.*;
- @ScriptManifest(name = "AFKer", author = "Computor", version = 1.0, info = "", logo = "")
- public class AFKer extends Script {
- private long timeBegan;
- private int xpPerHour;
- boolean test = true;
- public int totalXPGained;
- public String[] temp;
- //GUI
- botGUI g = new botGUI();
- AFKerItems g2 = new AFKerItems();
- public boolean guiWait = true;
- public String foodToEat;
- public int skillDisplay;
- //end GUI
- private int beginningAttack;
- private int currentAttackXp;
- private int currentAttackLevel;
- private int attackXpGained;
- private double nextAttackLevelXp;
- private long timeAttackTNL;
- private double xpTillNextAttackLevel;
- private int beginningHitpoints;
- private int currentHitpointsXp;
- private int hitpointsXpGained;
- private int beginningStrength;
- private int currentStrengthXp;
- private int currentStrengthLevel;
- private int strengthXpGained;
- private double nextStrengthLevelXp;
- private long timeStrengthTNL;
- private double xpTillNextStrengthLevel;
- private int beginningDefense;
- private int currentDefenseXp;
- private int currentDefenseLevel;
- private int defenseXpGained;
- private double nextDefenseLevelXp;
- private long timeDefenseTNL;
- private double xpTillNextDefenseLevel;
- final int[] XP_TABLE =
- {
- 0, 0, 83, 174, 276, 388, 512, 650, 801, 969, 1154,
- 1358, 1584, 1833, 2107, 2411, 2746, 3115, 3523, 3973, 4470, 5018,
- 5624, 6291, 7028, 7842, 8740, 9730, 10824, 12031, 13363, 14833,
- 16456, 18247, 20224, 22406, 24815, 27473, 30408, 33648, 37224,
- 41171, 45529, 50339, 55649, 61512, 67983, 75127, 83014, 91721,
- 101333, 111945, 123660, 136594, 150872, 166636, 184040, 203254,
- 224466, 247886, 273742, 302288, 333804, 368599, 407015, 449428,
- 496254, 547953, 605032, 668051, 737627, 814445, 899257, 992895,
- 1096278, 1210421, 1336443, 1475581, 1629200, 1798808, 1986068,
- 2192818, 2421087, 2673114, 2951373, 3258594, 3597792, 3972294,
- 4385776, 4842295, 5346332, 5902831, 6517253, 7195629, 7944614,
- 8771558, 9684577, 10692629, 11805606, 13034431, 200000000
- };
- //paint background
- private final Image bg = getImage("http://s12.postimg.org/wty7h6sb1/AFKer.png");
- private final Image bg1 = getImage("http://s1.postimg.org/hoow91tdb/Untitled_1.png");
- public JTextPane itemsToPickUp;
- private Image getImage(String url)
- {
- try
- {
- return ImageIO.read(new URL(url));
- }
- catch (IOException e) {}
- return null;
- }
- //end paint background
- @Override
- public void onStart() {
- //Code here will execute before the loop is started
- timeBegan = System.currentTimeMillis();
- beginningAttack = skills.getExperience(Skill.ATTACK);
- beginningHitpoints = skills.getExperience(Skill.HITPOINTS);
- beginningStrength = skills.getExperience(Skill.STRENGTH);
- beginningDefense = skills.getExperience(Skill.DEFENCE);
- timeAttackTNL = 0;
- timeStrengthTNL = 0;
- timeDefenseTNL = 0;
- g2.setVisible(true);
- g.setVisible(true);
- }
- @Override
- public void onExit() {
- //Code here will execute after the script ends
- /**
- log("End of Computor's AFKer."); //logs in console
- log("----------------------------------------------------------------------------------------");
- log("You gained a total of " + totalXPGained + " XP, " + attackXpGained +
- " attack XP, " + strengthXpGained + " strength XP, and " + defenseXpGained + "defence XP.");
- log("----------------------------------------------------------------------------------------");
- */
- //for some reason the script takes forever to exit when I use the logs.
- }
- @Override
- public int onLoop() throws InterruptedException
- {
- int currentHP = skills.getDynamic(Skill.HITPOINTS);
- final int timeToEat = skills.getStatic(Skill.HITPOINTS) / 2;
- if (currentHP <= timeToEat)
- if(foodToEat != null){
- inventory.interact("Eat", foodToEat);
- if(!inventory.contains(foodToEat)){
- Toolkit.getDefaultToolkit().beep();
- }
- }
- for (int i = 0; i < temp.length; i++){
- if (groundItems.closest(temp[i]) != null) {
- GroundItem loot = groundItems.closest(temp[i]);
- loot.interact("Take");
- }
- }
- return random(0, 123);
- }
- @Override
- public void onPaint(Graphics2D g) {
- //This is where you will put your code for paint(s)
- //background paint
- Graphics2D gr = g;
- g.drawImage(bg, 4, 341, null);
- if (test == false){
- if(!inventory.contains(foodToEat)){
- g.drawImage(bg1, 1, 1, null);
- }
- }
- //attack
- currentAttackXp = skills.getExperience(Skill.ATTACK);
- currentAttackLevel = skills.getStatic(Skill.ATTACK);
- attackXpGained = currentAttackXp - beginningAttack;
- xpPerHour = (int)( attackXpGained / ((System.currentTimeMillis() - this.timeBegan) / 3600000.0D));
- nextAttackLevelXp = XP_TABLE[currentAttackLevel + 1];
- xpTillNextAttackLevel = nextAttackLevelXp - currentAttackXp;
- if (attackXpGained >= 1)
- {
- timeAttackTNL = (long) ((xpTillNextAttackLevel / xpPerHour) * 3600000);
- }
- if (skillDisplay == 1){
- g.drawString("" + ft(timeAttackTNL), 377, 427);
- }
- g.drawString("" + attackXpGained, 203, 427);
- //strength
- currentStrengthXp = skills.getExperience(Skill.STRENGTH);
- currentStrengthLevel = skills.getStatic(Skill.STRENGTH);
- strengthXpGained = currentStrengthXp - beginningStrength;
- xpPerHour = (int)( strengthXpGained / ((System.currentTimeMillis() - this.timeBegan) / 3600000.0D));
- nextStrengthLevelXp = XP_TABLE[currentStrengthLevel + 1];
- xpTillNextStrengthLevel = nextStrengthLevelXp - currentStrengthXp;
- if (strengthXpGained >= 1)
- {
- timeStrengthTNL = (long) ((xpTillNextStrengthLevel / xpPerHour) * 3600000);
- }
- if (skillDisplay == 2){
- g.drawString("" + ft(timeStrengthTNL), 377, 427);
- }
- g.drawString("" + strengthXpGained,220, 458);
- //Defence
- currentDefenseXp = skills.getExperience(Skill.DEFENCE);
- currentDefenseLevel = skills.getStatic(Skill.DEFENCE);
- defenseXpGained = currentDefenseXp - beginningDefense;
- xpPerHour = (int)( defenseXpGained / ((System.currentTimeMillis() - this.timeBegan) / 3600000.0D));
- nextDefenseLevelXp = XP_TABLE[currentDefenseLevel + 1];
- xpTillNextDefenseLevel = nextDefenseLevelXp - currentDefenseXp;
- if (defenseXpGained >= 1)
- {
- timeDefenseTNL = (long) ((xpTillNextDefenseLevel / xpPerHour) * 3600000);
- }
- if (skillDisplay == 3){
- g.drawString("" + ft(timeDefenseTNL), 377, 427);
- }
- g.drawString("" + defenseXpGained, 432, 401);
- //hitpoints
- currentHitpointsXp = skills.getExperience(Skill.HITPOINTS);
- hitpointsXpGained = currentHitpointsXp - beginningHitpoints;
- g.drawString("" + hitpointsXpGained, 439, 458);
- int totalxp = attackXpGained + strengthXpGained + hitpointsXpGained + defenseXpGained;
- g.drawString("" + totalxp, 249, 401);
- totalXPGained = totalxp;
- }
- 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)
- {
- if (minutes < 10 && seconds < 10){
- res = (hours + ":0" + minutes + ":0" + seconds);
- }
- if (minutes < 10 && seconds >= 10){
- res = (hours + ":0" + minutes + ":" + seconds);
- }
- if (minutes >= 10 && seconds < 10){
- res = (hours + ":" + minutes + ":0" + seconds);
- }
- if (minutes >= 10 && seconds >= 10){
- res = (hours + ":" + minutes + ":" + seconds);
- }
- }
- if (days > 0)
- {
- if (minutes < 10 && seconds < 10){
- res = (days + ":" + hours + ":0" + minutes + ":0" + seconds);
- }
- if (minutes < 10 && seconds >= 10){
- res = (days + ":" + hours + ":0" + minutes + ":" + seconds);
- }
- if (minutes >= 10 && seconds < 10){
- res = (days + ":" + hours + ":" + minutes + ":0" + seconds);
- }
- if (minutes >= 10 && seconds >= 10){
- res = (days + ":" + hours + ":" + minutes + ":" + seconds);
- }
- }
- return res;
- }
- class AFKerItems extends JFrame {
- public AFKerItems() {
- initComponents();
- }
- private void thisWindowClosed(WindowEvent e) {
- temp = itemsToPickUp.getText().split("\n");
- }
- private void initComponents() {
- label1 = new JLabel();
- scrollPane1 = new JScrollPane();
- itemsToPickUp = new JTextPane();
- textPane2 = new JTextPane();
- textPane3 = new JTextPane();
- //======== this ========
- setResizable(false);
- setBackground(Color.white);
- addWindowListener(new WindowAdapter() {
- @Override
- public void windowClosed(WindowEvent e) {
- thisWindowClosed(e);
- }
- });
- Container contentPane = getContentPane();
- contentPane.setLayout(null);
- //---- label1 ----
- label1.setText("What would you like to pick up?");
- label1.setFont(new Font("Source Sans Pro Black", Font.BOLD, 16));
- contentPane.add(label1);
- label1.setBounds(new Rectangle(new Point(25, 20), label1.getPreferredSize()));
- //======== scrollPane1 ========
- {
- scrollPane1.setViewportView(itemsToPickUp);
- }
- contentPane.add(scrollPane1);
- scrollPane1.setBounds(25, 60, 215, 105);
- //---- textPane2 ----
- textPane2.setText("Put items in here followed by an indent.\nThe items MUST BE CASE SENSITIVE.\n\nExample:\nLobster\nBones\nFire rune\nCoins");
- textPane2.setEditable(false);
- textPane2.setBackground(UIManager.getColor("ColorChooser.background"));
- contentPane.add(textPane2);
- textPane2.setBounds(250, 60, 225, 115);
- //---- textPane3 ----
- textPane3.setText("Press start on other window when ready to begin bot.");
- textPane3.setEditable(false);
- textPane3.setBackground(UIManager.getColor("ColorChooser.background"));
- textPane3.setFont(new Font("Tahoma", Font.BOLD, 18));
- contentPane.add(textPane3);
- textPane3.setBounds(125, 225, 295, 85);
- contentPane.setPreferredSize(new Dimension(515, 360));
- pack();
- setLocationRelativeTo(getOwner());
- }
- private JLabel label1;
- private JScrollPane scrollPane1;
- private JTextPane itemsToPickUp;
- private JTextPane textPane2;
- private JTextPane textPane3;
- }
- class botGUI extends JFrame {
- public botGUI() {
- initComponents();
- }
- private void startButtonActionPerformed(ActionEvent e) {
- foodToEat = whatToEat.getText().toString();
- if (whatToAttack.getText().equalsIgnoreCase("Attack")){
- skillDisplay = 1;
- }
- if (whatToAttack.getText().equalsIgnoreCase("Strength")){
- skillDisplay = 2;
- }
- if (whatToAttack.getText().equalsIgnoreCase("Defence")){
- skillDisplay = 3;
- }
- g2.dispose();
- g.dispose();
- test = false;
- }
- private void initComponents() {
- startButton = new JButton();
- label1 = new JLabel();
- whatToEat = new JTextField();
- label2 = new JLabel();
- whatToAttack = new JTextField();
- //======== this ========
- setAlwaysOnTop(true);
- setResizable(false);
- setTitle("Computor's AFKer");
- Container contentPane = getContentPane();
- contentPane.setLayout(null);
- //---- startButton ----
- startButton.setText("Start");
- startButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- startButtonActionPerformed(e);
- }
- });
- contentPane.add(startButton);
- startButton.setBounds(87, 175, 210, 65);
- //---- label1 ----
- label1.setText("What are you going to train? (Attack, Strength, Defence)");
- contentPane.add(label1);
- label1.setBounds(new Rectangle(new Point(35, 40), label1.getPreferredSize()));
- contentPane.add(whatToEat);
- whatToEat.setBounds(35, 120, 130, whatToEat.getPreferredSize().height);
- //---- label2 ----
- label2.setText("Enter any food name here:");
- contentPane.add(label2);
- label2.setBounds(new Rectangle(new Point(35, 100), label2.getPreferredSize()));
- contentPane.add(whatToAttack);
- whatToAttack.setBounds(35, 60, 140, 20);
- contentPane.setPreferredSize(new Dimension(400, 300));
- pack();
- setLocationRelativeTo(getOwner());
- }
- private JButton startButton;
- private JLabel label1;
- private JTextField whatToEat;
- private JLabel label2;
- private JTextField whatToAttack;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment