Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Universal Paint


    Calculus

    Recommended Posts

    Snippet for scripters to use. It's extremely straight forward, and an example is included. Please, feel free to leave critiques/suggestions (except for Mad, I don't give a shit what you think).

     

    Features:

    • Auto-starts skill trackers as soon as player is logged in
    • Displays up to 9 skills at a time
    • Displays all skills which XP has been gained in since starting the script

     

    Video preview:

    https://www.dropbox.com/s/54veohlaobvn099/2016-08-04_15-09-38.mp4?dl=0

     

    Code:

     

     

    package Paint;
    
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;
    
    import java.awt.*;
    
    /**
     * Created by Calculus on 8/3/2016.
     */
    @ScriptManifest(category = Category.MISC, name = "Paint test", author = "Calculus", version = 1)
    public class PaintTest extends AbstractScript {
        @Override
        public int onLoop() {
            return 500;
        }
    
        @Override
        public void onPaint(Graphics g) {
            UniversalPaint.repaint(g, this);
        }
    }
    
    package Paint;
    
    import org.dreambot.api.methods.MethodContext;
    import org.dreambot.api.methods.skills.Skill;
    import org.dreambot.api.utilities.Timer;
    
    import java.awt.*;
    import java.text.DecimalFormat;
    import java.util.*;
    import java.util.List;
    
    import static org.dreambot.api.methods.MethodProvider.log;
    
    /**
     * Created by Calculus on 8/3/2016.
     */
    public class UniversalPaint {
        private final static int ALPHA = 160, X = 7, Y = 344, WIDTH = 489, HEIGHT = 15;
        private static final String[] suffix = new String[]{"", "k", "m", "b", "t"};
        private static boolean hasUpdated, startedThread;
    
        public static void repaint(Graphics g2, MethodContext ctx){
            if(hasUpdated) {
                Graphics2D g = (Graphics2D) g2;
                g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    
                List<UniversalPaint.PaintSkill> paintSkillList = new ArrayList<>();
    
                for (int i = 0; i < PaintSkill.values().length; i++) {
                    if (ctx.getSkillTracker().getGainedExperience(PaintSkill.values()[i].getSkill()) > 0)
                        paintSkillList.add(PaintSkill.values()[i]);
                }
    
                if (!paintSkillList.isEmpty()) {
                    int size = paintSkillList.size() > 9 ? 9 : paintSkillList.size();
                    for (int i = 0; i < size; i++) {
                        PaintSkill skill = paintSkillList.get(i);
    
                        g.setFont(new Font("Arial", Font.PLAIN, 12));
    
                        g.setColor(skill.getBackground());
                        g.fillRoundRect(X, (Y + (i * HEIGHT) + 1), WIDTH, HEIGHT, 5, 5);
    
                        g.setColor(skill.getForeground());
                        g.fillRoundRect(X, (Y + (i * HEIGHT) + 1), getBarFillPercent(WIDTH, ctx, skill.getSkill()), HEIGHT, 5, 5);
    
                        String text = skill.getSkill().getName() + ": ";
                        text += ctx.getSkills().getRealLevel(skill.getSkill()) + "/" + ctx.getSkillTracker().getStartLevel(skill.getSkill());
                        text += "  |  XP Gained: " + format(ctx.getSkillTracker().getGainedExperience(skill.getSkill()));
                        text += "  |  XP /hr: " + format(ctx.getSkillTracker().getGainedExperiencePerHour(skill.getSkill()));
                        text += "  |  XPTL: " + format(ctx.getSkills().getExperienceToLevel(skill.getSkill()));
                        text += "  |  TTL: " + Timer.formatTime(ctx.getSkillTracker().getTimeToLevel(skill.getSkill()));
    
                        g.setColor((skill.equals(PaintSkill.PRAYER) || skill.equals(PaintSkill.RUNECRAFTING)) ? Color.black : Color.white);
                        g.drawString(text, X + 6, (13 + Y + (i * HEIGHT)));
                    }
                }
    
                g.dispose();
            }else if(!startedThread){
                new Thread(()->startSkillTrackers(ctx)).start();
                startedThread = true;
            }
        }
    
        private static int getBarFillPercent(int barWidth, MethodContext ctx, Skill skill){
            double xpTL = ctx.getSkills().getExperienceForLevel(ctx.getSkills().getRealLevel(skill));
            double xpTL1 = ctx.getSkills().getExperienceForLevel(ctx.getSkills().getRealLevel(skill) + 1);
            double percentTNL = ((ctx.getSkills().getExperience(skill) - xpTL) / (xpTL1 - xpTL) * 100);
            return (int) ((barWidth / 100D) * percentTNL);
        }
    
        private static String format(double number) {
            String r = new DecimalFormat("##0E0").format(number);
            r = r.replaceAll("E[0-9]", suffix[Character.getNumericValue(r.charAt(r.length() - 1)) / 3]);
            while(r.length() > 4 || r.matches("[0-9]+\\.[a-z]")){
                r = r.substring(0, r.length()-2) + r.substring(r.length() - 1);
            }
            return r;
        }
    
        private static void startSkillTrackers(MethodContext ctx){
            while (!ctx.getClient().isLoggedIn() && ctx.getClient().getInstance().getScriptManager().isRunning())
                try { Thread.sleep(2000); } catch (InterruptedException e) {e.printStackTrace();}
    
            for(Skill s : Skill.values()) //Start all of the skill trackers
                ctx.getSkillTracker().start(s);
    
            hasUpdated = true;
            log("Started skill trackers!"); //Notify
        }
    
        private enum PaintSkill {
            ATTACK(      new Color(80, 17, 8, ALPHA)),
            DEFENCE(     new Color(111, 131, 196, ALPHA)),
            STRENGTH(    new Color(13, 112, 65, ALPHA)),
            HITPOINTS(   new Color(206, 58, 71, ALPHA)),
            RANGED(      new Color(85, 111, 13, ALPHA)),
            PRAYER(      new Color(224, 220, 220, ALPHA)),
            MAGIC(       new Color(162, 150, 129, ALPHA)),
            COOKING(     new Color(61, 12, 77, ALPHA)),
            WOODCUTTING( new Color(145, 115, 53, ALPHA)),
            FLETCHING(   new Color(0, 36, 37, ALPHA)),
            FISHING(     new Color(96, 128, 161, ALPHA)),
            FIREMAKING(  new Color(202, 86, 12, ALPHA)),
            CRAFTING(    new Color(125, 90, 56, ALPHA)),
            SMITHING(    new Color(52, 52, 31, ALPHA)),
            MINING(      new Color(56, 97,100, ALPHA)),
            HERBLORE(    new Color(3, 69, 5, ALPHA)),
            AGILITY(     new Color(23, 25, 96, ALPHA)),
            THIEVING(    new Color(82, 29, 62, ALPHA)),
            SLAYER(      new Color(22, 20, 20, ALPHA)),
            FARMING(     new Color(3, 56, 3, ALPHA)),
            RUNECRAFTING(new Color(181, 181, 169, ALPHA)),
            HUNTER(      new Color(99, 91, 56, ALPHA)),
            CONSTRUCTION(new Color(155, 143, 123, ALPHA));
    
            private final Color foreground;
            private final Color background;
            PaintSkill(Color background){
                this.background = background;
                this.foreground = new Color(background.getRed(), background.getGreen(), background.getBlue()).brighter();
            }
    
            public Color getForeground() {
                return foreground;
            }
    
            public Color getBackground() {
                return background;
            }
    
            public Skill getSkill(){
                return Skill.values()[ordinal()];
            }
        }
    }
     

     

     

    Link to comment
    Share on other sites

    private static final String[] suffix = new String[]{"", "k", "m", "b", "t"};
    
    Change to
    
    private static final String[] suffix = {"", "k", "m", "b", "t"};
    

    also u called ctx.getSkills() and ctx.getSkillTracker like 800 times, pls save it to a variable to reduce bloat

    Link to comment
    Share on other sites

    private static final String[] suffix = new String[]{"", "k", "m", "b", "t"};
    
    Change to
    
    private static final String[] suffix = {"", "k", "m", "b", "t"};
    

    also u called ctx.getSkills() and ctx.getSkillTracker like 800 times, pls save it to a variable to reduce bloat

     

    Wrong.

    Link to comment
    Share on other sites

           List<UniversalPaint.PaintSkill> paintSkillList = new ArrayList<>();
    
                for (int i = 0; i < PaintSkill.values().length; i++) {
                    if (ctx.getSkillTracker().getGainedExperience(PaintSkill.values()[i].getSkill()) > 0)
                        paintSkillList.add(PaintSkill.values()[i]);
                }
    
    

    Why did you need the index for this scenario?

     

    Should use a for-each loop or a stream and collect it 2 a list

    Link to comment
    Share on other sites

           List<UniversalPaint.PaintSkill> paintSkillList = new ArrayList<>();
    
                for (int i = 0; i < PaintSkill.values().length; i++) {
                    if (ctx.getSkillTracker().getGainedExperience(PaintSkill.values()[i].getSkill()) > 0)
                        paintSkillList.add(PaintSkill.values()[i]);
                }
    
    

    Why did you need the index for this scenario?

     

    Should use a for-each loop or a stream and collect it 2 a list

     

    Wut

    Link to comment
    Share on other sites

    Wut

    ?

    List<SupDude> list = Arrays.stream(PaintSkill.values())
        .filter(v -> ctx.getSkillTracker().getGainedExperience(v.getSkill()) > 0)
        .collect(Collectors.toList())
    
    
    Link to comment
    Share on other sites

     

    ?

    List<SupDude> list = Arrays.stream(PaintSkill.values())
        .filter(v -> ctx.getSkillTracker().getGainedExperience(v.getSkill()) > 0)
        .collect(Collectors.toList())
    
    

    literally changes nothing...

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.