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.

Noob question - Why Isn't this Task looping?

Featured Replies

  • I'm learning the different types of script making.
  • With this task based script I'm wondering why the <SlapCrabs> task only fights 1 npc then does nothing? ( testing on Highwayman, but the script will eventually be for crabs )

I know that you can use NPC filters and Lambda's ect. But for now I'm just trying to get this task to loop, It's supposed to fight highwaymen, But it only attacks 1 and then doesn't attack anymore after that?

here is the

  1. SlapCrabs ( Not looping )
  2. Task
  3. Main 

Why does it only kill 1 npc then stop? The canProcess() is true so it should attack as long as it's true?

SlapCrabs

package core;
import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.MethodProvider;


public class SlapCrabs extends Task {
	public SlapCrabs(MethodProvider api) {
		super(api);
	}
	public static Area crabZone = new Area(3013, 3288, 2999, 3270);
	NPC npc = api.getNpcs().closest("Highwayman");
	

	@Override
	public boolean canProcess() {
		return 
		crabZone.contains(api.myPlayer()) && npc.isAttackable();
	}

	@Override
	public void process() {
		npc.interact("Attack");
		api.log("Slappin Crabz'");
	}
}


Task

package core;

import org.osbot.rs07.script.MethodProvider;

public abstract class Task {
	protected MethodProvider api;

	public Task(MethodProvider api) {
		this.api = api;
	}

	public abstract boolean canProcess();

	public abstract void process();
	
	public void run() {
		if (canProcess())
			process();
	}
	
}

 

Edited by Elixar

1 hour ago, Elixar said:
  • I'm learning the different types of script making.
  • With this task based script I'm wondering why the <SlapCrabs> task only fights 1 npc then does nothing? ( testing on Highwayman, but the script will eventually be for crabs )

I know that you can use NPC filters and Lambda's ect. But for now I'm just trying to get this task to loop, It's supposed to fight highwaymen, But it only attacks 1 and then doesn't attack anymore after that?

here is the

  1. SlapCrabs ( Not looping )
  2. Task
  3. Main 

Why does it only kill 1 npc then stop? The canProcess() is true so it should attack as long as it's true?

SlapCrabs


package core;
import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.MethodProvider;


public class SlapCrabs extends Task {
	public SlapCrabs(MethodProvider api) {
		super(api);
	}
	public static Area crabZone = new Area(3013, 3288, 2999, 3270);
	NPC npc = api.getNpcs().closest("Highwayman");
	

	@Override
	public boolean canProcess() {
		return 
		crabZone.contains(api.myPlayer()) && npc.isAttackable();
	}

	@Override
	public void process() {
		npc.interact("Attack");
		api.log("Slappin Crabz'");
	}
}


Task


package core;

import org.osbot.rs07.script.MethodProvider;

public abstract class Task {
	protected MethodProvider api;

	public Task(MethodProvider api) {
		this.api = api;
	}

	public abstract boolean canProcess();

	public abstract void process();
	
	public void run() {
		if (canProcess())
			process();
	}
	
}


Main
 


package core;

import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import java.awt.*;
import java.util.ArrayList;

@ScriptManifest(author = "Elixar", info = "Fossil Island Crabs", logo = "https://i.imgur.com/tcvs0Wx.png", name = "Fossil Island Crabs", version = 0)

public class Main extends Script {
	ArrayList<Task> tasks = new ArrayList<Task>();
	private int slapped = 42;
	public String state = "Status: Idle";
	
	
	@Override
	public void onStart() {
		tasks.add(new WalkToCrabs(this));
		tasks.add(new SlapCrabs(this));
		log("Task System:Loading Tasks...");
		log("Task System:( ACTIVE )");
	}
	
	@Override
	public void onExit() {
		log("ree");
	}

	@Override
	public int onLoop() throws InterruptedException {
		tasks.forEach(tasks -> tasks.run());
		return 700;
	}

	@Override
	public void onPaint(Graphics2D g) {
		super.onPaint(g);
		g.setColor(Color.CYAN);
		g.setFont(new Font("Trebuchet MS", Font.BOLD, 14));
		g.drawString("Island Crabs 0.4", 8, 300);//X: 450 (left and right), Y: 345 (up and down)
		g.drawString("by Elixar", 8, 320);
		g.drawString("o", (int)getMouse().getPosition().getX() - 4, (int)getMouse().getPosition().getY() + 5);
		g.drawString(state, 8, 50);
		g.drawString("XP Gained: " + getExperienceTracker().getGainedXP(Skill.ATTACK) + " [lvl " + getExperienceTracker().getGainedLevels(Skill.ATTACK) + " ]", 8, 80);
		g.drawString("Slapped Crabs: " + slapped, 400, 320);
		
		
	}

}





:feels:        ?        :feels:          ?     :feels:

It's because you're declaring the Highwayman outside of the run loop, so it essentially only searches once for an available highwayman, move the 
 

NPC npc = api.getNpcs().closest("Highwayman");

into the process method. 

edit: to summarize, the task actually is actually being checked,, but it's only searching for a highwayman when the class is initially loaded, so Npc#isAttackable returns false

Edited by Slut

  • Author



Thank You!❤️

Edited by Elixar

32 minutes ago, Elixar said:

Oh my god you're 100% right.

You literally just took so much stress off my mind

Thank You!❤️

In the future, try placing some simple logs in your verify function (canProcess).

For example, in this case simply adding:

If (crabZone.contains(api.myPlayer())

   log("contains")

If (npc.isAttackable())

    log("attackable")

 

Would have greatly limit your bug searching to a specific area of the code and helped you figure out everything faster.

Just some advice :)

 

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.