Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Combat] Constant clicking on NPC

Featured Replies

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

You're only checking the guard != null. To get started; you should also check if your player is not under attack, if the guard is not under attack and if the guard is still alive (not doing the death emote, cause then its still not null while performing the emote)

  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

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

  • Author

Oh i see makes sense alright ill try this out and stuff thanks guys!

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.