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
  • Try asking for help in the chatbox
  • onPaint() help


    HTM
     Share

    Recommended Posts

    Long story short im working on a bot that contains multiple scripts. Because of this i am making paint for each bot, in this case fishing. im currently ironing everything out, that includes the paint. since there will be different paint for 7 different skills i have decided to make a method for the g.drawstrings for each paint. my problem occurs when the paint isnt being drawn. the variable turns true but it isnt recognized and paint. any help would be appreciated

    ______________________this snippet is from my main class______________________
    
    
    @Override
        public void onPaint(Graphics g) {
                if (GuiHelper.getisFishing()) {
                    FishingHelper.FishingPaint();
                }
            }
    
    
    ____________________this is the method i am calling on for the paint________________________________________
    
    
        public static void FishingPaint() {
            if (context.image != null) {
                g.drawImage(context.image, 0, 340, null); }
            { if (!context.hide) {
                g.drawImage(context.closeIcon, 500, 350, null); }
                if (context.hide) { g.drawImage(context.closeIcon, 500, 350, null); }}
            if (!context.hide) {
                g.drawImage(context.background, 20, 340, null);
                g.setColor(Color.white);
                g.drawImage(context.closeIcon, 500, 350, null);
                g.drawString("" + context.getSkillTracker().getGainedExperiencePerHour(Skill.FISHING), 385, 445);
                g.drawString("" + context.getSkillTracker().getGainedExperience(Skill.FISHING), 462, 432);
                g.drawString("" + formatTime(context.getSkillTracker().getTimeToLevel(Skill.FISHING)), 340, 393);
                g.drawString("" + GuiHelper.timeRan.formatTime(), 350, 465);
                g.drawString(BotState.getStartLevel() + " / " + BotState.getCurrentLevel() + " ( +" + BotState.getLevelsGained() + " )", 438, 390);
                g.drawString("" + (BotState.getCounter()), 409, 415); }
            if (context.hide) { g.drawImage(context.closeIcon, 500, 350, null); }
    
        }
    
    _________________________below is the action that sets the variable true when called on_____________________________________
    
    
       public static boolean isFishing = false;
    
    
    
    
                isFishing = fishingCheckBox.isSelected();
                if (fishingCheckBox.isSelected()) {
                    GuiHelper.setisFishing(true);
                    log("fishing set true");
                    GuiHelper.createFishingGUI(client, context);
                }
    
    
    
    
    
    
    
    
    
    
    
    

     

    Link to comment
    Share on other sites

    12 hours ago, hoke2012 said:

    Long story short im working on a bot that contains multiple scripts. Because of this i am making paint for each bot, in this case fishing. im currently ironing everything out, that includes the paint. since there will be different paint for 7 different skills i have decided to make a method for the g.drawstrings for each paint. my problem occurs when the paint isnt being drawn. the variable turns true but it isnt recognized and paint. any help would be appreciated

    ______________________this snippet is from my main class______________________
    
    
    @Override
        public void onPaint(Graphics g) {
                if (GuiHelper.getisFishing()) {
                    FishingHelper.FishingPaint();
                }
            }
    
    
    ____________________this is the method i am calling on for the paint________________________________________
    
    
        public static void FishingPaint() {
            if (context.image != null) {
                g.drawImage(context.image, 0, 340, null); }
            { if (!context.hide) {
                g.drawImage(context.closeIcon, 500, 350, null); }
                if (context.hide) { g.drawImage(context.closeIcon, 500, 350, null); }}
            if (!context.hide) {
                g.drawImage(context.background, 20, 340, null);
                g.setColor(Color.white);
                g.drawImage(context.closeIcon, 500, 350, null);
                g.drawString("" + context.getSkillTracker().getGainedExperiencePerHour(Skill.FISHING), 385, 445);
                g.drawString("" + context.getSkillTracker().getGainedExperience(Skill.FISHING), 462, 432);
                g.drawString("" + formatTime(context.getSkillTracker().getTimeToLevel(Skill.FISHING)), 340, 393);
                g.drawString("" + GuiHelper.timeRan.formatTime(), 350, 465);
                g.drawString(BotState.getStartLevel() + " / " + BotState.getCurrentLevel() + " ( +" + BotState.getLevelsGained() + " )", 438, 390);
                g.drawString("" + (BotState.getCounter()), 409, 415); }
            if (context.hide) { g.drawImage(context.closeIcon, 500, 350, null); }
    
        }
    
    _________________________below is the action that sets the variable true when called on_____________________________________
    
    
       public static boolean isFishing = false;
    
    
    
    
                isFishing = fishingCheckBox.isSelected();
                if (fishingCheckBox.isSelected()) {
                    GuiHelper.setisFishing(true);
                    log("fishing set true");
                    GuiHelper.createFishingGUI(client, context);
                }
    
    
    
    
    
    
    
    
    
    
    
    

     

    Where even are you getting "g" in FishingPaint?

    Link to comment
    Share on other sites

    2 hours ago, hoke2012 said:

    it's delcared at the top of the FishingHelper class. 

     

    private static Graphics g;
    

    Firstly you shouldn't be doing it that way. You should be passing the g from onPaint through the method FishingPaint
    Also, even if your implementation is like that, you are not even setting that global static g to anything on your OnPaint
    Please learn java before writing scripts, it will make it much easier for you

    Link to comment
    Share on other sites

    how is this suppose to work? so it should display the paint of hte script its running pretty much right? and the other script paint's should disappear if not active

    Link to comment
    Share on other sites

    6 hours ago, Neffarion said:

    Firstly you shouldn't be doing it that way. You should be passing the g from onPaint through the method FishingPaint
    Also, even if your implementation is like that, you are not even setting that global static g to anything on your OnPaint
    Please learn java before writing scripts, it will make it much easier for you

    Thanks for your input but i already figured it out by passing it through the method. Originally i couldnt pass it through the method like youre saying because it interferred with one of my other classes. just so you know, my script works and has worked, the difference is i am writing java like it should be written by partioning into different classes and not just writing it in script from top to bottom.  Global static g isnt even needed. Again thanks for your input although it wasnt useful. Again, script is working so obviously i know enough java to write a bot

    Link to comment
    Share on other sites

    On 7/10/2020 at 2:27 AM, hoke2012 said:

    Thanks for your input but i already figured it out by passing it through the method. Originally i couldnt pass it through the method like youre saying because it interferred with one of my other classes. just so you know, my script works and has worked, the difference is i am writing java like it should be written by partioning into different classes and not just writing it in script from top to bottom.  Global static g isnt even needed. Again thanks for your input although it wasnt useful. Again, script is working so obviously i know enough java to write a bot

    can you explain how you got different paints to work? 

    did u have different paint snippets in different task nodes or something

    Link to comment
    Share on other sites

    • 3 weeks later...
    On 7/13/2020 at 1:22 PM, kamilo said:

    can you explain how you got different paints to work? 

    did u have different paint snippets in different task nodes or something

     

    sorry for the late response, i've been busy travelling for work and the had a family vacation. 

     

    i have multiple classes simply put. to explain:

    in my main "onStart" i reference a class called GuiHelper:

    public void onStart() {
        List<Skill> selection = GuiHelper.SkillSelector(getClient().getInstance().getCanvas(), this);

    this starts my gui which i have labelled "SkillSelector()"

    depending which box is check in skill selector it will trigger the gui for the specific skill. i did run into the problem of selecting multiple skills and launching multiple gui's but this is cancelled by a return.

    button.addActionListener(e -> {
    
        isFishing = fishingCheckBox.isSelected();
        if (fishingCheckBox.isSelected()) {
            setisFishing(true);
            log("fishing set true");
            GuiHelper.createFishingGUI(client, context);
    
        }

     

    now the script will reference back to these options in main under my paint. so my main onPaint is something like:

     

    @Override
    public void onPaint(Graphics g) {
        super.onPaint(g);
        log("painting1");
        if (GuiHelper.getisFishing()) {
            fishingHelper.FishingPaint(g);
    
        }
    

    i have an if statement for all possible selections made under GuiHelper and if it is true it will start the paint for that. in this instance if "getisFishing" is true then FishingPaint below will start. the problem i encountered was starting multiple paints at once by selecting multiple check boxes in the guihelper. i cancelled this with a simple return statement which will stop the script:

     

    public static void FishingPaint(Graphics g) {
        if (image != null) {
            g.drawImage(image, 0, 340, null);
        }
        {
            if (!Main.hide) {
                g.drawImage(background, 20, 340, null);
                g.drawImage(closeIcon, 500, 350, null);
                g.setColor(Color.white);
                g.drawString("" + BotState.getXpPerHour(), 385, 445);
                g.drawString("" + BotState.getXpGained(FISHING), 462, 432);
                g.drawString("" + formatTime(BotState.getTimeToNext(FISHING)), 340, 393);
                g.drawString("" + GuiHelper.timeRan.formatTime(), 350, 465);
                g.drawString(BotState.getStartLevel() + " / " + BotState.getCurrentLevel() + " ( +" + BotState.getLevelsGained() + " )", 438, 390);
                g.drawString("" + (BotState.getCounter()), 409, 415);
            }
            if (Main.hide) {
                g.drawImage(closeIcon, 500, 350, null);
            }
        }
    }

     

     

     

     

    Link to comment
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
     Share

    ×
    ×
    • 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.