Jump to content

Door help and eatting help


Trunkss

Recommended Posts

Hey guys, I'm trying To make a Thiever bot which Thieves, So far I can make the bot walk to the bank, collect food and start thieving, but once my hp gets low my bot don't eat.

 

here is my code:

		if(myPlayer().getHealth() <= 30)
			return State.EAT;

		case EAT:
			this.inventory.interact(this.inventory.getSlot("Lobster"), "Eat");
			break;

no errors, just the bot don't eat.

 

I'm also having trouble getting to check if a door is open and if it isn't getting the bot to open it

	public final static Area door_tile = new Area(3287, 3172, 3287, 3271);

			Entity door = objects.closest(door_tile, 6837);
			if (door.exists()) {
				log("Opening door.");
				door.interact("Open");
			} else {
				log("Cannot find door.");


The problem I'm having is if it sees the closed door It opens it, then hunts for nearby closed doors, opens them too then crashes once theres no more to open.

 

I've looked through a few help threads but none seem to work

 

Thanks in advance,

Sherbie

Link to comment
Share on other sites

Probably gonna need to see some more of your code. Eating is probably a question of whether you've already returned a different state before executing the health check.

 

Also be aware that getHealth returns a percentage value, not the actual hitpoints.

Edited by FrostBug
Link to comment
Share on other sites

package theiving;


import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import java.util.concurrent.TimeUnit; 

import java.awt.*;

@ScriptManifest(author = "Sherbie", info = "My first script", name = "Warrior thiever", version = 0.7, logo = "")
public class main extends Script {

	private int count = 0;
	private int failed = 0;
	public int Lobster;
	private long timeBegan = System.currentTimeMillis();
	private long timeRan;
	private int beginningXP;
	private int currentXp;
	private int xpGained;
	private int xpPerHour;
	private double nextLevelXp;
	private double xpTillNextLevel;
	private long timeTNL;
	public final static Area door_tile = new Area(3287, 3172, 3287, 3271);

	  final int[] XP_TABLE = 
		  { 
			  0, 0, 83, 174, 276, 388, 512, 650, 801, 969, 1154,
	          1358, 1584, 1833, 2107, 2411, 2746, 3115, 3523, 3973, 4470, 5018,
	          5624, 6291, 7028, 7842, 8740, 9730, 10824, 12031, 13363, 14833,
	          16456, 18247, 20224, 22406, 24815, 27473, 30408, 33648, 37224,
	          41171, 45529, 50339, 55649, 61512, 67983, 75127, 83014, 91721,
	          101333, 111945, 123660, 136594, 150872, 166636, 184040, 203254,
	          224466, 247886, 273742, 302288, 333804, 368599, 407015, 449428,
	          496254, 547953, 605032, 668051, 737627, 814445, 899257, 992895,
	          1096278, 1210421, 1336443, 1475581, 1629200, 1798808, 1986068,
	          2192818, 2421087, 2673114, 2951373, 3258594, 3597792, 3972294,
	          4385776, 4842295, 5346332, 5902831, 6517253, 7195629, 7944614,
	          8771558, 9684577, 10692629, 11805606, 13034431, 200000000 
		  };

	
    private Position[] path = {
            new Position(3290, 3174, 0),
            new Position(3293, 3178, 0),
            new Position(3288, 3181, 0),
            new Position(3281, 3180, 0),
            new Position(3276, 3175, 0),
            new Position(3274, 3170, 0),
            new Position(3270, 3166, 0),
    };
    
    private Position[] path2 = {
    		 new Position(3270, 3166, 0),
    		 new Position(3274, 3170, 0),
    		 new Position(3276, 3175, 0),
    		 new Position(3281, 3180, 0),
    		 new Position(3288, 3181, 0),
    		 new Position(3293, 3178, 0),
    		 new Position(3290, 3174, 0),
    };
	@Override
	public void onStart() {
		timeBegan = System.currentTimeMillis();
		beginningXP = skills.getExperience(Skill.THIEVING); 
		timeTNL = 0;
		log("Welcome to Simple Al-Kharid Warrior Pickpocketer");
		log("If you experience any issues while running this script please report them to me on the forums.");
		log("Enjoy the script, gain some thieving levels!.");
	}

	private enum State {
		BANK, STEAL, EAT, WAIT
	};

	private State getState() {
		if(inventory.isEmptyExcept("Coins"))
			return State.BANK;
		Entity warrior = npcs.closest("Al-Kharid warrior");
		if (warrior != null)
			return State.STEAL;
		if(myPlayer().getHealth() <= 30)
			return State.EAT;
			return State.WAIT;
	}

	@Override
	public int onLoop() throws InterruptedException {
		switch (getState()) {
		
		case BANK:
			Entity door = objects.closest(door_tile, 6837);
			if (door.exists()) {
				log("Opening door.");
				door.interact("Open");
			} else {
				log("Cannot find door.");
			localWalker.walkPath(path);
			sleep(random(400, 650));
			objects.closest("Bank booth").interact("Bank");
			sleep(random(300, 900));
			if (getBank().isOpen()) {
			    getBank().withdraw("Lobster", 10);
			} else {
			    Entity b = objects.closest("Bank booth");
			    if (b != null && b.exists())
			        b.interact("Bank");
			    sleep(random(400, 600));
			localWalker.walkPath(path2);
			}
			if (door.exists()) {
				log("Opening door.");
				door.interact("Open");
			} else
				log("Cannot find door.");
			}
			break;
			
		case STEAL:
			Entity warrior = npcs.closest("Al-Kharid warrior");
			if(myPlayer().getHeight() > 220) {
				sleep(random(5000, 7500));
				failed = +1;
			}
			if (warrior != null) {
				warrior.interact("Pickpocket");
				count = +1;
				sleep(random(300, 500));

			}
			break;
		
		case EAT:
			this.inventory.interact(this.inventory.getSlot("Lobster"), "Eat");
			break;
		
		case WAIT:
			sleep(random(200, 800));
			break;
		
		}	return random(200, 300);
	}
	
	

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

	@Override
	public void onPaint(Graphics2D g) {
		timeRan = System.currentTimeMillis() - this.timeBegan;
		currentXp = skills.getExperience(Skill.THIEVING);
		xpPerHour = (int)( xpGained / ((System.currentTimeMillis() - this.timeBegan) / 3600000.0D));
		xpGained = currentXp - beginningXP;
		xpTillNextLevel = nextLevelXp - currentXp;
		if (xpGained >= 1)
		{
		    timeTNL = (long) ((xpTillNextLevel / xpPerHour) * 3600000);
		}
		super.onPaint(g);
		g.setColor(Color.WHITE);
		g.drawString("Start XP: " + beginningXP, 5, 280);
		g.drawString("Next Level" + ft(timeTNL), 5, 290);
		g.drawString("XP Gained" + xpGained, 5, 300);
		g.setColor(Color.GREEN);
		g.drawString("Pockets Attepmted: " + count, 5, 310);
		g.drawString(ft(timeRan), 5, 320);
		g.setColor(Color.ORANGE);
		g.drawString("Failed: " + failed, 5, 330);

	}
	
	private String ft(long duration) 
	{
		String res = "";
		long days = TimeUnit.MILLISECONDS.toDays(duration);
		long hours = TimeUnit.MILLISECONDS.toHours(duration)
		- TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration));
		long minutes = TimeUnit.MILLISECONDS.toMinutes(duration)
		- TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS
		.toHours(duration));
		long seconds = TimeUnit.MILLISECONDS.toSeconds(duration)
		- TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS
		.toMinutes(duration));
		if (days == 0) {
		res = (hours + ":" + minutes + ":" + seconds);
		} else {
		res = (days + ":" + hours + ":" + minutes + ":" + seconds);
		}
		return res;
	}

} 

I'm a complete noob, so I bet it's terrible.. That's my whole code for it If you see anything that can be done better please let me know aha

Link to comment
Share on other sites

to fix your eating problem, swap these 2 around:

		if (warrior != null)
			return State.STEAL;
		if(myPlayer().getHealth() <= 30)
			return State.EAT;

->

		if(myPlayer().getHealth() <= 30)
			return State.EAT;
		if (warrior != null)
			return State.STEAL;

Your door problem is probably caused by a typo in the door_tile.

public final static Area door_tile = new Area(3287, 3172, 3287, 3271);

Are you sure it shouldn't be:

public final static Area door_tile = new Area(3287, 3172, 3287, 3171);

?

Link to comment
Share on other sites

Noob, u need the action to be the first argument and then food for 2nd argumentargument.

If u want to interact with the door you don't need the door position, just make it interact with the name of door or its Id the way to check if the door is open or closed u need to check for its orientation, or just use door handler class

Edited by itzDot
Link to comment
Share on other sites

Noob, u need the action to be the first argument and then food for 2nd argumentargument.

If u want to interact with the door you don't need the door position, just make it interact with the name of door or its Id the way to check if the door is open or closed u need to check for its orientation, or just use door handler class

 

No and no..

 

acba080b8a659ce457da784d266636b6.png

 

When interacting with a door, it's perfectly valid to do it by position, if there are other doors of same name and ID nearby. He won't get the closed doors since those have different ID.

 

___

 

The way you're doing the interaction right now is essentially fine, but it would be slightly cleaner and more efficient to use this overload

e7bfcf3fc2b254d4c10e5a6242762238.png

 

Edited by FrostBug
Link to comment
Share on other sites

No and no..

acba080b8a659ce457da784d266636b6.png

When interacting with a door, it's perfectly valid to do it by position, if there are other doors of same name and ID nearby. He won't get the closed doors since those have different ID.

___

The way you're doing the interaction right now is essentially fine, but it would be slightly cleaner and more efficient to use this overload

e7bfcf3fc2b254d4c10e5a6242762238.png

More like yes and no
Link to comment
Share on other sites

to fix your eating problem, swap these 2 around:

		if (warrior != null)
			return State.STEAL;
		if(myPlayer().getHealth() <= 30)
			return State.EAT;

->

		if(myPlayer().getHealth() <= 30)
			return State.EAT;
		if (warrior != null)
			return State.STEAL;

Your door problem is probably caused by a typo in the door_tile.

public final static Area door_tile = new Area(3287, 3172, 3287, 3271);

Are you sure it shouldn't be:

public final static Area door_tile = new Area(3287, 3172, 3287, 3171);

?

 

switched those two around, it now eats, but it now eats all my lobsters aha..

Also having the same problem with the doors, looks for closed doors, then crashes once its opened the doors

just use getSkills().getDynamic(Skill.HITPOINTS); for health. getHealth is ridiculously useless.

 

I used this beforehand but changed it cause it wasn't working, now realised its to do with my cases being the wrong way around, Thanks anyway bro :)

Noob, u need the action to be the first argument and then food for 2nd argumentargument.

If u want to interact with the door you don't need the door position, just make it interact with the name of door or its Id the way to check if the door is open or closed u need to check for its orientation, or just use door handler class

None of this made any sence to me..

Edited by sherbie
Link to comment
Share on other sites

switched those two around, it now eats, but it now eats all my lobsters aha..

Also having the same problem with the doors, looks for closed doors, then crashes once its opened the doors

 

I used this beforehand but changed it cause it wasn't working, now realised its to do with my cases being the wrong way around, Thanks anyway bro smile.png

None of this made any sence to me..

 

The reason it eats all of your food is because getHealth() isn't updated outside of combat (so your 'health' will stay the same if you eat outside of combat).

 

use something like this if you still want percentage:

public int getHealthPercent() {
    int max = getSkills().getStatic(Skill.HITPOINTS);
    int dyn = getSkills().getDynamic(Skill.HITPOINTS);
    return (100 / max) * dyn;
}

 

Also, the reason you're getting an error is because you aren't nullchecking the door.

			if (door.exists()) {
				log("Opening door.");
				door.interact("Open");
			} else {
				log("Cannot find door.");

->

			if (door != null && door.exists()) {
				log("Opening door.");
				door.interact("Open");
			} else {
				log("Cannot find door.");
  • Like 1
Link to comment
Share on other sites

 

In your code, you also expect that your door is going to have the action "Open". Now yes, you search for ID, but have something like this:

Entity door = getObjects().closest(door_tile, 6837);
if (door != null && door.exists() && door.hasAction("Open")) door.interact("Open");
 
 
 
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...