Jump to content

Example Script - For educational purposes - Simple chicken Killer


Vag

Recommended Posts

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 :)

Link to comment
Share on other sites

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
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...