Jump to content

VAG's Chicken Blaster - First Script Ever


Vag

Recommended Posts

Hello,

I am here to release my first OSBot Script ever. Writing this took me no more than 5 minutes. It is very basic, where I was just testing out OSBot Scripting.. This seems like something I might be doing more @Future.

 

Script has no antiban, except random idle timer after killing a monster. Did a test run with this, and it does attack the chicken.

 

Script can/must be started out @Any Chicken Spawn in RuneScape.

 

Source code

//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 = "VAGs Chicken Blaster", author = "VAG", version = 1.0, info = "Public BETA", logo = "")
public class main extends Script {
	
	@Override
	public void onStart() {
		//Defines actions during startup
		log("VAGs Chicken Blaster 1.0 - Welcome!");
		
	}
	
	@Override
	public void onExit() {
		//Executed after the script ends
		log("Thank-you for using VAGs Chicken Blaster!");
	}
	
	@Override
	public int onLoop() throws InterruptedException {
		//Script on loop
		NPC chicken = npcs.closest("Chicken");
		if(!myPlayer().isAnimating() && !myPlayer().isMoving()) {
			if(chicken != null) {
			if (chicken.isVisible()) {
				chicken.interact("Attack");
				sleep(random(300, 600));
			} else {
				camera.toEntity(chicken);
			}
		  }
		} else {
			sleep(random(300, 600));
		}
		
		return(random(100, 300)); //Random(?) Loop timer
	}
	
	@Override
	public void onPaint(Graphics2D g) {
		//Loading paint
		super.onPaint(g);
		g.setColor(Color.GREEN);
		g.drawString("VAG's Chicken Blaster ", 28, 175);
		
	}

}

Rewrote.

Edited by Finland
  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
import org.osbot.rs07.api.filter.Filter;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(info = "", name = "Chickens", logo = "", version = 1.00, author = "Foulwerp" )
public class Chickens extends Script {
    public int onLoop() {
        if (myPlayer().getInteracting() != null) {
            //This check at the start saves resources, because you don't do useless things like find new npcs while in combat
            return random(500, 1000);
        }
        NPC chicken = npcs.closest(new Filter<NPC>() {
            public boolean match(NPC npc) {
                //Multiple checks using a filter to find the best npc to attack. I guess, optimizing this to do the least
                //resource intensive checks first, leading up the the most intensive. If one of the first checks returns
                //false, you didn't waste a bunch of resources. If you check if the npc is reachable first you would waste a lot
                //of resources on an A* algorithm on a mob you may not even want to attack. This is because you are polling
                //all the mobs till one of these returns true to all checks.
                return npc.getName().equals("Chicken") && npc.getHealth() > 0 && npc.isAttackable() && map.canReach(npc);
            }
        });
        if (chicken == null) {
            //If chicken is null just return so you wait for one to spawn
            return random(500, 1000);
        }
        if (!chicken.isOnScreen() {
            //Try to get the chicken on the screen by turning to it
            camera.toEntity(chicken);
            //Returning after doing an action
            return (500, 1000)
        }
        //Attack the chicken then return net iteration should see that I'm interacting which is the first check
        chicken.interact("Attack");
        //Default return but again returned after I completed an action
        return random(500, 1000);
    }
}

I know how hard it can be to learn when you have no reference so I decided to give you one, and a few tips.

 

Once you learn how to use filters life will be a lot easier. You can use multiple checks to find the perfect npc to attack, and not just the closest one to you. Filters can be applied to not only npcs but items, ground items, etc.

 

Instead of checking if your player is moving or animating check if it is interacting with something. In most cases if it is your player is in combat.

 

Try to write your code logically so that you don't have to use sleep. If you return it's better and what you return is how long in milliseconds it waits till it enters the loop again. When your script runs through the loop you want it to do 0 to 1 action and return. So every loop iteration should either have no actions done meaning the default is returned, or do 1 action in which you return a specified amount. Not action sleep another action sleep then return.

 

In a sense returning is sleeping, but a much better way allowing the bot to do what it needs to before you enter the loop again. Randoms aren't a big deal on oldschool but returning allows the bot to check for them and do other background things, sleeping doesn't.

Edited by Foulwerp
  • Like 2
Link to comment
Share on other sites

    public int onLoop() {
        if (myPlayer().getInteracting() != null) {
            //If my player is interacting I return because there is no point in doing any more checks till I'm out of combat
            return random(500, 1000);
        }
        NPC chicken = npcs.closest(new Filter<NPC>() {
            public boolean match(NPC npc) {
                //Multiple checks using a filter to find the best npc to attack
                return npc.getName().equals("Chicken") && npc.getHealth() > 0 && npc.isAttackable() && map.canReach(npc);
            }
        });
        if (chicken == null) {
            //If chicken is null just return so you wait for one to spawn
            return random(500, 1000);
        }
        if (!chicken.isOnScreen() {
            //Try to get the chicken on the screen by turning to it, and returning after the action
            camera.toEntity(chicken);
            return (500, 1000)
        }
        //Attack the chicken then return net iteration should see that I'm interacting and not proceed
        //further than the first check saving CPU because you're not constantly doing every check in the loop
        chicken.interact("Attack");
        return random(500, 1000);
    }

I know how hard it can be to learn when you have no reference so I decided to give you one, and a few tips.

 

Once you learn how to use filters life will be a lot easier. You can use multiple checks to find the perfect npc to attack, and not just the closest one to you. Filters can be applied to not only npcs but items, ground items, etc.

 

Instead of checking if your player is moving or animating check if it is interacting with something. In most cases if it is your player is in combat.

 

Try to write your code logically so that you don't have to use sleep. If you return it's better and what you return is how long in milliseconds it waits till it enters the loop again. When your script runs through the loop you want it to do 0 to 1 action and return. So every loop iteration should either have no actions done meaning the default is returned, or do 1 action in which you return a specified amount. Not action sleep another action sleep then return.

 

In a sense returning is sleeping, but a much better way allowing the bot to do what it needs to before you enter the loop again. Randoms aren't a big deal on oldschool but returning allows the bot to check for them and do other background things, sleeping doesn't.

 

 

Thanks for that, trying to do my own chicken killer. This will come in handy!

Link to comment
Share on other sites

import org.osbot.rs07.api.filter.Filter;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(info = "", name = "Chickens", logo = "", version = 1.00, author = "Foulwerp" )
public class Chickens extends Script {
    public int onLoop() {
        if (myPlayer().getInteracting() != null) {
            //This check at the start saves resources, because you don't do useless things like find new npcs while in combat
            return random(500, 1000);
        }
        NPC chicken = npcs.closest(new Filter<NPC>() {
            public boolean match(NPC npc) {
                //Multiple checks using a filter to find the best npc to attack. I guess, optimizing this to do the least
                //resource intensive checks first, leading up the the most intensive. If one of the first checks returns
                //false, you didn't waste a bunch of resources. If you check if the npc is reachable first you would waste a lot
                //of resources on an A* algorithm on a mob you may not even want to attack. This is because you are polling
                //all the mobs till one of these returns true to all checks.
                return npc.getName().equals("Chicken") && npc.getHealth() > 0 && npc.isAttackable() && map.canReach(npc);
            }
        });
        if (chicken == null) {
            //If chicken is null just return so you wait for one to spawn
            return random(500, 1000);
        }
        if (!chicken.isOnScreen() {
            //Try to get the chicken on the screen by turning to it
            camera.toEntity(chicken);
            //Returning after doing an action
            return (500, 1000)
        }
        //Attack the chicken then return net iteration should see that I'm interacting which is the first check
        chicken.interact("Attack");
        //Default return but again returned after I completed an action
        return random(500, 1000);
    }
}

I know how hard it can be to learn when you have no reference so I decided to give you one, and a few tips.

 

Once you learn how to use filters life will be a lot easier. You can use multiple checks to find the perfect npc to attack, and not just the closest one to you. Filters can be applied to not only npcs but items, ground items, etc.

 

Instead of checking if your player is moving or animating check if it is interacting with something. In most cases if it is your player is in combat.

 

Try to write your code logically so that you don't have to use sleep. If you return it's better and what you return is how long in milliseconds it waits till it enters the loop again. When your script runs through the loop you want it to do 0 to 1 action and return. So every loop iteration should either have no actions done meaning the default is returned, or do 1 action in which you return a specified amount. Not action sleep another action sleep then return.

 

In a sense returning is sleeping, but a much better way allowing the bot to do what it needs to before you enter the loop again. Randoms aren't a big deal on oldschool but returning allows the bot to check for them and do other background things, sleeping doesn't.

 

I love you

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