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.

better way to track mobs killed?

Featured Replies

I have seen the method my which you divide the total xp gained by the xp per mob, however I can see this losing accuracy over time because mobs can heal a but during an extended fight. Is there a better way to track mob deaths out there?

You can try checking if the mob you're currently fighting is doing the death animation

Edited by d0zza

Check if the NPC you are fighting has 0 health, or no longer exists. If that is the case, increment your kill counter by 1 and look for a new NPC to fight.

Edited by Explv

  • Author

I am having a slight encapsulation problem with my chicken counter. i am tracking the chicken entity within another task class so i need to track the number of killed chickens within the task class don't i? if this is the case then how would i pass the data to my Main.onPaint() function?

KillChickens.java

package tasks;

import org.osbot.rs07.api.filter.Filter;
import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.utility.ConditionalSleep;

import static org.osbot.rs07.script.MethodProvider.random;

public class KillChickens extends Task {
	private Area farm;
	public Filter<NPC> chickenFilter = new Filter<NPC>() {
		@Override
		public boolean match(final NPC entity) {
			return entity.getName().equalsIgnoreCase("chicken") &&
				   !entity.isUnderAttack() &&
				   entity.isAttackable() &&
				   farm.contains(entity);
		}
	};

	public KillChickens(Script script, Area farm) {
		super(script);
		this.farm = farm;
	}
	
	@Override
	public boolean verify() {
		return !script.myPlayer().isAnimating() && !script.myPlayer().isHitBarVisible();
	}

	@Override
	public int execute() {
		if (farm.contains(script.myPlayer())) {
			script.log("Finding chicken...");
			NPC chicken = script.getNpcs().singleFilter(script.getNpcs().getAll(), chickenFilter);
			
			if (!script.myPlayer().isAnimating() && chicken != null) {
				script.getCamera().toEntity(chicken);
				if (chicken.interact("Attack")) {
					new ConditionalSleep(5000) {
						@Override
						public boolean condition() throws InterruptedException {
							return chicken.exists() &&
								   chicken.getHealthPercent() > 0 &&
								   script.myPlayer().isInteracting(chicken);
						}
					}.sleep();
				};
			}
		} else {
			script.getWalking().webWalk(farm);
		}
		
		return random(300, 1200);
	}

	@Override
	public String describe() {
		return "Attacking Chickens.";
	}
}

Main.java

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import tasks.*;

import java.awt.*;
import java.util.ArrayList;
 
@ScriptManifest(author = "Tasemu", info = "Chicken killing script", name = "Chicken Killer", version = 1.0, logo = "")
public class Main extends Script {
	
	private long startTime;
	private ArrayList<Task> tasks = new ArrayList<>();
	private Area farm = new Area(
		    new int[][]{
		        { 3184, 3276 },
		        { 3184, 3278 },
		        { 3183, 3281 },
		        { 3179, 3288 },
		        { 3179, 3289 },
		        { 3178, 3289 },
		        { 3177, 3288 },
		        { 3175, 3288 },
		        { 3174, 3289 },
		        { 3171, 3289 },
		        { 3169, 3291 },
		        { 3169, 3295 },
		        { 3170, 3296 },
		        { 3170, 3298 },
		        { 3169, 3299 },
		        { 3169, 3300 },
		        { 3173, 3304 },
		        { 3173, 3308 },
		        { 3180, 3308 },
		        { 3180, 3304 },
		        { 3182, 3304 },
		        { 3183, 3303 },
		        { 3184, 3303 },
		        { 3186, 3301 },
		        { 3186, 3299 },
		        { 3187, 3298 },
		        { 3187, 3296 },
		        { 3186, 3295 },
		        { 3186, 3291 },
		        { 3184, 3289 },
		        { 3190, 3280 },
		        { 3192, 3280 },
		        { 3193, 3279 },
		        { 3193, 3276 },
		    }
		);
 
    @Override
    public void onStart() {
        log("Welcome to Chicken Killer!");
        log("Current version: " + getVersion());
        
        startTime = System.currentTimeMillis();
        
        getExperienceTracker().start(Skill.ATTACK);
        getExperienceTracker().start(Skill.STRENGTH);
        getExperienceTracker().start(Skill.DEFENCE);
        getExperienceTracker().start(Skill.HITPOINTS);
        getExperienceTracker().start(Skill.RANGED);
        getExperienceTracker().start(Skill.MAGIC);
        
        tasks.add(new KillChickens(this, farm));
        tasks.add(new Loot(this, farm));
    }
    
    public int getChickenCount() {
    	int xpPerChicken = 12;
    	int totalXp = getExperienceTracker().getGainedXP(Skill.ATTACK)
    				+ getExperienceTracker().getGainedXP(Skill.STRENGTH)
    				+ getExperienceTracker().getGainedXP(Skill.DEFENCE)
    				+ getExperienceTracker().getGainedXP(Skill.RANGED)
    				+ getExperienceTracker().getGainedXP(Skill.MAGIC);
    	
    	return totalXp / xpPerChicken;
    }
 
    @Override
    public int onLoop() throws InterruptedException {
    	for (Task task : tasks) {
            if (task.verify())
                return task.execute();
        }
    	
        return random(600, 1600);
    }
 
    @Override
    public void onExit() {
        log("Bye!");
    }
 
    @Override
    public void onPaint(Graphics2D g) {
    	final long runTime = System.currentTimeMillis() - startTime;
    	int xpDrawMarker = 0;
    	
    	drawMouse(g);
    	
    	g.setColor(Color.WHITE);
    	g.drawString("Chicken Killer", 10, 40);
    	g.drawString("Time running: " + formatTime(runTime), 10, 55);
    	g.drawString("Chickens Killed: " + getChickenCount(), 10, 70);
    	
    	if (getExperienceTracker().getGainedXP(Skill.ATTACK) > 0) {
    		g.drawString("ATT XP gained: " + getExperienceTracker().getGainedXP(Skill.ATTACK) + " (TTL: " + formatTime(getExperienceTracker().getTimeToLevel(Skill.ATTACK)) + ")", 10, 85 + xpDrawMarker);
    		xpDrawMarker += 15;
    	}
    	
    	if (getExperienceTracker().getGainedXP(Skill.STRENGTH) > 0) {
    		g.drawString("STR XP gained: " + getExperienceTracker().getGainedXP(Skill.STRENGTH) + " (TTL: " + formatTime(getExperienceTracker().getTimeToLevel(Skill.STRENGTH)) + ")", 10, 85 + xpDrawMarker);
    		xpDrawMarker += 15;
    	}
    	
    	if (getExperienceTracker().getGainedXP(Skill.DEFENCE) > 0) {
    		g.drawString("DEF XP gained: " + getExperienceTracker().getGainedXP(Skill.DEFENCE) + " (TTL: " + formatTime(getExperienceTracker().getTimeToLevel(Skill.DEFENCE)) + ")", 10, 85 + xpDrawMarker);
    		xpDrawMarker += 15;
    	}
    	
    	if (getExperienceTracker().getGainedXP(Skill.HITPOINTS) > 0) {
    		g.drawString("HP XP gained: " + getExperienceTracker().getGainedXP(Skill.HITPOINTS) + " (TTL: " + formatTime(getExperienceTracker().getTimeToLevel(Skill.HITPOINTS)) + ")", 10, 85 + xpDrawMarker);
    		xpDrawMarker += 15;
    	}
    	
    	if (getExperienceTracker().getGainedXP(Skill.RANGED) > 0) {
    		g.drawString("RANGED XP gained: " + getExperienceTracker().getGainedXP(Skill.RANGED) + " (TTL: " + formatTime(getExperienceTracker().getTimeToLevel(Skill.RANGED)) + ")", 10, 85 + xpDrawMarker);
    		xpDrawMarker += 15;
    	}
    	
    	if (getExperienceTracker().getGainedXP(Skill.MAGIC) > 0) {
    		g.drawString("MAGIC XP gained: " + getExperienceTracker().getGainedXP(Skill.MAGIC) + " (TTL: " + formatTime(getExperienceTracker().getTimeToLevel(Skill.MAGIC)) + ")", 10, 85 + xpDrawMarker);
    		xpDrawMarker += 15;
    	}
    	
    }
    
    public final String formatTime(final long ms){
        long s = ms / 1000, m = s / 60, h = m / 60;
        s %= 60; m %= 60; h %= 24;
        return String.format("%02d:%02d:%02d", h, m, s);
    }
    
    private void drawMouse(Graphics graphics) {
		((Graphics2D) graphics).setRenderingHints(
			new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
		Point pointer = mouse.getPosition();
		Graphics2D spinG = (Graphics2D) graphics.create();
		Graphics2D spinGRev = (Graphics2D) graphics.create();
		spinG.setColor(new Color(255, 255, 255));
		spinGRev.setColor(Color.cyan);
		spinG.rotate(System.currentTimeMillis() % 2000d / 2000d * (360d) * 2 * Math.PI / 180.0, pointer.x, pointer.y);
		spinGRev.rotate(System.currentTimeMillis() % 2000d / 2000d * (-360d) * 2 * Math.PI / 180.0, pointer.x, pointer.y);
		final int outerSize = 20;
		final int innerSize = 12;
		spinG.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
		spinGRev.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
		spinG.drawArc(pointer.x - (outerSize / 2), pointer.y - (outerSize / 2), outerSize, outerSize, 100, 75);
		spinG.drawArc(pointer.x - (outerSize / 2), pointer.y - (outerSize / 2), outerSize, outerSize, -100, 75);
		spinGRev.drawArc(pointer.x - (innerSize / 2), pointer.y - (innerSize / 2), innerSize, innerSize, 100, 75);
		spinGRev.drawArc(pointer.x - (innerSize / 2), pointer.y - (innerSize / 2), innerSize, innerSize, -100, 75);
	}
 
}

 

Declare a public integer for your kill counter in KillChickens.java called killCount (Or whatever you want to name it). You can then access it in your main with KillChickens.killCount

Edited by d0zza

What d0zza said, or preferably make it a private int with a public getter method.

Side note:

I would recommend staying away from the task system people here use. It is overcomplicated, messy and counter-intuitive. Considering you are writing a chicken killer I don't know why you wouldn't just put this all in a single class. However if you want multiple classes, there are better ways to achieve it.

Also you could remove a lot of duplicate code from your onPaint with a simple for loop.

  • Author

Cheers, this is my first script / java project. i'm more used to web dev stuff so i'm not sure on best practises yet. Cheers for the advice, i'll look into state stuff for my next script. o7

  • Author

Also if you dont mind my asking, what is wrong with splitting up the script into multiple classes, even if the script is small? Also what is wrong with the task based approach? as a developer i saw it as a nice way to split up code and have each task responsible for its own running. Are java programming patterns different?

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.