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
  • Variables


    ElChapoJr

    Recommended Posts

    Hello Everyone! I am brand new to scripting so don't mind my nooby-ness :P

     

    But I have a question, In my GUI the player is able to select 3 locations. And the goal is whenever they select the location the bot walks to that area. So the script would need the input from the GUI  However i'm not entirely sure how to put that into code. Any help is appreciated. Im assuming it has something to do with getters and setters.

    Heres what I have so far. (Dont judge im stilll learning :P) The VictimType is working fine. But the Location is where im having the issues.

     

    Thanks!

    public int onLoop() {
            if (startScript) {
                if (gui.Location().contains(getLocalPlayer())) {
                    pickPocket(gui.getVictimType());
                } else {
                    if (getWalking().walk(gui.Location().getRandomTile())) {
                    }
                }
            }
            return 600;
        }
    
    Link to comment
    Share on other sites

     

    public int onLoop() {
            if (startScript) {
                if (gui.Location().contains(getLocalPlayer())) {
                    pickPocket(gui.getVictimType());
                } else {
                    if (getWalking().walk(gui.Location().getRandomTile())) {
                    }
                }
            }
            return 600;
        }
    

    Since you are newish to coding I'll show you an easy but not the cleanest way to do what you want done. It's very easy to follow along and will work for what you need done.

     

    What you need to do is implement a ActionListener in your GUI.

     

    For example here is a ComboBox action listener in a Gui class

    npcComboBox.addActionListener(e -> selectedNPC = npcComboBox.getSelectedItem().toString());

    What this does is set my variable "String selectedNPC" in my gui class to a String that of the players choice

     

    For reference here is how I set my ComboBox

    npcComboBox.setModel(new DefaultComboBoxModel(new String[] {"Giant rat", "Scorpion", "Skeleton"}));

    So selectedNPC will change each time the user selects a new option in the ComboBox

     

    Now that we have information of what the player chose we need to convert the string into the location of what we selected, we do so by going to your Start button action listener (You should already have this implemented and your script shouldn't loop until your gui has been set.)

     

    Inside our Start button action listener we add

    if(selectedNPC == "Scorpion") {
    main.TaskArea = main.scorpionArea;
    }
    else if(selectedNPC =="Giant rat") {
    main.TaskArea = main.ratArea;
    }
    else if(selectedNPC == "Skeleton") {
    main.TaskArea = main.skeletonArea;
    }

    We check which String our user selected and change our Area in our Main class to the Area of the selected NPC, if your GUI is not in a separate class then you don't need to add "main."

    Link to comment
    Share on other sites

    Thanks Noodle!

     

    Do you mind if I pm you if I have any other questions?


    public int onLoop() {
            if (startScript) {
                if (gui.Location().contains(getLocalPlayer())) {
                    pickPocket(gui.getVictimType());
                } else {
                    if (getWalking().walk(gui.Location().getRandomTile())) {
                    }
                }
            }
            return 600;
        }
    

    Since you are newish to coding I'll show you an easy but not the cleanest way to do what you want done. It's very easy to follow along and will work for what you need done.

     

    What you need to do is implement a ActionListener in your GUI.

     

    For example here is a ComboBox action listener in a Gui class

    npcComboBox.addActionListener(e -> selectedNPC = npcComboBox.getSelectedItem().toString());

    What this does is set my variable "String selectedNPC" in my gui class to a String that of the players choice

     

    For reference here is how I set my ComboBox

    npcComboBox.setModel(new DefaultComboBoxModel(new String[] {"Giant rat", "Scorpion", "Skeleton"}));

    So selectedNPC will change each time the user selects a new option in the ComboBox

     

    Now that we have information of what the player chose we need to convert the string into the location of what we selected, we do so by going to your Start button action listener (You should already have this implemented and your script shouldn't loop until your gui has been set.)

     

    Inside our Start button action listener we add

    if(selectedNPC == "Scorpion") {
    main.TaskArea = main.scorpionArea;
    }
    else if(selectedNPC =="Giant rat") {
    main.TaskArea = main.ratArea;
    }
    else if(selectedNPC == "Skeleton") {
    main.TaskArea = main.skeletonArea;
    }

    We check which String our user selected and change our Area in our Main class to the Area of the selected NPC, if your GUI is not in a separate class then you don't need to add "main."

     

    Link to comment
    Share on other sites

    Thanks Noodle!

     

    Do you mind if I pm you if I have any other questions?

    Sure, although you'll probably get a faster response if you message me on Discord.

    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.