Jump to content

take far away item


Recommended Posts

Posted

im using this wilderness looting script that takes items from the ground. it works pretty well except when it finds an item that is so far away or behind a hill so that the take menu is not available and it just gets stuck. how would i fix this to walk towards the item if it is too far away? or at least ignore if it cant actually be picked up.

for(int i = 0;i<P2PLoot.length;i++){
    for(GroundItem g: groundItems.getAll()){
        if(g.getName().equals(P2PLoot[i])&&g !=null){
            if(inventory.isFull()||skills.getDynamic(Skill.HITPOINTS)<=6||myPlayer().isUnderAttack()){
                break;
            }
            log("found item!"+ P2PLoot[i]);
            GroundItem a=  groundItems.closest(P2PLoot[i]);
            a.interact("Take");
            sleep(300);
            do{
                sleep(200);
            }while(myPlayer().isAnimating());

            breaker = true;
            break;
        }
    }

 

Posted

this snippet may be helpful:

public GroundItem getTokkul() {
    Filter<GroundItem> b = item -> (item.getName().contains("Tokkul") && item.getAmount() > tokkulloot && getMap().realDistance(item) < 7 );
    GroundItem tokkul = getGroundItems().closest(b);
    return tokkul;
}

I.e this only returns the tokkul is there if you could also add a getMap().canReach(item), this means if you can't reach it it won't return as true

getMap().realDistance(item) < 7

 

Posted
 if(g.getName().equals(P2PLoot[i])&&g !=null){

change to:

 if(g.getName().equals(P2PLoot[i])&&g !=null && getMap().canReach(g) && getMap().realDistance(g) < ARBITRARY NUMBER say 7){

Then if you wanted you can do if your g = null (so you prioritise looting stuff nearer to your character) walk to items further away and loot them

When sleeping - your using static sleeps: Below is a way of randomising that sleep time - just makes it a tad less botlike

try{
    sleep(random(300,600));
}
catch(Exception e){

}
Posted (edited)

You can test whether the tile is reachable, which can found here.

You should definitely separate out your logic, because you're looking for items and, whilst in the midst of doing that, are re-checking whether you're in danger. You don't/shouldn't do that. You should check whether you're in danger first then find those items:

IF IN DANGER
    GO AND RECOVER
ELSE IF FOUND ITEMS
    LOOT ITEMS
ELSE
    WAIT FOR ITEMS

I'm not going to write your entire script, but I will help you find items:

private boolean isGroundItemSomethingWeWant(GroundItem item) {
	boolean yes = false;
	String itemName = item.getName();
	for (String name : P2PLoot) {
		if (itemName.equals(name)) {
			yes = true;
			break;
		}
	}
	return yes;
}

Then you can do this:

List<GroundItem> items = groundItems.getAll().stream()
			.filter(this::isGroundItemSomethingWeWant)
			.filter(map::canReach)
			.collect(Collectors.toList());

 

Edited by liverare

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...