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
  • Way of checking if player is standing on Any game object


    benhowe

    Recommended Posts

    Hi, I've been working on a script for the past couple of days but something has really stumped me. How should I check if my player isn't standing ontop of a GameObject?

    I've tried using the GameObjects.closest() method. I've even read through the docs but I can't seem to find a way to check what GameObjects are in your players area &/OR checking if a game object exists on the tile you are standing on. I'm sure it's pretty straight forward 😅

    Link to comment
    Share on other sites

    6 hours ago, Pandemic said:

    You could do something like this:

    
    GameObjects.getTopObjectOnTile(Client.getLocalPlayer().getTile()));

     

    Thanks, This did work. My script now moves if there is anything on the tile, which is what I thought I wanted but didn't realise this included things like grass. I'm trying to make it so my script will fire make anywhere and prevent it getting stuck on things it can't fire make on, Any suggestions?

    Link to comment
    Share on other sites

    2 hours ago, benhowe said:

    Thanks, This did work. My script now moves if there is anything on the tile, which is what I thought I wanted but didn't realise this included things like grass. I'm trying to make it so my script will fire make anywhere and prevent it getting stuck on things it can't fire make on, Any suggestions?

    You could make exceptions for certain 'objects' in your logic. So check if the object on the tile isn't called 'X' or 'Y' before forcing the movement.

    Link to comment
    Share on other sites

    46 minutes ago, Pseudo said:

    You could make exceptions for certain 'objects' in your logic. So check if the object on the tile isn't called 'X' or 'Y' before forcing the movement.

    Yeah, I figured I could do that already. I thought it would be better if the script could just avoid all objects it couldn't fire make on rather than a predetermined list of them. If I can't figure out how to do the first option this is what I will do though

    Link to comment
    Share on other sites

    You could try this instead, it might give you what you want:

    List<GameObject> gameObjectsOnMyTile = GameObjects.all(object -> object != null && object instanceof SceneObject && object.getTile().equals(Client.getLocalPlayer().getTile()));
    
    if (gameObjectsOnMyTile.size() > 0) {
      GameObject objectOnMyTile = gameObjectsOnMyTiles.get(0);
      
      // Do something with it
    }

     

    Link to comment
    Share on other sites

    In the interest of helping someone else who might search for this answer here is my code, I'm sure it can be improved on (if anyone has any suggestions that will be good!) 

    while (Inventory.contains("Logs"))
    	{
    		Tabs.openWithMouse(Tab.INVENTORY);
    		SleepHelper.sleepUntil(Tab.INVENTORY::isOpen, SleepHelper.randomSleepLong(1000, 3000));
    		Tile tile = Client.getLocalPlayer().getTile();
    
    		if (TileHelper.canFireMake()) {
    			Item log = Inventory.get("Logs");
    			log.useOn("tinderbox");
    			LogHelper.log("Uses Log");
    			SleepHelper.randomSleep(2000,4000);
    			SleepHelper.sleepUntil(() -> Me.playerObject().getAnimation() != 733, 10000);
    				} else {
    					SleepHelper.sleepUntil(() -> Walking.walk(tile.getRandomizedTile(2)) && Me.playerObject().isStandingStill(), 7000,9000);
    						}
    				}

    The canFireMake method is located in a different class and looks like this, thanks pandemic.

    	public static boolean canFireMake() {
    		List<GameObject> gameObjectsOnMyTile = GameObjects.all(object -> object != null && object instanceof SceneObject && object.getTile().equals(Client.getLocalPlayer().getTile()));
    
    		if (gameObjectsOnMyTile.isEmpty()) {
    			return true;
    		} else {
    			return false;
    		}
    	}

     

    Link to comment
    Share on other sites

    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.