Jump to content

Hover Function


Gearfighter

Recommended Posts

Hi everyone,

 

I am currently nearly finished with the combat portion of my script, as it is attacking only one thing at a time, and waiting till it dies to attack another NPC, and also not attacking other NPC's already in combat.

 

Something i thought that would be really good to polish of the script off would be to add in a hover option so that as soon as the npc the bot is killing dies, it clicks on the next available, not in combat npc.

 

Just something that would be good as it would make the bot get potentionally more exp/hour.

 

http://pastebin.com/7XCBwFYi

 

That is my pastebin of the script i have currently.

 

What would i need to add and explain why so i can learn. And is there anything i need to change in my script to make the script run smoother or be more functional?

 

I have been researching as well so its not like im asking for an easy cop out. i have been trying to learn java for a couple days and looking at all different open source scripts to learn more and more.

 

Cheers in advance,

 

Gearfighter

Link to comment
Share on other sites

Hi everyone,

 

I am currently nearly finished with the combat portion of my script, as it is attacking only one thing at a time, and waiting till it dies to attack another NPC, and also not attacking other NPC's already in combat.

 

Something i thought that would be really good to polish of the script off would be to add in a hover option so that as soon as the npc the bot is killing dies, it clicks on the next available, not in combat npc.

 

Just something that would be good as it would make the bot get potentionally more exp/hour.

 

http://pastebin.com/7XCBwFYi

 

That is my pastebin of the script i have currently.

 

What would i need to add and explain why so i can learn. And is there anything i need to change in my script to make the script run smoother or be more functional?

 

I have been researching as well so its not like im asking for an easy cop out. i have been trying to learn java for a couple days and looking at all different open source scripts to learn more and more.

 

Cheers in advance,

 

Gearfighter

 

When you are under attack, find the next NPC which is not equal to the NPC you are attacking, that has health > 0 and is not under attack from another player, and then use hover() to hover over it.

Link to comment
Share on other sites

How would i go about putting that into my script.

 

sorry for being nooby but ive been looking all over the place trying to do it

 

Perhaps something like this (Sorry can't be bothered to test it):

import org.osbot.rs07.api.filter.NameFilter;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

@ScriptManifest(name = "Cow Killer", info = "Kills Cows...", author = "Explv", version = 0.1, logo = "")
public final class CowKiller extends Script {

    private NPC currentCow, nextCow;

    @Override
    public final int onLoop() throws InterruptedException {

        if(isAttackingCow()) {
            hoverNextNPC();
        } else {
            currentCow = null;
            attackNPC();
        }
        return random(150, 200);
    }

    private boolean isAttackingCow() {
        return currentCow != null &&
               currentCow.exists() &&
               currentCow.getHealthPercent() > 0 &&
               myPlayer().isInteracting(currentCow);
    }

    private void hoverNextNPC() {
        nextCow = getClosestCow();
        if(nextCow != null && !getMouse().isOnCursor(nextCow)) {
            nextCow.hover();
        }
    }

    private void attackNPC() {

        currentCow = isAttackableTarget(nextCow) ? nextCow : getClosestCow();

        if(currentCow != null && currentCow.interact("Attack")) {
            new ConditionalSleep(5000) {
                @Override
                public boolean condition() throws InterruptedException {
                    return myPlayer().isInteracting(currentCow) ||
                           !isAttackableTarget(currentCow);
                }
            }.sleep();
        }
    }

    private NPC getClosestCow() {
        return getNpcs().closest(
                new NameFilter<>("Cow", "Cow calf"),
                npc -> npc != currentCow &&
                       isAttackableTarget(npc)
        );
    }

    private boolean isAttackableTarget(final NPC target) {
        return target != null &&
               target.exists() &&
               target.getHealthPercent() > 0 &&
               !target.isUnderAttack();
    }
}

Explanation:

- If the we are under attack:
  - If we are hovering over another cow (nextCow variable) and that cow is attackable:
    - Set that cow as the cow to attack
  - Else find the closest attackable cow
  - Store the cow that we found in the global variable currentCow, to be used when hovering
  - If we have an attackable cow (!= null):
    - Use the interaction "Attack" on the cow
    - If the interaction was successful:
      - Sleep for 5 seconds, or until we are attacking the cow,
        or until the cow is no longer attackable.

- If the player is not under attack:
  - Find the closest cow that is not the cow we are attacking (currentCow), and that is attackable
  - If a cow is found (!= null):
    - Store the cow in the global variable nextCow, to be used when attacking
    - If we are not already hovering over that cow:
      - Hover over the cow
Edited by Explv
  • Like 2
Link to comment
Share on other sites

 

Perhaps something like this (Sorry can't be bothered to test it):

import org.osbot.rs07.api.filter.NameFilter;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

@ScriptManifest(name = "Cow Killer", info = "Kills Cows...", author = "Explv", version = 0.1, logo = "")
public final class CowKiller extends Script {
    
    private NPC currentCow;
    
    @Override
    public final int onLoop() throws InterruptedException {
        
        if(isAttackingCow()) {
            hoverNextNPC();    
        } else {
            currentCow = null;
            attackNPC();
        }
        return random(150, 200);
    }
    
    private boolean isAttackingCow() {
        return currentCow != null && 
               currentCow.exists() && 
               currentCow.getHealthPercent() > 0 &&
               myPlayer().isInteracting(currentCow);
    }
    
    private void hoverNextNPC() {
        NPC hoverCow = getClosestCow();
        if(hoverCow != null && !getMouse().isOnCursor(hoverCow)) {
            hoverCow.hover();
        }
    }
    
    private void attackNPC() {
        
        currentCow = getClosestCow();
        
        if(currentCow != null && currentCow.interact("Attack")) {
            new ConditionalSleep(5000) {
                @Override
                public boolean condition() throws InterruptedException {
                    return !currentCow.exists() ||
                            currentCow.getHealthPercent() == 0 || 
                            myPlayer().isUnderAttack() || 
                            myPlayer().isInteracting(currentCow);
                }
            }.sleep();
        }
    }
    
    private NPC getClosestCow() {
        return getNpcs().closest(
                new NameFilter<>("Cow", "Cow calf"),
                npc -> npc != currentCow &&
                       !npc.isUnderAttack() &&
                       npc.getHealthPercent() > 0
        );
    }
}

Explanation:

 

  • If the player is not under attack, you find the closest Cow that isn't under attack from another player, and has health > 0 (not doing it's dying animation). If a cow is successfully found (!= null), perform the interaction "Attack", and then sleep until the player is attacking that cow, or until the cow no longer exists, or for 5 seconds.
  • If the player is under attack, find the next closest Cow, that isn't equal to the Cow the player is attacking, is not under attack from another player, has health > 0. If a Cow is found, and we are not already hovering over it, then hover over it. 

 

 

This is great.

Link to comment
Share on other sites

 

Perhaps something like this (Sorry can't be bothered to test it):

import org.osbot.rs07.api.filter.NameFilter;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

@ScriptManifest(name = "Cow Killer", info = "Kills Cows...", author = "Explv", version = 0.1, logo = "")
public final class CowKiller extends Script {

    private NPC currentCow, nextCow;

    @Override
    public final int onLoop() throws InterruptedException {

        if(isAttackingCow()) {
            hoverNextNPC();
        } else {
            currentCow = null;
            attackNPC();
        }
        return random(150, 200);
    }

    private boolean isAttackingCow() {
        return currentCow != null &&
               currentCow.exists() &&
               currentCow.getHealthPercent() > 0 &&
               myPlayer().isInteracting(currentCow);
    }

    private void hoverNextNPC() {
        nextCow = getClosestCow();
        if(nextCow != null && !getMouse().isOnCursor(nextCow)) {
            nextCow.hover();
        }
    }

    private void attackNPC() {

        currentCow = isAttackableTarget(nextCow) ? nextCow : getClosestCow();

        if(currentCow != null && currentCow.interact("Attack")) {
            new ConditionalSleep(5000) {
                @Override
                public boolean condition() throws InterruptedException {
                    return myPlayer().isInteracting(currentCow) ||
                           !isAttackableTarget(currentCow);
                }
            }.sleep();
        }
    }

    private NPC getClosestCow() {
        return getNpcs().closest(
                new NameFilter<>("Cow", "Cow calf"),
                npc -> npc != currentCow &&
                       isAttackableTarget(npc)
        );
    }

    private boolean isAttackableTarget(final NPC target) {
        return target != null &&
               target.exists() &&
               target.getHealthPercent() > 0 &&
               !target.isUnderAttack();
    }
}

Explanation:

- If the we are under attack:
  - If we are hovering over another cow (nextCow variable) and that cow is attackable:
    - Set that cow as the cow to attack
  - Else find the closest attackable cow
  - Store the cow that we found in the global variable currentCow, to be used when hovering
  - If we have an attackable cow (!= null):
    - Use the interaction "Attack" on the cow
    - If the interaction was successful:
      - Sleep for 5 seconds, or until we are attacking the cow,
        or until the cow is no longer attackable.

- If the player is not under attack:
  - Find the closest cow that is not the cow we are attacking (currentCow), and that is attackable
  - If a cow is found (!= null):
    - Store the cow in the global variable nextCow, to be used when attacking
    - If we are not already hovering over that cow:
      - Hover over the cow

 

Hey Explv, thankyou for this, i will give it a shot. its very helpful and informative!

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