Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Getting the closest NPC doesn't work right


    ModAssh

    Recommended Posts

    Posted

    Here's my code

    NPC spot = getNpcs().closest("Fishing spot");
    	
    	if(failSafe && System.currentTimeMillis() - lastClick > 700)
    	{
    		spot.interact("Use-rod");
    		failSafe = false;
    		sleep((int) (500 + (Math.random()*1000)));
    	}
    	
    	if(SouthSpot.contains(getLocalPlayer())) {
    		sleep((int) (800 + Math.random()*1000));
    		if(!SouthSpot.contains(spot.getTile())) {
    		if(MiddleSpot.contains(spot.getTile())) {
    			getWalking().clickTileOnMinimap(tileNearSpot(spot.getTile()).getRandomTile());
    			lastClick = System.currentTimeMillis();
    			running = true;
    			return;
    		}
    		if(NWSpot.contains(spot.getTile())) {
    			sleep((int) (800 + Math.random()*1000));
    			getWalking().clickTileOnMinimap(MiddleBarb.getRandomTile());
    			sleep((int) (2000 + Math.random()*200));
    			getWalking().clickTileOnMinimap(tileNearSpot(spot.getTile()).getRandomTile());
    			lastClick = System.currentTimeMillis();
    			running = true;
    			return;
    		}
    		}
    	}

    Sometimes this will move me from an area (ie SouthSpot, MiddleSpot, or NW Spot) even if there are other fishing spots in that area to one significantly further away. (Particularly running me about 10 tiles to the south to start fishing at the southern area)

    Sort of bamboozled by it :(

    Posted

    Have you logged the tile of the fishing spot to double check it's finding that, and not just walking to a different spot?

    Posted

    Yes, my method pulls the closest fishing spot npc at the top of the method to train fishing. The tile from this spot is passed into the check for if the tile is in the area I'm in. It doesn't run to a new area without recognizing that the 'closest' available tile is in that area. For some reason it seems to prefer spots to the south when other spots are closer.

    Posted

    This is why I suggest using the all() method with Filter<NPC> and just sort by distance to the player, if it can be reached, is in combat and so on. I was working on a script for combat a few weeks ago and noticed that using closest() actually is broken in some forms because it targeted NPCs that were far away and were in combat and whatnot, and ideally did not pick the "closest" NPC.

    Posted

    How are you sorting by distance and what kind of delay does it add?

     

    EDIT : Nevermind, I figured it out thanks :)

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.