Jump to content

Struggling to collect item! Help!


marceluxd

Recommended Posts

This script is supposed to kill the closest Chaos druid that is not fighting and collect the drops. The problem is that it just clicks on the drop and very shortly after it tries to attack another druid, i mean, it cancels the collecting action and start to attack. Please help!

Obs: Is it possible to use the glory amulet teleport to edgeville?

@ScriptManifest(author = "Marcelo", info = "Kill druids and collect herbs", name = "DruidMassacre", version = 0, logo = "")
public class DruidKiller extends Script {

	@Override
	public void onStart() {
		log("Let's get started!");
	}
	private enum State{
		ATTACK, COLLECT, TELEPORT, EAT, NOTHING;
	}
	
	private State getState() {
		GroundItem weed = getGroundItems().closest("Loop half of key", "Tooth half of key", "Rune spear","Dragon spear", "Shield left half", "Ensouled chaos druid head", "Grimy ranarr weed", "Grimy lantadyme", "Grimy dwarf weed", "Grimy cadantine", "Grimy avantoe", "Grimy kwuarm");	
		NPC druid = getNpcs().closest(npc -> npc.getName().startsWith("Chaos druid") && npc.isAttackable());

		if(myPlayer().getHealthPercent() <= 70) {
			if (getInventory().contains("Swordfish")){
				return State.EAT;
			}
			else {
				return State.TELEPORT;
			}
		}
		
		if(weed != null) {
			return State.COLLECT;
		}
		
		if(!getCombat().isFighting() && myPlayer().isAttackable() && !myPlayer().isAnimating() && !myPlayer().isMoving() && druid != null) {
			return State.ATTACK;
		}

		return State.NOTHING;
	}
	@Override
	public int onLoop() throws InterruptedException {
		GroundItem weed = getGroundItems().closest("Nature rune", "Loop half of key", "Tooth half of key", "Rune spear","Dragon spear", "Shield left half", "Ensouled chaos druid head", "Grimy ranarr weed", "Grimy lantadyme", "Grimy dwarf weed", "Grimy cadantine", "Grimy avantoe", "Grimy kwuarm");	
		NPC druid = getNpcs().closest(npc -> npc.getName().startsWith("Chaos druid") && npc.isAttackable());
	
		switch(getState()) {
		case EAT:
			log("Eat");
			getInventory().interact("Eat", "Swordfish");
		
		case TELEPORT:
			log("Teleport!");
		
		case COLLECT:
			log("Collecting weed");
			if(!myPlayer().isMoving() && !myPlayer().isAnimating()) {
				weed.interact("Take");
			}
		
		case ATTACK:
			log("Attacking");
			druid.interact("Attack");
			sleep(random(1497, 4923));
		
		case NOTHING:
			log("Nothing");
		}
		
		return random(300, 700);
	}

	@Override
	public void onExit() {
		log("terminou porra");
	}

	@Override
	public void onPaint(Graphics2D g) {

	}

}

 

Link to comment
Share on other sites

9 hours ago, Malcolm said:
9 hours ago, Malcolm said:

You're supposed to break; in your switch statements so that would be why for that.

 

A couple things I want to point out though,

First thing is that imo you're creating your local variables a lot earlier than you need to be. Also for the weed imo you should declare what the loot is.



    private final String[] loot = { "Loop half of key", "Tooth half of key", "Rune spear", "Dragon spear", "Shield left half", "Ensouled chaos druid head", "Grimy ranarr weed", "Grimy lantadyme", "Grimy dwarf weed", "Grimy cadantine",
            "Grimy avantoe", "Grimy kwuarm" };

 

 

 

Thanks for the reply. Where should i declare the variable loot?

Edited by marceluxd
Link to comment
Share on other sites

On 3/31/2020 at 10:23 AM, marceluxd said:

Thanks for the reply. Where should i declare the variable loot?

You would declare that variable in the class. Outside of any method body. So that the entire class will be able to use it.

You could also declare it static and will be able to use it throughout all your classes.

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