Jump to content

Help with my Chicken Killer


Mechagoober

Recommended Posts

I'm going off Saiyan's chicken killer, trying to customize it so it will actually run and look legit. Well, I've tried to customize it and I am not having much luck learning. So I thought I would post a topic and request some help. Remember, I'm fairly new to java and am trying not to give up. I think i'm looking how to use a Filter so it attacks the right npc.. not sure if this is the same thing as a filter or not.
Also, here is a link to Saiyan's chicken killer he posted a half year ago. http://osbot.org/forum/topic/89682-open-source-chicken-killer-can-copy-and-paste-and-improve5-min-script/

Do I need to create my own methods to start using them in if statements so for ex. I can call a method to have a conditional Sleep?

Idk how to use a filter, i think i need that to be successful.

This is what I found for a filter, i think this is the most relevant to my script but idk!!
 

Any help is appreciated!
And yes I have looked at the API, its intimidating at a glance

NPC chicken = getNpcs().closest("Chicken"); 
NPC chicken = getNpcs().closest(filters)
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;
import org.osbot.rs07.api.filter.NameFilter;
import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.GroundItem;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.model.Player;

import java.awt.*;

@ScriptManifest(author = "Kitten Krazy", info = "Adam's Chicken Killer", name = "Chicken Killer", version = 0, logo = "")
public class main extends Script {

	final Area CHICKEN_AREA = new Area(3226, 3001, 3236, 3295);

	@Override
	public void onStart() {
		log("Kitten Krazy's chicken killer");
	}

	private enum State {
		KILL, SLEEP;
	}

	private State getState() {

		NPC chicken = getNpcs().closest("Chicken");
			if(chicken != null){
				
					return State.KILL;
		}
		return State.SLEEP;

		}
	

	@Override
	public int onLoop() throws InterruptedException {
		switch (getState()) {
		case KILL:
			
		
			NPC chicken = getNpcs().closest("Chicken");
			if(!getCombat().isFighting()){ 
				if(!myPlayer().isUnderAttack()){
					if(chicken != null){
						chicken.interact("Attack");
					}
				}
			}
			
			
			
				if(chicken.interact("Attack")){
				new ConditionalSleep(3000, 500){
					public boolean condition() throws InterruptedException{
						return myPlayer().isInteracting(chicken);
					}
				}.sleep();
			}
				if(myPlayer().isInteracting(chicken)){
					new ConditionalSleep(3000, 500){
						public boolean condition() throws InterruptedException{
							return myPlayer().isInteracting(chicken);
						}
					}.sleep();
				}
					
			}
			
				
			

				
			
			
			
		return 0;
	}

	@Override
	public void onExit() {
		log("Thanks for running my chicken killer!");
	}

	@Override
	public void onPaint(Graphics2D g) {

	}

}
  • Like 1
Link to comment
Share on other sites

        NPC chicken = getNpcs().closest(new Filter<NPC>() {
            @Override
            public boolean match(NPC npc) {
                return npc != null && npc.exists() && 
                        npc.getName().equals("Chicken") && npc.isAttackable();
            }
        });
//ConditionalSleep example
            if (chicken != null){
                if (chicken.interact("Attack")){
                    new ConditionalSleep(5000) { // 5000ms timeout
                       @Override
                       public boolean condition() throws InterruptedException {
                          return myPlayer().isInteracting(chicken);
                       }
                    }.sleep();
                }
            }

Hope it helps

Edited by Christopher
Link to comment
Share on other sites

Why exactly does Filter stay having red lines under it? I copyed that exact code and it still gives red lines. Did I not import something

I appreciate your response

 

Yes you need to import

 

import org.osbot.rs07.api.filter.Filter;


Rsz02uO.gif

You could also use lambda

NPC blah = getNpcs().closest(npc -> npc.getName().equals("Cat") && //other conditions);

then interact

View this thread for some helpful information.

 

ZTp3Y57.png

Edited by Christopher
Link to comment
Share on other sites

Thank you so much,
Why doesn't Eclipse pop up and tell me I need to import the filter? All it does is show me the methods I can use with .closest

It has been fine for ground items and all the other stuff I had. Do you use intelliJ? I tried using it but it doesn't recognize something.. Eclipse should work anyways. Any idea? Thank you again!

Link to comment
Share on other sites

I use intellij so idk about eclipse. I'm off to bed now. Good luck

Thank you so much,

Why doesn't Eclipse pop up and tell me I need to import the filter? All it does is show me the methods I can use with .closest

It has been fine for ground items and all the other stuff I had. Do you use intelliJ? I tried using it but it doesn't recognize something.. Eclipse should work anyways. Any idea? Thank you again!

Link to comment
Share on other sites

Thank you so much,

Why doesn't Eclipse pop up and tell me I need to import the filter? All it does is show me the methods I can use with .closest

It has been fine for ground items and all the other stuff I had. Do you use intelliJ? I tried using it but it doesn't recognize something.. Eclipse should work anyways. Any idea? Thank you again!

Eclipse does tell to import if you hover over the red text. Ctrl+shift+o is a useful shortcut to sort out all imports, super useful.

Another useful shortcut in eclipse is ctrl+shift+f which formats your code to make it more readable.

As for the code, I'd split it up into logical steps:

 

if (not in combat)
    NPC chicken = findChicken();
    attack(chicken);
else
    Sleep or do anything you would do in combat

As for a findChicken method, something like this.

private NPC findNPC(NPC... exceptions) {
		@SuppressWarnings("unchecked")
		NPC chicken = getNpcs().closest(new Filter<NPC>() {
			@Override
			public boolean match(NPC npc) {
				return npc.getName().equals("Chicken") 
					&& !npc.isUnderAttack() && (npc.getHealthPercent() > 0)
			}
		});
		return chicken;
	}

And for attack, maybe

	private void attack(NPC chicken) throws InterruptedException {
		if (chicken != null) {
			if (map.canReach(chicken)) {
				if (chicken.isVisible()) {
					chicken.interact("Attack");
				} else {
					s.camera.toEntity(chicken);
				}
			} 
		}
	}

I think it's just a good habit overall to split your steps into methods, leads to cleaner code and makes it so you can reuse it often.

  • Like 1
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...