Jump to content

bChickenRanger [first script]


Recommended Posts

Posted

Buitenspel's Chicken Ranger

 

Hey everybody, this is the first script that I will show to others, would love people to be harsh on me. However, be constructive in that you help me in what I did wrong and what I should change.

 

I know momentarily it is really static and only kills chicken + loots bronze arrows, but I might switch it up a bit later. I still need to start learning on how to work with a GUI and interacting with that GUI (actionListeners).

 

So here we go:

 

package bChickenRanger;

import java.awt.Graphics2D;
import org.osbot.rs07.api.model.GroundItem;
import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.api.ui.Tab;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;


@ScriptManifest(author = "Buitenspel", info = "Kills chickens with ranged", name = "bChickenRanger", version = 1.18	, logo = "")
public class main extends Script {
	

    private int chicken1 = 2693;
    private int chicken2 = 2692;
    int currentHpXp;
    int hpXpGained;
    int beginningHpXp;
    int currentRangeXp;
    int rangeXpGained;
    int beginningRangeXp;
     
   	@Override
	public void onStart() {
		this.log("Welcome to the chicken slayer");
		beginningHpXp = (skills.getExperience(Skill.HITPOINTS));
		beginningRangeXp = (skills.getExperience(Skill.RANGED));
		this.log("Your starting HP Xp = " + beginningHpXp);
		this.log("Your starting Ranged Xp = " + beginningRangeXp);
	}

	private enum State {
		KILL, KILLING, LOOT, EQUIP, DROP, IDLE, ANTIBAN, CHECKWILLOW;
	};

	private State getState() {
		NPC chicken = npcs.closest(chicken1, chicken2);
//		GroundItem feather = groundItems.closest("Feather");
		GroundItem bronzeArrow = groundItems.closest("Bronze arrow");
		Item bones = inventory.getItem("Bones");
		Item rawChicken = inventory.getItem("Raw chicken");
		long bronzeArrowAmount = inventory.getAmount(882);
		
		if (random(1,20) == 1) {
			return State.ANTIBAN;
		} else if (!myPlayer().isUnderAttack() && !myPlayer().isMoving() && myPlayer().getInteracting() == null && bronzeArrowAmount >= random(10,30)) {
			return State.EQUIP;
		} else if (!myPlayer().isAnimating() && myPlayer().getInteracting() == null && !myPlayer().isMoving() && chicken != null && bronzeArrow == null) {
			return State.KILL;
		} else if (myPlayer().isAnimating() && myPlayer().getInteracting() != null){
			return State.KILLING;			
		} else if (!myPlayer().isUnderAttack() && !myPlayer().isMoving() && bronzeArrow != null && myPlayer().getInteracting() == null) {
			return State.LOOT;
		} else if (!myPlayer().isUnderAttack() && !myPlayer().isMoving() && myPlayer().getInteracting() == null && (bones != null || rawChicken != null)) {
			return State.DROP;
		}		
		return State.IDLE;
	}
	
    public void kill() throws InterruptedException {
    	NPC chicken = npcs.closest(chicken1, chicken2);
    	if( !myPlayer().isMoving() && !myPlayer().isUnderAttack() && !inventory.isFull()) {
    		if(chicken != null && chicken.isAttackable() && chicken.isOnScreen()) {
    			chicken.interact("Attack");
    			sleep(random(1682, 2098));
    		} else {
    			camera.toEntity(chicken);
    		}
    	} else {
    		sleep(random(891,1032));
    	}
    	this.log("State: Kill");
    	sleep(random(1200,1500));
    }
    
    public void killing() throws InterruptedException {
    	if(!myPlayer().isMoving() && myPlayer().isUnderAttack() && mouse.isOnScreen()) {
    		mouse.moveRandomly();
    		mouse.moveOutsideScreen();
    		sleep(random(1400,1900));
    	} else {
    		sleep(1700);
    	}
    	this.log("State: Killing");
    }
    
    public void loot() throws InterruptedException {
    	GroundItem groundItem = groundItems.closest("Bronze arrow");
    	if(!myPlayer().isMoving() && !myPlayer().isUnderAttack() && !myPlayer().isAnimating()) {
        	if(groundItem != null && map.canReach(groundItem)) {
        		if(!groundItem.isOnScreen()) {
        			camera.toEntity(groundItem);
        			if(!groundItem.isOnScreen()) {
        				getLocalWalker().walk(groundItem);
        			}
        		}
        		groundItem.interact("Take");
        		sleep(random(200,300));
               	}        	
    	}    	
    	this.log("State: Loot");
    }
    
       
    
    public void idle() throws InterruptedException {
    	NPC chicken = npcs.closest(chicken1, chicken2);
    	if(chicken == null && !myPlayer().isUnderAttack() && !myPlayer().isMoving()) {
    		camera.toEntity(chicken);
    		if(chicken == null) {
    			getLocalWalker().walk(chicken);
    		}
    	}
    	this.log("State: idle");
    	sleep(random(500,1200));
    }
    
    public void drop() throws InterruptedException {
    	Item bones = inventory.getItem("Bones");
		Item rawChicken = inventory.getItem("Raw chicken");
		this.getTabs().open(Tab.INVENTORY);
		if (bones != null) {
			inventory.drop("Bones");
		}
		if (rawChicken != null) {
			inventory.drop("Raw chicken");
		} else {
			sleep(random(300,600));
		}
		this.log("State: Drop");
    }
    
    public void equip() throws InterruptedException {
    	Item bronzeArrow = inventory.getItem("Bronze arrow");
    	this.getTabs().open(Tab.INVENTORY);
    	if (bronzeArrow != null) {
    		bronzeArrow.interact("Wield");
    	}
    	this.log("State: Equip");
    }
    
    public void antiBan() throws InterruptedException {
        if (random(0, 10) == 1) {
            switch (random(0, 6)) {
                case 0:
                    this.camera.movePitch(gRandom(20, 60));
                    this.log("Antiban: 0");
                    break;
                case 1:
                    this.getTabs().getSkills().open();
                    this.getSkills().hoverSkill(Skill.RANGED);
                    this.log("Antiban: 1");
                    sleep(random(1111, 2777));
                    break;
                case 2:
                    this.camera.moveYaw(110 + random(25, 80));
                    this.log("Antiban: 2");
                    break;
                case 3:
                    this.camera.moveYaw(random(1, 359));
                    this.log("Antiban: 3");
                    break;
                case 4:
                    this.getMouse().moveRandomly();
                    sleep(random(3333, 5473));
                    this.log("Antiban: 4");
                    break;
                case 5:
                    this.mouse.moveRandomly();
                    this.log("Antiban: 5");
                    break;
                case 6:
                    this.log("Antiban: 6");
                    switch (random(1, 7)) {
                        case 1:
                            this.getTabs().open(Tab.ATTACK);
                            break;
                        case 2:
                            this.getTabs().open(Tab.QUEST);
                            break;
                        case 3:
                            this.getTabs().open(Tab.EQUIPMENT);
                            break;
                        case 4:
                            this.getTabs().open(Tab.PRAYER);
                            break;
                        case 5:
                            this.getTabs().open(Tab.MAGIC);
                            break;
                        case 6:
                            this.getTabs().open(Tab.FRIENDS);
                            break;
                        case 7:
                            this.getTabs().open(Tab.SETTINGS);
                            break;

                    }
                    sleep(random(2377, 4556));
            }
            sleep(random(186, 987));
            this.getTabs().open(Tab.INVENTORY);
         }
    }

	@Override
	public int onLoop() throws InterruptedException {
		switch (getState()) {
		case DROP:
			this.drop();
			break;
		case EQUIP:
			this.equip();
			break;
		case IDLE:
			this.idle();
			break;
		case KILL:
			this.kill();			
			break;
		case KILLING:
			this.killing();
			this.antiBan();
			break;
		case LOOT:
			this.loot();
			break;
		case ANTIBAN:
			this.antiBan();
			break;
		default:
			break;
		}
		return random(200, 300);

	}

	@Override
	public void onExit() {
		currentRangeXp = skills.getExperience(Skill.RANGED);
		currentHpXp = skills.getExperience(Skill.HITPOINTS);
		hpXpGained = currentHpXp - beginningHpXp;
		rangeXpGained = currentRangeXp - beginningRangeXp;
		log("Thanks for running the bChickenRanger!");
		log("You gained a total of: " + rangeXpGained + " Ranged experience");
		log("You gained a total of: " + hpXpGained + " Ranged experience");
	}

	@Override
	public void onPaint(Graphics2D g) {
		
	}

}
  • Like 1
Posted (edited)

Cool script smile.png However I do not suggest you use ids for the chickens as you have.

 

Perhaps instead do

 

NPC Chicken = npcs.closest("Chicken"); 

 

or similar with your custom filters

 

Apa

 

Thank you for the feedback.

 

Currently it keeps on returning the state: loot, I don't know what happened. But apparently it can't find the chickens anymore now I changed it..

Edited by Buitenspel
Posted

Looks good, as apaec also told you; you should work with name filters, this doesn't require you to update the ids if they change after a update. Also; such an antiban system is actually more likely to get you banned, if a person keeps doing the same things, jagex will find its pattern. So imo you should delete that antiban.

Apartstanding from those, nice first script (:

Posted

Looks good, as apaec also told you; you should work with name filters, this doesn't require you to update the ids if they change after a update. Also; such an antiban system is actually more likely to get you banned, if a person keeps doing the same things, jagex will find its pattern. So imo you should delete that antiban.

Apartstanding from those, nice first script (:

 

So would you say that the OSBot general antiban is enough to prevent the player from getting banned.

 

Or do you use another form of antiban?

Ya you have a short antiban distance. You'll have a higher possibility to high it more often since it's short. Plus you are always calling they method using the get state. maybe us a timer?

 

So, you mean that in the onloop I should add a time element for antiban rather than using the state method?

Posted

The antiban system that osb has will get either removed or improved. Devs still deciding on it. Ask for what you said if you want to use your own antiban that's fine too. Just don't leave it in on state method. I'd rather you use a timer. Which you do add to the on loop.

All I'm saying it if you call your antiban alot it will be repetitive and it wont be any good of an antiban.

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