Jump to content

Minotaur Fighter script - questions


Prolax

Recommended Posts

package ProLaxMinotaurFighter;

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 java.awt.*;

@ScriptManifest(
        version = 1.0,
        name = "ProLaxMinotaurFighter",
        author = "ProLax",
        info = "This is a Minotaur Fighter script.",
        logo = ""
)

public class ProLaxMinotaurFighter extends Script{
    private int currentLevelStr;
    private int beginningLevelStr;
    private int beginningXpStr;
    private int currentXpStr;
    private int xpGainedStr;

    private int currentLevelAtt;
    private int beginningLevelAtt;
    private int beginningXpAtt;
    private int currentXpAtt;
    private int xpGainedAtt;

    private int currentLevelHp;
    private int beginningLevelHp;
    private int beginningXpHp;
    private int currentXpHp;
    private int xpGainedHp;

    public void onStart(){
        log("The Minotaur fighter script started.");
        beginningLevelStr = skills.getStatic(Skill.STRENGTH);
        beginningXpStr = skills.getExperience(Skill.STRENGTH);

        beginningLevelAtt = skills.getStatic(Skill.ATTACK);
        beginningXpAtt = skills.getExperience(Skill.ATTACK);

        beginningLevelHp = skills.getStatic(Skill.HITPOINTS);
        beginningXpHp = skills.getExperience(Skill.HITPOINTS);
    }

    public int onLoop() throws InterruptedException {
        NPC minotaur = npcs.closest("Minotaur");

        if(!myPlayer().isAnimating() && !myPlayer().isMoving()) {
            if(minotaur != null) {
                if (minotaur.isVisible()) {
                    minotaur.interact("Attack");
                    sleep(random(300, 600));
                } else {
                    camera.toEntity(minotaur);
                }
            }
        } else {
            sleep(random(300, 600));
        }

        return(random(100, 300));

    }

    public void onPaint(Graphics2D g) {

        Graphics2D gr = g;

        gr.setColor(Color.cyan);

        gr.drawString("Prolax Minotaur killer", 10, 230);

        currentLevelAtt = skills.getStatic(Skill.ATTACK);
        gr.drawString("Starting Attack level: " + beginningLevelAtt + " ~ Current Attack level: " + currentLevelAtt, 10,245);

        currentXpAtt = skills.getExperience(Skill.ATTACK);
        xpGainedAtt = currentXpAtt - beginningXpAtt;
        gr.drawString("Attack XP gained: " + xpGainedAtt, 10, 260);

        currentLevelStr = skills.getStatic(Skill.STRENGTH);
        gr.drawString("Starting Strength level: " + beginningLevelStr + " ~ Current Strength level: " + currentLevelStr, 10,275);

        currentXpStr = skills.getExperience(Skill.STRENGTH);
        xpGainedStr = currentXpStr - beginningXpStr;
        gr.drawString("Strength XP gained: " + xpGainedStr, 10, 290);

        currentLevelHp = skills.getStatic(Skill.HITPOINTS);
        gr.drawString("Starting Hitpoints level: " + beginningLevelHp + " ~ Current Hitpoints level: " + currentLevelHp, 10,305);

        currentXpHp = skills.getExperience(Skill.HITPOINTS);
        xpGainedHp = currentXpHp - beginningXpHp;
        gr.drawString("Hitpoints XP gained: " + xpGainedHp, 10, 320);

    }

    public void onExit(){
        this.log("The Minotaur fighter script stopped.");
    }

}

Hi,

 

I started a Minotaur Fighter script. I have a few questions.

 

- Once my player is attacking a NPC, the script keeps clicking on the NPC?

- How can I include more antibans methods?

- How can I implement more camera turns?

 

Thanks,

ProLax

 

Edited by Prolax
Link to comment
Share on other sites

        if(!myPlayer().isAnimating() && !myPlayer().isMoving() && !myPlayer().isUnderAttack()) {
            if(minotaur != null && minotaur.exists()) {
                if (minotaur.isVisible()) {
                    minotaur.interact("Attack");
                    sleep(random(300, 600));
                } else {
                    camera.toEntity(minotaur);
                }
            }
        }

Ok thanks for the answer. Could you explain why I need a global variable for minotaur? It's only used in OnLoop()

 

I edited my code, see above.

Link to comment
Share on other sites

        if(!myPlayer().isAnimating() && !myPlayer().isMoving() && !myPlayer().isUnderAttack()) {
            if(minotaur != null && minotaur.exists()) {
                if (minotaur.isVisible()) {
                    minotaur.interact("Attack");
                    sleep(random(300, 600));
                } else {
                    camera.toEntity(minotaur);
                }
            }
        }

Ok thanks for the answer. Could you explain why I need a global variable for minotaur? It's only used in OnLoop()

 

I edited my code, see above.

 

 

To check if the minotaur has no health/is null.

if (minotaur == null || !minotaur.exists() || minotaur.getHealth() == 0) {
    minotaur = getNpcs().closest("Minotaur");
}

if (!myPlayer().isUnderAttack() && minotaur != null && !minotaur.isUnderAttack()) {
    if (!minotaur.isVisible()) getCamera().toEntity(minotaur);
    minotaur.interact("Attack");
}

Something like this would work.

 

Link to comment
Share on other sites

  • 1 month later...

To check if the minotaur has no health/is null.

if (minotaur == null || !minotaur.exists() || minotaur.getHealth() == 0) {
    minotaur = getNpcs().closest("Minotaur");
}

if (!myPlayer().isUnderAttack() && minotaur != null && !minotaur.isUnderAttack()) {
    if (!minotaur.isVisible()) getCamera().toEntity(minotaur);
    minotaur.interact("Attack");
}

Something like this would work.

 

I'm not understanding how the three conditions in the first if-statement work.

I'm new to this, but I thought == null and !exists() are the same thing? And if any of the conditions evaluate to true, why would you choose that Minotaur? It seems like it wouldn't be attackable in any of those cases

 

NPC cow = getNpcs().closest(NAME);
if (cow != null && cow.isAttackable() && cow.getHealth() > 0)
	if (cow.isVisible())
		cow.interact("Attack");
	else if (!cow.isVisible())
		camera.toEntity(cow);
		cow.interact("Attack");

This is how I've laid out my Cow killer script. Would this work?

Link to comment
Share on other sites

I'm not understanding how the three conditions in the first if-statement work.

I'm new to this, but I thought == null and !exists() are the same thing? And if any of the conditions evaluate to true, why would you choose that Minotaur? It seems like it wouldn't be attackable in any of those cases

NPC cow = getNpcs().closest(NAME);if (cow != null && cow.isAttackable() && cow.getHealth() > 0)	if (cow.isVisible())		cow.interact("Attack");	else if (!cow.isVisible())		camera.toEntity(cow);		cow.interact("Attack");
This is how I've laid out my Cow killer script. Would this work?

If our NPC is evaluated to NULL, we can't run #exists() on it. If those conditions evaluate to true, our Minotaur is dead and thus we need a new one.

Link to comment
Share on other sites

    public int onLoop() throws InterruptedException {
        NPC minotaur = getNpcs().closest("Minotaur");
        if (!myPlayer().isUnderAttack() || !myPlayer().isAnimating()) {
            if (minotaur != null && minotaur.isAttackable() && minotaur.getHealth() > 0) {
                if (minotaur.isVisible()) {
                    minotaur.interact("Attack");
                } else if (!minotaur.isVisible()) {
                    camera.toEntity(minotaur);
                    minotaur.interact("Attack");
                }
            }
        }
        return (random(100, 300));
    }

Hi,

 

I still have the following problem, my player keeps spam clicking minotaurs, while it is already fighting a minotaur.

 

 

    public int onLoop() throws InterruptedException {
        NPC minotaur = getNpcs().closest("Minotaur");
        if(minotaur.exists() && !myPlayer().isUnderAttack()){
            if(!minotaur.isVisible()){
                camera.toEntity(minotaur);
            }
            minotaur.interact("attack");
            sleep(700);
        }
        return (random(100, 300));
    }

I edited a bit.

 

 

Link to comment
Share on other sites

    public int onLoop() throws InterruptedException {
        NPC minotaur = getNpcs().closest("Minotaur");
        if (!myPlayer().isUnderAttack() || !myPlayer().isAnimating()) {
            if (minotaur != null && minotaur.isAttackable() && minotaur.getHealth() > 0) {
                if (minotaur.isVisible()) {
                    minotaur.interact("Attack");
                } else if (!minotaur.isVisible()) {
                    camera.toEntity(minotaur);
                    minotaur.interact("Attack");
                }
            }
        }
        return (random(100, 300));
    }

Hi,

 

I still have the following problem, my player keeps spam clicking minotaurs, while it is already fighting a minotaur.

 

 

    public int onLoop() throws InterruptedException {
        NPC minotaur = getNpcs().closest("Minotaur");
        if(minotaur.exists() && !myPlayer().isUnderAttack()){
            if(!minotaur.isVisible()){
                camera.toEntity(minotaur);
            }
            minotaur.interact("attack");
            sleep(700);
        }
        return (random(100, 300));
    }

I edited a bit.

 

 

After you attack minotaur, set him into a global variable (say, npc)

private NPC npc;
public int onLoop() throws InterruptedException {
    if (npc == null || !npc.exists() || npc.getHealth() == 0) {
        //find new npc
        NPC minotaur = getNpcs().closest("Minotaur");
        //minotaur checks
        minotaur.interact("Attack");
        npc = minotaur;
    }
}
  • Like 1
Link to comment
Share on other sites

 

After you attack minotaur, set him into a global variable (say, npc)

private NPC npc;
public int onLoop() throws InterruptedException {
    if (npc == null || !npc.exists() || npc.getHealth() == 0) {
        //find new npc
        NPC minotaur = getNpcs().closest("Minotaur");
        //minotaur checks
        minotaur.interact("Attack");
        npc = minotaur;
    }
}

 

This is a nice and efficient approach, since it avoids filtering the NPCs redundantly in every cycle.

But be sure to not rely on an interaction completing successfully like it does in this particular example (failing to attack = stuck forever)

private NPC npc;
public int onLoop() throws InterruptedException {
    if (npc == null || !npc.exists() || npc.getHealth() == 0) {
        //find new npc
        NPC minotaur = getNpcs().closest("Minotaur");
        //minotaur checks
        npc = minotaur;
    } else if(myPlayer().getInteracting() != npc) {
        npc.interact("Attack");
    }
}
Link to comment
Share on other sites

 

This is a nice and efficient approach, since it avoids filtering the NPCs redundantly in every cycle.

But be sure to not rely on an interaction completing successfully like it does in this particular example (failing to attack = stuck forever)

private NPC npc;
public int onLoop() throws InterruptedException {
    if (npc == null || !npc.exists() || npc.getHealth() == 0) {
        //find new npc
        NPC minotaur = getNpcs().closest("Minotaur");
        //minotaur checks
        npc = minotaur;
    } else if(myPlayer().getInteracting() != npc) {
        npc.interact("Attack");
    }
}

 

Alternatively..

npc = (minotaur.interact("Attack") ? minotaur : null);

 

  • Like 1
Link to comment
Share on other sites

Thanks a lot, the attacking is now working perfect.

Next I'm going to implement looting and eating.

I've read that using states is not adviced, what should I use instead?

I'm on my phone here so forgive any typos.

You should look into something called a Node system, which is essentially an object oriented way of handling numerous tasks.

The idea is to have an abstract base class (let's call it Node) and have all of your nodes (eat, fight, loot) extend our Node class.

public abstract class Node
In the abstract node clasa there should also be two abstract methods (let's call them canProcess and process). Each of our nodes will override this method with our own code.

We can store each node in a List<Node> since they all extend our abstract Node class, and then call our abstract methods (canProcess and process) because they are defined in our Node class

In our onLoop, we want to see if we can process each node and then run it. You want do loop through every node, see if canProcess returns true, and if it does run process.

Hope this helped, I believe there is a tutorial somewhere in the forums for it :)

  • Like 1
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.
Note: Your post will require moderator approval before it will be visible.

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