Jump to content

Example Script - For educational purposes - Simple chicken Killer


Recommended Posts

Posted

This is a educational release for a simple chicken killing script. The script will attack the monster (chicken). This will not eat or loot, just a basic bare bone for chicken killer.

//OSBot API
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

//Importing Java AWT
import java.awt.*;

//Script Details
@ScriptManifest(name = "Chicken Killer", author = "YOU!!", version = 1.0, info = "", logo = "")
public class main extends Script {
	
	@Override
	public void onStart() {
		log("Welcome - your first script!");
		
	}
	
	@Override
	public void onExit() {
		log("K Bye");
	}
	
	@Override
	public int onLoop() throws InterruptedException {
		//Script on loop
		NPC chicken = npcs.closest("Chicken");
 //Looking for non-player character chicken, which will be the closest NPC called chicken
		if(!myPlayer().isAnimating() && !myPlayer().isMoving()) {
			if(chicken != null) {
			if (chicken.isVisible()) {
				chicken.interact("Attack");
				sleep(random(300, 600));
//If chicken is available on the screen, we will perform interaction Attack on it.
			} else {
				camera.toEntity(chicken);
//Moving camera so that the chicken will be visible on the screen.
			}
		  }
		} else {
			sleep(random(300, 600));
//Sleeping for with devitation
		}
		
		return(random(100, 300));
//Starting the script over after random sleep in milliseconds.
	}
	
	@Override
	public void onPaint(Graphics2D g) {
		//Loading paint
		super.onPaint(g);
		g.setColor(Color.GREEN);
		g.drawString("Uncle Dolan had a chikun ", 5, 290);
//Text color is GREEN - printing a line in the client saying Uncle Dolan had a chikun
		
	}

}

K bye :)

Posted (edited)

You should probably use some sort of event-node state system as it's much more modular, manageable, and it just looks better. Not trying to be a dick or anything, but especially for new scripters that aren't familiar with Java it's better to show them the best way of doing things so they learn and get comfortable with it from early on.

Edited by lare96

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...