Jump to content

Welcome to DreamBot!

Download for Free

Supercharge Your Bots

Run unlimited bots today using DreamBot's Covert Mode and
stay more protected.

Upgrade Now
Frequently Asked Questions
  • Are you not able to open the client? Make sure you have Java installed
  • 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 gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox

Interested in advertising your business? Reach out today!

Sign in to follow this  
benhowe

Way of checking if player is standing on Any game object

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 😅

Share this post


Link to post
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?

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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
}

 

Share this post


Link to post
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;
		}
	}

 

Share this post


Link to post
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.

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.

Sign in to follow this  

×
×
  • Create New...