Jump to content

take far away item


breakfastyum

Recommended Posts

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

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

 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){

}
Link to comment
Share on other sites

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