Jump to content
Stando

WhizFighter (WIP, Ver 1.0)

Recommended Posts

Posted (edited)

Hello everyone. I have developed a basic combat bot. This bot will attack any IDs that are placed within the array stating ENEMY_IDS. This bot can also check for one's health, and eat specific food based on the FOOD_IDs that are given to it. The LOOT array (or list) accepts any loot IDs. I would like as many people as possible to respond to this thread, and to post any feedback that they have in mind. Factors like how much experience you gained in your stats, or how long it took to get from one level to another would be appreciated! Also, if you would make any modifications, what modifications would you make?

Below is the code for WhizFighter. The GUI elements can be ignored since they have not been implemented correctly yet. I am looking for a way to allow the user to input IDs and numbers they found from the debug menu in order to have them choose whatever monster to attack in game, rather than going through code and manually doing it that way.

Quote
import org.osbot.rs07.api.map.constants.Banks;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import javax.swing.*;
import java.lang.reflect.InvocationTargetException;

@ScriptManifest(name = "WhizFighter", author = "Happy", info = "Combat bot", version = 1.0, logo = "")
public class WhizFighter extends Script {
    private final int FOOD_ID = 379;
    private final int [] ENEMY_IDS = {3302, 3030, 3017, 3029, 3035};
    private final int [] LOOT = {526};

    private GUI gui = new GUI();
    private String Monster;
    public int monster = 0;

    @Override
    public void onStart() {
        log("Starting WhizFighter!");

        try {
            SwingUtilities.invokeAndWait(() -> {
                gui = new GUI();
                gui.open();
                log("Click start to begin script!");
            });
        } catch (InterruptedException | InvocationTargetException e) {
            e.printStackTrace();
            stop();
            return;
        }

        if(!gui.isStarted()) {
            stop();
            return;
        }

        Monster = gui.getMonsterID();

    }

    @Override
    public int onLoop() throws InterruptedException {

        isReadyToAttack();

        attack();

        return random(1000, 6000);
    }

    @Override
    public void onExit() {
        if (gui != null) {
            gui.close();
        }
    }


    public void attack() throws InterruptedException {

        if(!isReadyToAttack()) {
            return;
        }

        if(getHPPercent() < 50) {
            heal();
        }

        Monster = gui.getMonsterID();

        if(!enemy().isUnderAttack()) {
            enemy().interact("Attack");
        }


    }

    public void bank() throws InterruptedException {

        if(!Banks.LUMBRIDGE_UPPER.contains(myPosition()) && getInventory().isFull()) {
            getWalking().webWalk(Banks.LUMBRIDGE_UPPER);
            getBank().open();
            getBank().depositAll(LOOT);
        }

    }

    public int getHPPercent() {

        log("Getting current HP %");

        float staticHP = getSkills().getStatic(Skill.HITPOINTS);
        float dynamicHP = getSkills().getDynamic(Skill.HITPOINTS);
        return (int) (100 * (dynamicHP / staticHP));

    }

    private NPC enemy() throws InterruptedException {
        return getNpcs().closest(ENEMY_IDS);
    }

    public boolean hasFood() {
        getInventory().contains(387);
        return false;
    }

    public void heal() throws InterruptedException {

        sleep(2000);
        getInventory().getItem(387).interact("Eat");

    }

    public boolean isReadyToAttack() {

        if (getCombat().isFighting()) {
            return false;
        }
        else if(myPlayer().isAnimating() || myPlayer().isUnderAttack() || myPlayer().isMoving()) {
            return false;
        }

        return true;
    }

    public void loot() throws InterruptedException {
        getGroundItems().closest(LOOT).interact("Take");
    }

}

 

Edited by Stando
  • Like 1
Link to comment
Share on other sites

57 minutes ago, Wishy said:
   public boolean hasFood() {
        getInventory().contains(387);
        return false;
    }

    public void heal() throws InterruptedException {

        sleep(2000);
        getInventory().getItem(387).interact("Eat");

 

Unless im mistaken. 387 should be 379?

387 is Burnt Shark.

387 may be Burnt Shark, but I do not have the IDs openly available unless I open OSBot. Thank you for stating this though. The ID would be changed manually by those who run the script. Just think of it as a placeholder for now. 

Link to comment
Share on other sites

6 hours ago, Stando said:

387 may be Burnt Shark, but I do not have the IDs openly available unless I open OSBot. Thank you for stating this though. The ID would be changed manually by those who run the script. Just think of it as a placeholder for now. 

Use an item Database search.

 

Best practice is having your IDs matching. As someone may just change the "379" to their respective food ID.

Link to comment
Share on other sites

On 5/1/2022 at 6:39 PM, Lunar said:

Check out Explv's tutorial, at the bottom of it there's a section on making a GUI. Should help you to allow users to chose what they want to fight.
 

 

I actually used this guide for reference. What it doesn't show is allowing text input for IDs related to items or monsters. If someone could show me how to do that, maybe one on one, that would be great.   

On 5/2/2022 at 2:24 AM, Wishy said:

Use an item Database search.

 

Best practice is having your IDs matching. As someone may just change the "379" to their respective food ID.

Okay, this is a good idea. There should be databases openly available for monster IDs and item IDs.

Link to comment
Share on other sites

1 hour ago, Stando said:

I actually used this guide for reference. What it doesn't show is allowing text input for IDs related to items or monsters. If someone could show me how to do that, maybe one on one, that would be great. 

Check out this guide to java swing components, you'll want to be looking at the JTextField.https://web.mit.edu/6.005/www/sp14/psets/ps4/java-6-tutorial/components.html

Link to comment
Share on other sites

On 5/13/2022 at 8:42 PM, Stando said:

I actually used this guide for reference. What it doesn't show is allowing text input for IDs related to items or monsters. If someone could show me how to do that, maybe one on one, that would be great.   

Okay, this is a good idea. There should be databases openly available for monster IDs and item IDs.

https://chinplugins.xyz/items is the one i use. Its the most up to date.

Link to comment
Share on other sites

Posted (edited)
4 hours ago, Stando said:

I read through JTextfield. When I added one to my GUI, it stopped working.

e265e7a3aa3d1a26ddfba14574f48425.png

 

You're adding the textfield to itself, and the label to itself. Make a new JPanel first, then add the label and textfield to the panel.

You should end up having a main panel that everything is added to, and then for each form of input whether it's a button, textfield, checkbox etc. you should have a panel, label, and form of input. Label and input are added to the panel, then that panel is added to the main panel.
 

Edited by Lunar
Link to comment
Share on other sites

21 hours ago, Lunar said:

You're adding the textfield to itself, and the label to itself. Make a new JPanel first, then add the label and textfield to the panel.

You should end up having a main panel that everything is added to, and then for each form of input whether it's a button, textfield, checkbox etc. you should have a panel, label, and form of input. Label and input are added to the panel, then that panel is added to the main panel.
 

10166c57c67834585718545f1febccdf.png

Thank you! This actually was a fix. How do I put spaces in between labels? This is how it currently looks (I put it in the WC GUI I made as an example). The GUI also logs me out after hitting start.

Link to comment
Share on other sites

Posted (edited)
2 hours ago, Stando said:

10166c57c67834585718545f1febccdf.png

Thank you! This actually was a fix. How do I put spaces in between labels? This is how it currently looks (I put it in the WC GUI I made as an example). The GUI also logs me out after hitting start.

Set the layout on each panel to something like FlowLayout.LEFT. For the logging out, you're gonna need to check what you're doing when you press the button. Should be a simple fix, just find where you're stopping the script.

Edited by Lunar
Link to comment
Share on other sites

21 hours ago, Lunar said:

Set the layout on each panel to something like FlowLayout.LEFT. For the logging out, you're gonna need to check what you're doing when you press the button. Should be a simple fix, just find where you're stopping the script.

0df359936f01717624cd6597f1418275.png

The logger does not show me any errors . Do you see as to why the script would log me out after hitting "Start"?

Link to comment
Share on other sites

2 hours ago, Stando said:

The logger does not show me any errors . Do you see as to why the script would log me out after hitting "Start"?

Can I see your isStarted method, and your start button listener? I would guess that you have something going on in one of those that is causing it to stop the script.

Link to comment
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.



  • Recently Browsing   0 members

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