Jump to content

[Combat] Constant clicking on NPC


DragonTTK

Recommended Posts

I am trying to make a script and it will constantly keep clicking on the NPC regardless of if its already in combat or not and will sometimes try to switch to another npc in combat how would i go about stopping this?

 

Note im really new to this and would like to get into this sort of stuff.

 

Heres the code im using (Guard killer)

 

 

 

package GuardKiller;

import org.osbot.rs07.api.model.GroundItem;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;


@ScriptManifest(author = "Skeleton", info = "Kills falador guards", name = "Guard Killer", version = 1, logo = "http://osbot.org/images/logo.png")
public class GuardKiller extends Script {
    
    BufferedImage background;
    
    @Override
    public void onStart() {
        try{

background = ImageIO.read(GuardKiller.class.getResourceAsStream("/GuardKillers/images/bg.png"));
} catch(IOException e){

log(e);
}
    }

    private enum State {
        KILL, LOOT, WAIT, BANK, WALK,
    };

    private State getState() {
        NPC guard = npcs.closest("Guard");
        GroundItem loot = groundItems.closest("{Medium} Clue Scroll");
        if (guard != null)
            return State.KILL;
        if (loot != null)
            return State.LOOT;

        return State.WAIT;
    }

    @Override
    public int onLoop() throws InterruptedException {
        switch (getState()) {
        case KILL:
            NPC guard = npcs.closest("Guard");
         if(guard != null){
         guard.interact("Attack");
         log("Status: Attacking...");
         }
            break;
            
        case LOOT:
            GroundItem loot = groundItems.closest("{Medium} Clue Scroll");
            if (loot != null) {
                loot.interact("Take");
                log("Status: Looting...");
    
            }
            break;
        
        case WAIT:
            log("Status: Waiting...");
            sleep(random(500, 600));
            break;
            
        case BANK:
            log("Status: Banking...");
            break;
            
        case WALK:
            log("Status: Walking...");
            break;
    }
    return random(200, 300);

    }
    
    @Override
    public void onExit() {
    }
    
    @Override
public void onPaint(Graphics2D g){
        
if(background != null){

g.drawImage(background, null, 149, 154);
g.drawString("Guard killer", 37, 270);
}

}
    

 

Edited by DragonTTK
Link to comment
Share on other sites

  private State getState() {
        NPC guard = npcs.closest("Guard");
        GroundItem loot = groundItems.closest("{Medium} Clue Scroll");
        if (myPlayer().isUnderAttack()) {
            return State.WAIT;
        if (guard != null)
            return State.KILL;
        if (loot != null)
            return State.LOOT;
        return State.WAIT;
    } 

also try adding a sleep in your KILL state so when it clicks once it sleeps for a bit before trying to grab a new state

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

if (guard != null && guard.isAttackable() && !myPlayer().isUnderAttack())
            return State.KILL;

You need more checks other than "guard != null" if you want to fight NPC.

 

As IHB said, you should put a sleep after interaction; a conditional sleep.

if(guard != null){
   if(guard.interact("Attack")) {
      log("Status: Attacking...");
      new ConditionalSleep(4000, 500) {
	@Override
	public boolean condition() throws InterruptedException {
		return api.myPlayer().isInteracting(guard);
	}
      }.sleep();
   } 
}

It will check the condition() every 500 ms and wait maximum 4000 ms before executing the interaction again.

Edited by Woody
  • 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...