Jump to content

AIO Paint - Dynamic & Self-Optimizing - Use in any script


DylanSRT

Recommended Posts

I got tired of creating paints for every bot so I decided to created an AIO paint script with the goal of minimizing input needed to customize a paint for a certain script. I also wanted it to be noob-proof and easy to implement into any script. I know I could have used something like this when I first started making scripts. If you use this template in a SDN script, I would appreciate it if you left my signature in the paint. I spent a lot of time creating this topic when I could have easily kept it to myself.

Features:

  • Automatically detects exp gain in any skill and adds it to paint (if using a script which does not gain XP, it will automatically hide this window)
  • Displays current lvl, starting lvl, XP gained, XP per hour, % to next level, time to next level, and has a progress bar to next level
  • Automatically self-optimizes window sizes to fit required text based on only two inputs - font size & text padding
  • Displays script name, time ran, current world, and number of current players on map by default
  • Has easy input for custom counters and automatically adds them into paint
  • Hide button to hide paint & Reset button to reset the XP counters
  • Displays big warning indicator when other players use certain keywords (bot,reported,etc..)
  • 10+ Optional color and font settings

Demonstration of Paint, Hide, Reset, & Warning Indicator:

 

 

How to implement into any script:

Please follow these directions carefully. Use Spoiler 1 (Script Skeleton) as your guide. This will show where user input is required and where to paste code from other spoilers (indicated by %%%%%%). The default settings of the paint will come out looking like the paint in the video. 

Spoiler 1 (Script Skeleton)

Spoiler

import org.osbot.rs07.api.Chatbox;
import org.osbot.rs07.api.Tabs;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.api.ui.Spells;
import org.osbot.rs07.api.ui.Tab;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import java.awt.*;
import java.awt.event.*;
import java.awt.font.FontRenderContext;
import java.text.DecimalFormat;
import java.util.ArrayList;

@ScriptManifest(name = "PaintDemo", author = "DylanSRT", version = 1.0, info = "Epic Paint", logo = "")

public class PaintDemo extends Script {

    //------------User Settings---------------
   //You can also add this block of code at the end of the script between spoiler 5 and 6
    //------------Essentials---------------
    //Font size & Text Padding will determine the size of paint
    //Look at forum for examples
    final int baseFontSize = 14; //Recommended 12-20
    final int textPadding = 5; //space between text,columns, & rows
    final String title = "DylanSRT Paint Demo"; //add script name here
    final boolean warningEnabled = true; //Warning window pops up on paint if a player says one of the keywords, Make sure public chat is visible
    final String[] warningChatKeywords = {"bot", "botting", "report", "reported", "Botting", "Bot", "Report", "Reported"};

    //--Custom Counters - Read Forum for details
    //Set customInfo=null if you don't want to add anything
        String[] customInfo = {
                "State: " + state,
                "Logs Chopped: " + logsChopped,
                "Fires Made: " + firesMade,
                "Alchs cast: " + alchsCast
        };

    //------------Cosmetics---------------
    final float paintTransparency = 0.60F; // 0.00F is transparent, 1.00F is opaque
    final Color textColor = new Color(255, 255, 255);
    final Color paintOutlineColor = new Color(0, 0, 0);
    final Color paintFillColor = new Color(0, 0, 0);
    final Color captionColor = new Color(139, 0, 0);
    final Color dividerColor = new Color(169, 169, 169);
    final Color progressBarFillColor = new Color(139, 0, 0);
    final Color progressBarOutlineColor = new Color(139, 0, 0);
    final Color warningColor = new Color(139, 0, 0);
    final String fontStyle = "SansSerif";
    private final Font baseFont = new Font(fontStyle, Font.PLAIN, baseFontSize);
    private final Font boldFont = new Font(fontStyle, Font.BOLD, baseFontSize);
    private final Font warningFont = new Font(fontStyle, Font.BOLD, 40);

    @Override
    public void onStart() {
    //%%%%%%%%%%% Paste contents of Spoiler 2(OnStart) here
    }

   @Override
    public void onPaint(Graphics2D g) {
	//%%%%%%%%%%% Paste contents of Spoiler 3(OnPaint) here
    }

    @Override
    public int onLoop() throws InterruptedException {
     //%%%%%%%%%%% Paste contents of Spoiler 4(OnLoop) here
        return random(500, 1000);
    }

    //%%%%%%%%%%% Paste contents of Spoiler 5(Used methods) here
	
	//%%%%%%%%%%% Paste contents of Spoiler 6(Additional Variables) here

}

 

Spoiler 2 (onStart)

Spoiler

        for (int i = 0; i < allSkills.length; i++) {
            startingLevelsAll[i] = getSkills().getStatic(allSkills[i]);
            startingExpAll[i] = getSkills().getExperience(allSkills[i]);
        }
        startTime = System.currentTimeMillis();

 

Spoiler 3 (onPaint)

Spoiler

    	//Check for warning keywords in chat
        if (warningEnabled && checkChat(warningChatKeywords)) {
            showWarning = true;
        }

        // Timer Variables
        millis = (System.currentTimeMillis() - startTime);
        hours = (millis / 3600000L);
        millis -= hours * 3600000L;
        minutes = (millis / 60000L);
        millis -= minutes * 60000L;
        seconds = (millis / 1000L);

        ArrayList<Skill> paintSkills = new ArrayList<Skill>();
        ArrayList<Double> startingExp = new ArrayList<Double>();
        ArrayList<Integer> startingLvl = new ArrayList<Integer>();

        Graphics2D g2 = (Graphics2D) g;

        FontMetrics fmb = g2.getFontMetrics(baseFont);
        FontMetrics fmBold = g2.getFontMetrics(boldFont);
        FontMetrics fmWarning = g2.getFontMetrics(warningFont);
        FontRenderContext context = g2.getFontRenderContext();

        //Title Paint Dimensions
        titleRowHeight = fmb.getHeight() + textPadding;
        if (customInfo != null)
            titlePaintHeight = titleRowHeight * (5 + customInfo.length) + textPadding;
        else
            titlePaintHeight = titleRowHeight * 5 + textPadding;
        titlePaintX = 10 + skillsRowLength;
        titlePaintY = 480 - titlePaintHeight;
        Rectangle titlePaintRect = new Rectangle(titlePaintX, titlePaintY, titlePaintLength + 2 * textPadding, titlePaintHeight);

        //Rectangles for buttons & warning screen
        hideBtn = new Rectangle(titlePaintX + textPadding, titlePaintY + titlePaintHeight - titleRowHeight, lengthHide + 4, titleRowHeight - textPadding);
        resetBtn = new Rectangle(titlePaintX + 4 * textPadding + lengthHide, titlePaintY + titlePaintHeight - titleRowHeight, lengthReset + 4, titleRowHeight - textPadding);
        Rectangle warningRect = new Rectangle(0, 0, 520, 340);

        //Display only "Show" button if paint is hidden
        if (hidePaint) {
            g2.setColor(paintFillColor);
            g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, paintTransparency));
            g2.fill(hideBtn);
            g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
                    1.00f));
            g2.setColor(paintOutlineColor);
            g2.setStroke(new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
            g2.draw(hideBtn);
            g2.setFont(boldFont);
            g2.setColor(dividerColor);
            g2.drawString(sshow, getCenterX(titlePaintX + textPadding, lengthHide + 4, sshow, fmBold),
                    getCenterY(titlePaintY + titlePaintHeight - titleRowHeight, titleRowHeight - textPadding, fmBold));
            if (boldFont.getStringBounds(sshow, context).getWidth() > lengthHide)
                lengthHide = (int) boldFont.getStringBounds(sshow, context).getWidth();
        } else {

            //Title Paint Fill & Draw
            g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, paintTransparency));
            if (showWarning) {
                g2.setColor(warningColor);
                g2.fill(warningRect);
            }
            g2.setColor(paintFillColor);
            g2.fill(titlePaintRect);
            g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.00f));
            g2.setStroke(new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
            g2.setColor(paintOutlineColor);
            g2.draw(titlePaintRect);
            if (showWarning) {
                g2.setColor(Color.white);
                g2.setFont(warningFont);
                g2.drawString("Warning: Keyword in Chat", (520 - fmWarning.stringWidth("Warning: Keyword in Chat")) / 2, (fmWarning.getAscent() + (340 - (fmWarning.getAscent() + fmWarning.getDescent())) / 2));
            }

            //Add Hide and Reset Buttons
            g2.setColor(paintOutlineColor);
            g2.draw(hideBtn);
            g2.draw(resetBtn);
            g2.setFont(boldFont);
            g2.setColor(dividerColor);
            g2.drawString(shide, getCenterX(titlePaintX + textPadding, lengthHide + 4, shide, fmBold),
                    getCenterY(titlePaintY + titlePaintHeight - titleRowHeight, titleRowHeight - textPadding, fmBold));
            if (boldFont.getStringBounds(shide, context).getWidth() > lengthHide)
                lengthHide = (int) boldFont.getStringBounds(shide, context).getWidth();
            g2.drawString(reset, getCenterX(titlePaintX + 4 * textPadding + lengthHide, lengthReset + 4, reset, fmBold),
                    getCenterY(titlePaintY + titlePaintHeight - titleRowHeight, titleRowHeight - textPadding, fmBold));
            if (boldFont.getStringBounds(reset, context).getWidth() > lengthReset)
                lengthReset = (int) boldFont.getStringBounds(reset, context).getWidth();

            //Add Title
            g2.setColor(captionColor);
            g2.setFont(boldFont);
            g2.drawString(title, getCenterX(titlePaintX + textPadding, titlePaintLength, title, fmBold), getCenterY(titlePaintY + textPadding, titleRowHeight, fmBold));
            if (boldFont.getStringBounds(title, context).getWidth() + 2 * textPadding > titlePaintLength)
                titlePaintLength = (int) boldFont.getStringBounds(title, context).getWidth() + 2 * textPadding;

            //Add text
            ArrayList<String> textTitlePaint = new ArrayList<String>();
            textTitlePaint.add("Time Ran: " + hours + " hours " + minutes + " minutes " + seconds + " seconds");
            if (customInfo != null) {
                for (int i = 0; i < customInfo.length; i++) {
                    textTitlePaint.add(customInfo[i]);
                }
            }
            textTitlePaint.add("World " + getWorlds().getCurrentWorld() + " | " + (getMap().getPlayers().getAll().size() - 1) + " players on map");

            g2.setColor(textColor);
            g2.setFont(baseFont);
            for (int i = 0; i < textTitlePaint.size(); i++) {
                g2.drawString(textTitlePaint.get(i), getCenterX(titlePaintX + textPadding, titlePaintLength, textTitlePaint.get(i), fmb), getCenterY(titlePaintY + textPadding, titleRowHeight, fmb) + (1 + i) * titleRowHeight);
                if (baseFont.getStringBounds(textTitlePaint.get(i), context).getWidth() > titlePaintLength)
                    titlePaintLength = (int) baseFont.getStringBounds(textTitlePaint.get(i), context).getWidth();
            }
            g2.setColor(captionColor);
            String signature = "Created with DylanSRT Paint Template";
            g2.drawString(signature, getCenterX(titlePaintX + textPadding, titlePaintLength, signature, fmb), getCenterY(titlePaintY + titlePaintHeight - titleRowHeight, titleRowHeight - textPadding, fmBold) - titleRowHeight);

            //Check for an experience gain in any skill
            for (int i = 0; i < allSkills.length; i++) {
                Skill s = allSkills[i];
                if (skills.getExperience(s) != startingExpAll[i]) {
                    paintSkills.add(s);
                    startingLvl.add((int) startingLevelsAll[i]);
                    startingExp.add(startingExpAll[i]);
                }
            }
            l = paintSkills.size();

            //If experience has been gained in any skill, skills paint is initialized
            if (l > 0) {
                //Skills Paint Dimensions
                rowHeight = fmb.getHeight() + 2 * textPadding;
                skillsPaintHeight = (l + 1) * rowHeight;
                skillsPaintX = 10;
                skillsPaintY = 480 - skillsPaintHeight;
                Rectangle skillsPaintRect = new Rectangle(skillsPaintX, skillsPaintY, skillsRowLength, skillsPaintHeight);
                rowY = new int[l];
                skillRectangles = new Rectangle[l];
                progressRectangles = new Rectangle[l];

                //Calculate data for skills paint
                skillsPaintData = new String[l + 1][6];
                String[] skillsPaintCaptions = {"Skill", "LVL", "kXP", "kXP/hr", "%TNL", "TimeTNL"};
                for (int i = 0; i < 6; i++) {
                    skillsPaintData[0][i] = skillsPaintCaptions[i];
                }
                for (int i = 1; i < l + 1; i++) {
                    Skill s = paintSkills.get(i - 1);
                    skillsPaintData[i][0] = s.name();
                    skillsPaintData[i][1] = getSkills().getStatic(s) + "/" + startingLvl.get(i - 1);
                    double xpGained = getSkills().getExperience(s) - startingExp.get(i - 1);
                    DecimalFormat df = new DecimalFormat("###.##");
                    skillsPaintData[i][2] = df.format(xpGained / 1000) + "";
                    double xpPhr = ((int) (xpGained * 3600000.0D / (System.currentTimeMillis() - startTime)));
                    skillsPaintData[i][3] = df.format(xpPhr / 1000) + "";
                    skillsPaintData[i][4] = Double.toString((100 * (experiencePrevLevel(s) / experienceTotalNeeded(s)))).substring(0, 4);
                    skillsPaintData[i][5] = formatTime(timeTnl(experienceToNextLevel(s), xpPhr));
                }
                for (int i = 0; i < l; i++) {
                    Skill s = paintSkills.get(i);
                    rowY[i] = (skillsPaintY + (i + 1) * rowHeight);
                    skillRectangles[i] = new Rectangle(skillsPaintX, rowY[i], skillsRowLength, rowHeight);
                    progressRectangles[i] = (new Rectangle(skillsPaintX, rowY[i] + 2, 0, rowHeight - 4));
                    progressRectangles[i].setSize((int) ((100 * (experiencePrevLevel(s) / experienceTotalNeeded(s))) * skillsRowLength / 100), rowHeight - 4);
                }

                //Add transparent paint background
                g2.setColor(paintFillColor);
                g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, paintTransparency));
                g2.fill(skillsPaintRect);

                //Add progress bars & progress bar outline
                g2.setStroke(new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
                for (int i = 0; i < l; i++) {
                    g2.setColor(progressBarFillColor);
                    g2.fill(progressRectangles[i]);
                    g2.setColor(progressBarOutlineColor);
                    g2.draw(progressRectangles[i]);
                }

                g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
                        1.00f));

                //Add lines to seperate skills
                g2.setColor(paintOutlineColor);
                for (int i = 0; i < l; i++) {
                    g2.drawLine(skillsPaintX, rowY[i], skillsPaintX + skillsRowLength, rowY[i]);
                }

                //Draw thick line around paint
                g2.setStroke(new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
                g2.draw(skillsPaintRect);
                g2.draw(titlePaintRect);

                //Arrays to keep track of string lengths for dynamic window size optimization
                int[] x = {skillsPaintX,
                        skillsPaintX + lengthC1,
                        skillsPaintX + lengthC1 + lengthC2,
                        skillsPaintX + lengthC1 + lengthC2 + lengthC3,
                        skillsPaintX + lengthC1 + lengthC2 + lengthC3 + lengthC4,
                        skillsPaintX + lengthC1 + lengthC2 + lengthC3 + lengthC4 + lengthC5};
                int[] lengths = {lengthC1, lengthC2, lengthC3, lengthC4, lengthC5, lengthC6};
                sd = "|";

                //Add Skill Paint Captions
                g2.setFont(boldFont);
                g2.setColor(captionColor);
                for (int i = 0; i < 6; i++) {
                    g2.drawString(skillsPaintData[0][i], getCenterX(x[i] + i * lengthDivide + (1 + 2 * i) * textPadding, lengths[i], skillsPaintData[0][i], fmBold), getCenterY(skillsPaintY, rowHeight, fmBold));
                    if (boldFont.getStringBounds(skillsPaintData[0][i], context).getWidth() > lengths[i]) {
                        lengths[i] = (int) boldFont.getStringBounds(skillsPaintData[0][i], context).getWidth();

                    }
                }

                //Add dividers
                g2.setColor(dividerColor);
                context = g2.getFontRenderContext();
                for (int i = 0; i < l + 1; i++) {
                    for (int j = 0; j < 5; j++) {
                        g2.drawString(sd, getCenterX(x[j + 1] + j * lengthDivide + (2 + 2 * j) * textPadding, lengthDivide, sd, fmBold), getCenterY(skillsPaintY + rowHeight * i, rowHeight, fmBold));
                        lengthDivide = (int) boldFont.getStringBounds(sd, context).getWidth();
                    }
                }

                //Add data
                g2.setFont(baseFont);
                g2.setColor(textColor);
                for (int i = 1; i < l + 1; i++) {
                    for (int j = 0; j < 6; j++) {
                        g2.drawString(skillsPaintData[i][j], getCenterX(x[j] + j * lengthDivide + (1 + 2 * j) * textPadding, lengths[j], skillsPaintData[i][j], fmb), getCenterY(skillsPaintY + rowHeight * i, rowHeight, fmb));
                        if (baseFont.getStringBounds(skillsPaintData[i][j], context).getWidth() > lengths[j]) {
                            lengths[j] = (int) baseFont.getStringBounds(skillsPaintData[i][j], context).getWidth();
                        }
                    }
                }

                //Update lengths
                lengthC1 = lengths[0];
                lengthC2 = lengths[1];
                lengthC3 = lengths[2];
                lengthC4 = lengths[3];
                lengthC5 = lengths[4];
                lengthC6 = lengths[5];
                skillsRowLength = lengthC1 + lengthC2 + lengthC3 + lengthC4 + lengthC5 + lengthC6 + lengthDivide * 5 + textPadding * 12;
            }

        }

 

Spoiler 4 (onLoop)

Spoiler

//Make sure this is at the very top of your OnLoop
getBot().getCanvas().addMouseListener(listener);

 

Spoiler 5 (Used methods)

Spoiler

MouseListener listener = new MouseListener() {
        @Override
        public void mouseClicked(MouseEvent mouseEvent) {
            p = mouse.getPosition();
            if (hideBtn.contains(p)) {
                hidePaint = !hidePaint;
            } else if (resetBtn.contains(p)) {
                for (int i = 0; i < allSkills.length; i++) {
                    startingLevelsAll[i] = getSkills().getStatic(allSkills[i]);
                    startingExpAll[i] = getSkills().getExperience(allSkills[i]);
                }
                startTime = System.currentTimeMillis();
                skillsRowLength = 0;
            }
        }

        @Override
        public void mousePressed(MouseEvent mouseEvent) {

        }

        @Override
        public void mouseReleased(MouseEvent mouseEvent) {

        }

        @Override
        public void mouseEntered(MouseEvent mouseEvent) {

        }

        @Override
        public void mouseExited(MouseEvent mouseEvent) {

        }
    };
    
    private int getCenterX(int x, int w, String s, FontMetrics f) {
        return x + (w - f.stringWidth(s)) / 2;
    }

    private int getCenterY(int y, int h, FontMetrics f) {
        return y + (f.getAscent() + (h - (f.getAscent() + f.getDescent())) / 2);
    }

    private boolean checkChat(String[] keywords) {
        for (String s : keywords) {
            if (chatbox.contains(Chatbox.MessageType.ALL, s)) {
                return true;
            }
        }
        return false;
    }

    private int experienceToNextLevel(Skill skill) {
        int xp = getSkills().getExperience(skill);
        for (int i = 0; i < 99; i++) {
            if (xp < xpForLevels[i]) {
                return xpForLevels[i] - xp;
            }
        }
        return 200000000 - xp;
    }

    private double experiencePrevLevel(Skill skill) {
        int xp = getSkills().getExperience(skill);
        for (int i = 0; i < 99; i++) {
            if (xp < xpForLevels[i]) {
                return xp - xpForLevels[i - 1];
            }
        }
        return 200000000 - xp;
    }

    private double experienceTotalNeeded(Skill skill) {
        int xp = getSkills().getExperience(skill);
        for (int i = 0; i < 99; i++) {
            if (xp < xpForLevels[i]) {
                return xpForLevels[i] - xpForLevels[i - 1];
            }
        }
        return 200000000 - xp;
    }

    long timeTnl(double xpTNL, double xpPH) {

        if (xpPH > 0) {
            long timeTNL = (long) ((xpTNL / xpPH) * 3600000.0D);
            return timeTNL;
        }
        return 0;
    }

    private String formatTime(long time) {
        int sec = (int) (time / 1000L), d = sec / 86400, h = sec / 3600, m = sec / 60 % 60, s = sec % 60;
        return new StringBuilder()
                .append(h < 10 ? new StringBuilder().append("0").append(h)
                        .toString() : Integer.valueOf(h))
                .append(":")
                .append(m < 10 ? new StringBuilder().append("0").append(m)
                        .toString() : Integer.valueOf(m))
                .append(":")
                .append(s < 10 ? new StringBuilder().append("0").append(s)
                        .toString() : Integer.valueOf(s)).toString();
    }

 

Spoiler 6 (Additional Variables)

Spoiler

int skillsRowLength, titlePaintLength, rowHeight, skillsPaintHeight, titlePaintHeight, skillsPaintX, titlePaintX, skillsPaintY,
            titlePaintY, lengthC1, lengthC2, lengthC3, lengthC4, lengthC5, lengthC6, lengthDivide, lengthHide, lengthReset,
            titleRowHeight,l;
    int[] rowY;
    int[] xpForLevels = {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};

    String state, sd;
    String shide = "Hide";
    String sshow = "Show";
    String reset = "Reset";
    String[][] skillsPaintData;

    double[] startingLevelsAll = new double[23];
    double[] startingExpAll = new double[23];

    public long startTime = 0L, millis = 0L, hours = 0L;
    public long minutes = 0L, seconds = 0L, last = 0L;

    Rectangle hideBtn, resetBtn;
    Rectangle[] skillRectangles, progressRectangles;

    boolean hidePaint = false;
    boolean showWarning = false;

    final Skill[] allSkills = {Skill.ATTACK, Skill.MINING, Skill.SLAYER, Skill.HITPOINTS, Skill.DEFENCE, Skill.MAGIC, Skill.RANGED,
            Skill.STRENGTH, Skill.AGILITY, Skill.CONSTRUCTION, Skill.COOKING, Skill.CRAFTING, Skill.FARMING, Skill.FIREMAKING, Skill.FISHING,
            Skill.FLETCHING, Skill.HERBLORE, Skill.HUNTER, Skill.PRAYER, Skill.RUNECRAFTING, Skill.SMITHING, Skill.THIEVING, Skill.WOODCUTTING};

    Point p;

 

Adding Custom Counters:

In addition to the default features of the paint, I made it very easy to add in custom counters. You can do this using customInfo settings in the Script Skeleton. They will appear underneath the "Time Ran:" timer.

Spoiler

 String[] customInfo = {
                "State: " + state,
                "Logs Chopped: " + logsChopped,
                "Fires Made: " + firesMade,
                "Alchs cast: " + alchsCast
        };

 

Just add the String you want in the caption and the Variable it is referring to into this Array in the same manner as this example. You have to make sure your counter/state variable is properly initialized and updating information in your onLoop. Make sure to set customInfo=null if you don't want to add anything. Don't just delete it.

By default, the counters will not reset when the Reset button is pressed. If you want them to reset, you need to add some code to the MouseEvent in the used methods spoiler. Going along with the example above, this is what you would need to change it to:

Spoiler

   MouseListener listener = new MouseListener() {
        @Override
        public void mouseClicked(MouseEvent mouseEvent) {
            p = mouse.getPosition();
            if (hideBtn.contains(p)) {
                hidePaint = !hidePaint;
            } else if (resetBtn.contains(p)) {
                for (int i = 0; i < allSkills.length; i++) {
                    startingLevelsAll[i] = getSkills().getStatic(allSkills[i]);
                    startingExpAll[i] = getSkills().getExperience(allSkills[i]);
                }
                startTime = System.currentTimeMillis();
                skillsRowLength = 0;
                state="";
                logsChopped=0;
                firesMade=0;
                alchsCast=0;
            }
        }

 

Font Size & Text Padding:

These settings are the only inputs you need to use to control the size of the paint. Below are some pictures of different combinations:

baseFontSize=14 & textPadding=5 (Default)

image.png.8e9cc13042c6b41f3144bdbfff5bf17c.png

baseFontSize=10 & textPadding=1 (the Space Saver)

image.png.c9f36da04531bd83ef316c0fedd2a959.png

baseFontSize=20 & textPadding=10 (the IDGAF) - You can see this option would actually push the paint out of the bot with the skills paint activated, so this would mean that you need to reduce your size. However, this could be a viable option for bots that don't train XP.

image.png.3201a15227c5a59a0c4458b0c4a9671a.png

 

 

 

Edited by DylanSRT
  • Like 3
  • Heart 2
Link to comment
Share on other sites

Looking good - now let's take it up a gear!

Take what you've done here and make it modular. I'll give you some examples:

CustomPaint

Spoiler

public abstract class CustomPaint extends API implements Painter {

	private boolean visible = true;

	public abstract void paint(Graphics2D g);
	
	@Override
	public void initializeModule() {
		bot.addPainter(this);
	}
	
	@Override
	public void onPaint(Graphics2D g) {
		if (visible) {
			paint(g); // this calls that abstract method
		}
	}
	
	public boolean isVisible() {
		return visible;
	}
	
	public void setVisible(boolean visible) {
		this.visible = visible;
	}
}

 

This'll let us hide/show different paints and gives us a basis for our paint modules. Here's an example:

SkillTrackerPaint

Spoiler

public class SkillTrackerPaint extends CustomPaint {

	private Skill[] skills;

	@Override
	public void initializeModule() {
		
		super.initializeModule(); // This calls the thingy in CustomPaint :)
		
		skills = Skill.values();
	}
	
	@Override
	public void paint(Graphics2D g) {
		
		int y = 25;
		
		for (Skill s : skills) {
			
			g.drawString(s.name(), 25, y);
			
			y += 25;
		}
	}
}

 

And...

MousePaint

Spoiler

public class MousePaint extends CustomPaint {

	Point mouseLocation;
	boolean leftClickDown;
	boolean rightClickDown;
	
	@Override
	public void initializeModule() {

		super.initializeModule();
		
		// gonna add mouse listener
		
		bot.addMouseListener(new BotMouseListener() {
			
			@Override
			public void checkMouseEvent(MouseEvent e) {
				switch (e.getID()) {
				
				case MouseEvent.MOUSE_PRESSED:
					
					if (e.getButton() == MouseEvent.BUTTON1) { // left click
						leftClickDown = true;
						
					} else if (e.getButton() == MouseEvent.BUTTON3) { // right click
						rightClickDown = true;
					}
					
					break;
					
				case MouseEvent.MOUSE_RELEASED:
					
					if (e.getButton() == MouseEvent.BUTTON1) { // left click
						leftClickDown = true;
						
					} else if (e.getButton() == MouseEvent.BUTTON3) { // right click
						rightClickDown = true;
					}
					
					break;
				}
			}
			
			@Override
			public void mouseDragged(MouseEvent e) {
				mouseLocation.setLocation(e.getPoint());
			}
			
			@Override
			public void mouseMoved(MouseEvent e) {
				mouseLocation.setLocation(e.getPoint());
			}
			
		});
	}

	@Override
	public void paint(Graphics2D g) {
		
		if (leftClickDown) {
			g.setColor(Color.RED);
		} else if (rightClickDown) {
			g.setColor(Color.GREEN);
		} else {
			g.setColor(Color.BLUE);
		}
		
		g.fillOval(mouseLocation.x - 5, mouseLocation.y - 5, 10, 10);
	}
	
}

 

And best of all, here's how to add it to the script:

public class Test extends Script {

	CustomPaint skillTrackerPaint;
	CustomPaint mousePaint;

	@Override
	public void onStart() throws InterruptedException {
		
		skillTrackerPaint = new SkillTrackerPaint();
		skillTrackerPaint.exchangeContext(bot); // must give botty to painte first!
		skillTrackerPaint.initializeModule();
		
		mousePaint = new MousePaint();
		mousePaint.exchangeContext(bot);
		mousePaint.initializeModule();
	}
	
	@Override
	public int onLoop() throws InterruptedException {
		
		if (ehh for whatever reason we want) {
			
			skillTrackerPaint.setVisible(false);
		}
		
		return 0;
	}

}

Doing this means you can split up your paint code, add fine-tuned functionality (such as draggable paints, or even your own paint GUI windows!) This'll help keep the script code and paint code clean. :)

 

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Hey @liverare,

Thanks for the advice. I actually do have it in a separate class for my own but like I said I wanted to make it super-noob proof in this post since many people start off with just the basic script skeleton. I'm glad your post is up now so they can learn how to use separate classes.

Btw your two GUI tutorials basically taught me how to make GUIs so I'm a big fan ! 

 

 

Link to comment
Share on other sites

  • 11 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...