Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Eat food if < 35% hp

Featured Replies

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();
            }
        }
 

Make sure the names of the item, "shrimp" and the interaction, "eat" is exactly how it's written in the game.

If that's fine, then just remove everything and put the "eat" code in the on loop and see if that works. If it does, then it should indicate that something else is the issue.

Yea the name of your food is definitely wrong, other than that it should work :)

  • 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

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.