Jump to content

Eat food if < 35% hp


jajaXd

Recommended Posts

I can't get the script to eat food. Any help? 😛

 

public int onLoop() throws InterruptedException {
                
                if (myPlayer().getHealthPercent() < 35) {
                    eatFood();
                    sleep(random(500, 1000));
                }

            return 0;
        }

 

public void eatFood() throws InterruptedException {
            if (getInventory().contains("Shrimps")) {            
            
            getInventory().getItem("Shrimps").interact("Eat");
                
            }
            else {
                goBank();
                sleep(random(1000, 2000));
                goMonsterLoc();
            }
        }
 

Link to comment
Share on other sites

  • 2 weeks later...
On 7/19/2019 at 9:54 AM, jajaXd said:

I can't get the script to eat food. Any help? 😛

 

public int onLoop() throws InterruptedException {
                
                if (myPlayer().getHealthPercent() < 35) {
                    eatFood();
                    sleep(random(500, 1000));
                }

            return 0;
        }

 

public void eatFood() throws InterruptedException {
            if (getInventory().contains("Shrimps")) {            
            
            getInventory().getItem("Shrimps").interact("Eat");
                
            }
            else {
                goBank();
                sleep(random(1000, 2000));
                goMonsterLoc();
            }
        }
 


your timer seems a bit silly because eating takes 3 ticks. you're more than welcome to do random (1800, 2400), but random doesn't really matter much anyways
here's two ways you can go about it, but it's virtually the exact same code just done differently. untested, but it should work
you're also better off checking if your player is in an Area instead of checking if the bank booth is null. or you can use map.distance and a null check

as for everyone else, it is infact "Shrimps" in-game. it doesn't take much effort to check it out on the wikia for the correct name, instead of telling op he got it wrong

	Position VarrockWestBank = new Position(3184, 3436, 0);

	int health;

	boolean invHas(String item) { return inventory.contains(item); }
	boolean eat(String name) { return inventory.interact("Eat", name); }
	boolean objExists(String obj) { return objects.closest(obj) != null; }

	String booth = "Bank booth", food = "Shrimps";

	public int onLoop() throws InterruptedException {
		health = myPlayer().getHealthPercent();
		
		if (health <= 35 && invHas(food)) {
			eat(food);
			sleep(1800);
		} else if (health <= 50 && !invHas(food) && !objExists(booth)) {
			walking.webWalk(VarrockWestBank);
		}
		return 200;
	}
	Position VarrockWestBank = new Position(3184, 3436, 0);

	public int onLoop() throws InterruptedException {
		if (myPlayer().getHealthPercent() <= 35 && inventory.contains("Shrimps")) {
			inventory.interact("Eat", "Shrimps");
			sleep(1800);
		} else if (myPlayer().getHealthPercent() <= 50 && !inventory.contains("Shrimps") && objects.closest("Bank booth") == null) {
			walking.webWalk(VarrockWestBank);
		}
		return 200;
	}

 

edit: you can also choose to not declare certain positions like I did, and you can simple do - walking.webWalk(Banks.VARROCK_WEST);

Edited by qmqz
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...