Jump to content

Changing attack styles


Paxy

Recommended Posts

First question: so basically i want the bot to go from, 20 str to 20 attack to 20 defence for example. I can get the bot to change to agressive attack style but it carries on clicking agressive attack style ive tried 2 or 3 differant ways but cant get it to stop clicking it. Any snippets to help me?

 

second question: I use eclipse and i like to run my scripts usually in debug mode so any minor changes i do are automatically transferred ( unless a restart is require for bigger changes like conditions ) is there a way to save the changes in eclipse and the bot know these changes have been made? Im having to restart the whole client just to change the name of an NPC and its really annoying 

Thank you.

@Override

public int onLoop() throws InterruptedException {

if (shouldEat()) {

currentState = State.EATING;

eatFood();

} else if (shouldAttackCow()) {

currentState = State.ATTACKING_COW;

attackCow();

} else if (shouldChangeAttackStyle()) {

currentState = State.CHANGING_ATTACK_STYLE;

changeAttackStyle();

} else {

currentState = State.IDLE;

idleActions();

}

return random(200, 500); // Sleep for a short duration before the next loop

}





private boolean shouldEat() {

return getSkills().getDynamic(Skill.HITPOINTS) < 7; // Check if HP is below 15

}



private void eatFood() throws InterruptedException {

if (!getTabs().isOpen(Tab.INVENTORY)) {

getTabs().open(Tab.INVENTORY);

}

if (getInventory().contains("Trout")) {

getInventory().getItem("Trout").interact("Eat");

}

}



private boolean shouldAttackCow() {

return !myPlayer().isAnimating() && COW_AREA.contains(myPosition());

}



private void attackCow() throws InterruptedException {

NPC cow = npcs.closest(npc -> npc.getName().equals("Cow") && !npc.isUnderAttack() && npc.hasAction("Attack"));

if (cow != null && cow.interact("Attack")) {

conditionalSleep(() -> myPlayer().isAnimating(), 5000);

}

}



private boolean shouldChangeAttackStyle() {

return getSkills().getStatic(Skill.STRENGTH) < 20 || getSkills().getStatic(Skill.ATTACK) < 20 || getSkills().getStatic(Skill.DEFENCE) < 20;

}



private void changeAttackStyle() throws InterruptedException {

switch (getState()) {

case CHANGE_TO_AGGRESSIVE:

selectAttackStyle(AGGRESSIVE_ATTACK_STYLE_CHILD_ID);

break;

case CHANGE_TO_ACCURATE:

selectAttackStyle(ACCURATE_ATTACK_STYLE_CHILD_ID);

break;

case CHANGE_TO_DEFENSIVE:

selectAttackStyle(DEFENSIVE_ATTACK_STYLE_CHILD_ID);

break;

case IDLE:

log("We have reached 20 in all combat stats!");

this.stop();

break;

}

}



private boolean isAttackStyleSelected(int childId) {

// Assuming you have a constant for the parent ID of the combat styles interface

return getWidgets().get(593, childId).getSpriteIndex1() == 131;

}



private void selectAttackStyle(int childId) throws InterruptedException {

if (!getTabs().isOpen(Tab.ATTACK)) {

getTabs().open(Tab.ATTACK);

conditionalSleep(() -> getTabs().isOpen(Tab.ATTACK), 3000);

}

RS2Widget attackOption = getWidgets().get(COMBAT_OPTIONS_GROUP_ID, childId);

if (attackOption != null && attackOption.isVisible() && !isAttackStyleSelected(childId)) {

attackOption.interact();

conditionalSleep(() -> isAttackStyleSelected(childId), 3000);

}

}



private State getState() {

if (getSkills().getStatic(Skill.STRENGTH) < 20 && !isAttackStyleSelected(AGGRESSIVE_ATTACK_STYLE_CHILD_ID)) {

return State.CHANGE_TO_AGGRESSIVE;

} else if (getSkills().getStatic(Skill.ATTACK) < 20 && !isAttackStyleSelected(ACCURATE_ATTACK_STYLE_CHILD_ID)) {

return State.CHANGE_TO_ACCURATE;

} else if (getSkills().getStatic(Skill.DEFENCE) < 20 && !isAttackStyleSelected(DEFENSIVE_ATTACK_STYLE_CHILD_ID)) {

return State.CHANGE_TO_DEFENSIVE;

} else {

return State.IDLE;

}

}



private void idleActions() throws InterruptedException {

if (random(1, 100) <= 5) { // 5% chance to rotate the camera

getCamera().toEntity(npcs.closest("Cow"));

} else if (random(1, 100) <= 3) { // 3% chance to open a random tab

getTabs().open(Tab.values()[random(0, Tab.values().length)]);

}

sleep(random(200, 500));

}



private boolean conditionalSleep(java.util.function.BooleanSupplier condition, long timeout) throws InterruptedException {

long startTime = System.currentTimeMillis();

while (!condition.getAsBoolean() && (System.currentTimeMillis() - startTime) < timeout) {

sleep(100);

}

return condition.getAsBoolean();

}```

 

Edited by Paxy
Link to comment
Share on other sites

Create a method that stores skill levels on an integer and loop it. It's easier to work with integers, plus you can do all three in one method.

Create another method that compares these three integers. Eg if attack integer is higher than str integer, edit a string called "AttackStyle" to "Aggressive".

Create another method that checks for the string and do something like, if string is "Aggressive", if attack style is not Aggressive, switch to Aggressive.

Edited by FushigiBot
Link to comment
Share on other sites

This is what I do in a script that takes care of attack and strength. Wouldn't be hard to add on defence to it.

 

	
//main variables used
    String MyWeapon;
    int AttackWidgetID[] = {593, 4};
    int StrengthWidgetID[] = {593, 8};


//do this before attacking target
    void CheckGear(){
        int MyAttackLvl = getSkills().getDynamic(Skill.ATTACK);
        if (MyAttackLvl < 5) {
            MyWeapon = "Iron scimitar";
        } else if (MyAttackLvl >= 5 && MyAttackLvl < 10) {
            MyWeapon = "Steel scimitar";
        } else if (MyAttackLvl >= 10 && MyAttackLvl < 20) {
            MyWeapon = "Black scimitar";
        } else if (MyAttackLvl >= 20 && MyAttackLvl < 30) {
            MyWeapon = "Mithril scimitar";
        } else if (MyAttackLvl >= 30 && MyAttackLvl < 40) {
            MyWeapon = "Adamant scimitar";
        } else {
            MyWeapon = "Rune scimitar";
        }
        if(!getEquipment().isWearingItem(EquipmentSlot.WEAPON, MyWeapon)) {
            getTabs().open(Tab.INVENTORY);
            log("should equip weapon");
            log("My weapon = " + MyWeapon);
            if(inventory.contains(MyWeapon)) {
                log("attempting to equip " + MyWeapon);
                inventory.getItem(MyWeapon).interact("Wield");
            }
        }
        if(!getEquipment().isWearingItem(EquipmentSlot.AMULET, "Amulet of power")) {
            if(inventory.contains("Amulet of power")) {
                inventory.getItem("Amulet of power").interact("Wear");
            }
        }
    }

//do this also before attacking target
    void CheckCombatStyle() {
        int MyAttack = getSkills().getDynamic(Skill.ATTACK);
        int MyStrength = getSkills().getDynamic(Skill.STRENGTH);
        if ((MyAttack < 10) ||
                (MyAttack < 20 && MyStrength >= 10) ||
                (MyAttack < 30 && MyStrength >= 20) ||
                (MyAttack < 40 && MyStrength >= 30) ||
                (MyAttack < 50 && MyStrength >= 40) ||
                (MyAttack < 60 && MyStrength >= 50) ||
                (MyAttack < 70 && MyStrength >= 60) ||
                (MyAttack < 80 && MyStrength >= 70) ||
                (MyAttack < 90 && MyStrength >= 80) ||
                (MyAttack < 90 && MyStrength >= 80) ||
                (MyAttack < 99 && MyStrength >= 90)) {
            ActivateAttack();
        } else {
            ActivateStrength();
        }
    }


//do this if needed from CheckCombatStyle()
    void ActivateAttack() {
        int CombatStyle = getConfigs().get(43);
        if (CombatStyle != 0) {
            if (getTabs().open(Tab.ATTACK)) {
                if (getWidgets().get(AttackWidgetID[0], AttackWidgetID[1]).interact()) {
                    new ConditionalSleep(5000) {
                        @Override
                        public boolean condition() {
                            return CombatStyle == 0;
                        }
                    }.sleep();
                }
            }
        }
    }


//do this if needed from CheckCombatStyle()
    void ActivateStrength() {
        int CombatStyle = getConfigs().get(43);
        if (CombatStyle != 1) {
            if (getTabs().open(Tab.ATTACK)) {
                if (getWidgets().get(StrengthWidgetID[0], StrengthWidgetID[1]).interact()) {
                    new ConditionalSleep(5000) {
                        @Override
                        public boolean condition() {
                            return CombatStyle == 1;
                        }
                    }.sleep();
                }
            }
        }
    }

 

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