Jump to content
Sign in to follow this  
MoonMan

Script not functioning properly

Recommended Posts

hey, so I'm having a fair few issues with a script I'm trying to make here. Basically the script is supposed to make pizzas once the player reaches a certain cooking level. Here are my problems.
1. The IDE I am using, IntelliJ, is telling me that the Class 'Main' is never used, in spite of there being no other class.
2. The script its self is not showing up in my OSBot Client. I have built it to a JAR file and ported it over via USB to my PC with OSBot on it and it isn't showing, even when in the script folder.

This is what I have done so far:
- Checked the IDE is building properly, Artifacts are set to compile to output root, I have triple checked everything is in order.
- Removing certain parts of the script that were never used, no change.

I have posted in the Discord but wanted to put something out here to reach more people and hopefully be able to help others if they get this issue. Cheers

 

import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.api.map.*;
import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.utility.ConditionalSleep;




@ScriptManifest(name = "Pizza bot", author = "", version = 1.0, info = "", logo = "")

public class Main extends Script {

    Position edgeBank = new Position(3096, 3494, 0);
    Position edgeRang = new Position(3078, 3495, 0);

    @Override

    public int onLoop() throws InterruptedException {

        if(!isCookingLevel()){
            if(haveAnchovy())
                cookAnchovy();
            else
                fetchIngredients("Raw anchovies", 28);
        }//end if
        else{
            getWalking().webWalk(edgeBank);
            putTomato();
            putCheese();
            putAnchovies();
            cookUncooked();
        }
        return(100);
    }

    private boolean haveAnchovy(){
        if(getInventory().onlyContains("Raw anchovies"))
            return(true);
        else
            return(false);
    }//end haveAnchovy

    private void cookAnchovy() throws InterruptedException {
        getWalking().webWalk(edgeRang);
        objects.closest("Cooking range").interact("Cook");
        sleep(2000);
        widgets.interact(270, 14, "Cook");
    }

    private boolean isCookingLevel(){//returns true if the required cooking level is met
        if((getSkills().getDynamic(Skill.COOKING)) == 35)
            return(true);
        else
            return(false);
    }//end isCookingLevel

    private void fetchIngredients(String item, int amt) throws InterruptedException {
        getWalking().webWalk(edgeBank);
        getBank().open();
        getBank().withdraw(item, amt);
        sleep(500);
        getBank().close();
    }

    private void putTomato() throws InterruptedException {
            fetchIngredients("Pizza base", 14);
            fetchIngredients("Tomato", 14);
            if (getInventory().getItem("Pizza base").interact("Use", "Pizza base")) //select "use" for pizza base
                if (getInventory().getItem("Tomato").interact("Use", "Tomato"))//select "use" for tomato
                    sleep(1000);//chill for 1000
            makeAll();//call the makeAll method. SEE LINE 23
    }

    private void putCheese() throws InterruptedException{
        fetchIngredients("Cheese", 14);
        if (getInventory().getItem("Incomplete pizza").interact("Use", "Incomplete pizza"))//use pizza
            if (getInventory().getItem("Cheese").interact("Use", "Cheese"))//use cheese
                sleep(800);//chill
        makeAll();//call makeAll
    }

    private void putAnchovies() throws InterruptedException{
        fetchIngredients("Cooked anchovy", 14);
        if (getInventory().getItem("Plain pizza").interact("Use", "Plain pizza"))//use pizza
            if (getInventory().getItem("Anchovies").interact("Use", "Anchovies"))//use anchovy
                sleep(800);//chill
        makeAll();//call makeAll
    }

    public void makeAll() throws InterruptedException {
        RS2Widget PizzaWidget;
        PizzaWidget = getWidgets().get(309, 6);
        if (PizzaWidget != null && PizzaWidget.isVisible())
            if (PizzaWidget.interact("Make all"))
                sleep(18000);
    }

    public void cookAll() throws InterruptedException {//just cooks all
        RS2Widget Uncooked = widgets.get(307, 4);//declare widget called Uncooked
        if (Uncooked != null && Uncooked.isVisible()) //do if Uncooked is not null and is visible
            sleep(500); //chill for 500
        Uncooked.interact("Cook All"); //use the uncooked to do the "cook all" interaction
        new ConditionalSleep(1000000) { //chill for a long time
            @ Override //override the condition method
            public boolean condition() throws InterruptedException {
                return  !getInventory().contains("Uncooked pizza"); 
            }
        }.sleep();
    }

    public void cookUncooked () throws InterruptedException {//cooks uncooked pizza on a range
        sleep(300); {
            fetchIngredients("Uncooked pizza", 28);//fetch 28 uncooked pizzas
            getWalking().webWalk(edgeRang);//walk to the edgeville range
            RS2Widget UnpizzaWidget = widgets.get(307, 4);//make a widget object
            RS2Object Range = objects.closest("Range");{ //grab the closest range
                if (Range.isVisible());//if you see the range
                if (getInventory().getItem("Uncooked pizza").interact("Use", "Uncooked pizza"))//use pizza
                    if 	(Range.interact("Use"));//use on range
                new ConditionalSleep(10000) {//chill for 10000
                    @ Override
                    public boolean condition() throws InterruptedException {//override condition
                        return (UnpizzaWidget != null && (UnpizzaWidget.isVisible()));
                    }
                }.sleep();//sleep
                cookAll();//call cookAll method SEE LINE 77
            }
        }
    }//end cookUncooked
}//end main

 

Share this post


Link to post
Share on other sites
4 hours ago, Token said:

Follow the scripting setup guide I posted, it's under featured topics

I have, I followed it as best I could, I didn't setup GIT because I dont want it setup at the moment. My only issue is that I cannot manage to get the dependencies bit to work. The bit that's irritating me is the fact that IntelliJ says my main class isn't being used. Which makes no sense to me. Thankyou for all the help though, would it help if I sent pictures of all my settings?

Share this post


Link to post
Share on other sites

Sometimes for me when making a new script the option to "Put into Output Root" is not there and it says "Extract into Output Root."  Make sure it actually says "Put."  Then maybe Output Directory for the JAR could go right to your USB, check script != null on the USB before disconnecting, then move to the PC.

I was able to copy paste your code above and make the JAR, build project, open OSBot, find script, run script. All inside of IntelliJ IDEA Community Edition 2019.3.4 x64

Share this post


Link to post
Share on other sites
On 4/2/2020 at 3:31 AM, Ace99 said:

Sometimes for me when making a new script the option to "Put into Output Root" is not there and it says "Extract into Output Root."  Make sure it actually says "Put."  Then maybe Output Directory for the JAR could go right to your USB, check script != null on the USB before disconnecting, then move to the PC.

I was able to copy paste your code above and make the JAR, build project, open OSBot, find script, run script. All inside of IntelliJ IDEA Community Edition 2019.3.4 x64

weird, my script worked perfectly for you? How do you mean "check scrit != null" on my USB? Did you have issues with intelliJ saying the script wasnt using the main function?

Share this post


Link to post
Share on other sites
8 hours ago, MoonMan said:

weird, my script worked perfectly for you? How do you mean "check scrit != null" on my USB? Did you have issues with intelliJ saying the script wasnt using the main function?

Yeah it did. I didn't run the pizza maker to actually see the bot functionality but I made the JAR, found it on OSBot local, ran the script and it started the login process with no error.  Script != null on the USB was just a way to say make sure the script JAR is on your USB before you move it over (to make sure the USB isn't the issue).  No issues with main class.

Honestly just delete all the files associated with the project, make a new project, setup your library and artifact compile out, copy the code here and paste into the new project and see if it works for you.  It did for me, so it has to be one of your setting. If a fresh start doesn't work, attach a pic of your project structure settings.

Share this post


Link to post
Share on other sites
15 minutes ago, Ace99 said:

Yeah it did. I didn't run the pizza maker to actually see the bot functionality but I made the JAR, found it on OSBot local, ran the script and it started the login process with no error.  Script != null on the USB was just a way to say make sure the script JAR is on your USB before you move it over (to make sure the USB isn't the issue).  No issues with main class.

Honestly just delete all the files associated with the project, make a new project, setup your library and artifact compile out, copy the code here and paste into the new project and see if it works for you.  It did for me, so it has to be one of your setting. If a fresh start doesn't work, attach a pic of your project structure settings.

I'll give it a go certainly. Thankyou for all the help. Just so I know, did the script actually function? If you have discord I can ad you and we can discuss further, if thats against forum rules I'm sorry. Its just easier to discuss directly. I might have to just start everything again. I am really confused. I got OSBot up and running on my scripting PC and I compiled the script directly into my script folder and had copy-pasted from this forum post over to IntelliJ. But it still didn't show up. Really lost here.

Share this post


Link to post
Share on other sites

You are building the artifact at the top, right? Build > Build Artifacts > Build/Rebuild.  Since I got it running I would try to start it all over fresh.  If you follow a setup guide from Token or Explv step by set it will work.

Share this post


Link to post
Share on other sites
Posted (edited)

Don't worry about it saying that your Main class is not being used. Technically in the IDE it is not since you are not creating/extending from it anywhere.

Two things usually cause this error.

1. No ScriptManifest - You have this so most likely its number 2

2. Wrong java version.

For the wrong java version go to File -> Project Structure -> Project

Once you are in that window check to make sure that the Project SDK is 1.8 and that your Project Language Level is 8.

If you don't have JDK 1.8 option than you will have to download it from here.

Edited by BravoTaco
  • Like 1

Share this post


Link to post
Share on other sites
39 minutes ago, BravoTaco said:

Don't worry about it saying that your Main class is not being used. Technically in the IDE it is not since you are not creating/extending from it anywhere.

Two things usually cause this error.

1. No ScriptManifest - You have this so most likely its number 2

2. Wrong java version.

For the wrong java version go to File -> Project Structure -> Project

Once you are in that window check to make sure that the Project SDK is 1.8 and that your Project Language Level is 8.

If you don't have JDK 1.8 option than you will have to download it from here.

so it says my java version is 11.0. This can't be right though because asking my computer what Java version is being run it return 1.8.0, which is version 8. I go to IntelliJ and look for the JDK 8 and I cannot find it. I run linux and have checked using where and whereis to get filepaths of the Java JDK. I go to those filepaths to locate the new JDK and it cannot find them there. I am incredibly confused.

Share this post


Link to post
Share on other sites
1 hour ago, MoonMan said:

so it says my java version is 11.0. This can't be right though because asking my computer what Java version is being run it return 1.8.0, which is version 8. I go to IntelliJ and look for the JDK 8 and I cannot find it. I run linux and have checked using where and whereis to get filepaths of the Java JDK. I go to those filepaths to locate the new JDK and it cannot find them there. I am incredibly confused.

I don't have much experience using linux so I won't be able to help you out with it. But once you correct the java versions it should successfully build out. Sorry about not being able to assist further.

Share this post


Link to post
Share on other sites
2 hours ago, BravoTaco said:

2. Wrong java version.

Nice thinking.  @MoonMan remake the project and when you select new project, use the drop down and select Project SDK: 1.8

I also only have Java 8 on my computer but it gives me the option for Java 12 in that drop-down, it may default to the current java version the first time.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...