Jump to content

get the current object we are interacting with?


Recommended Posts

Posted
16 minutes ago, atoo said:

Smh, i was looking at that one yesterday but i didnt know if it would apply to rocks lol.

 

edit- wait will this even work for rocks?

Gets the character that this character is currently facing/interacting.

3
public abstract class Character<C extends XCharacter<?>>
extends Animable<C>
implements Entity

 

 

Entity

All Known Implementing Classes:
Character, GroundDecoration, GroundItem, InteractableObject, NPC, Player, WallDecoration, WallObject

 

public interface Entity
extends Identifiable, Interactable, Vector3D
Represents an in-game model.

 

do you even java docs bro

Posted
Just now, Chris said:

public abstract class Character<C extends XCharacter<?>>
extends Animable<C>
implements Entity

 

 

Entity

All Known Implementing Classes:
Character, GroundDecoration, GroundItem, InteractableObject, NPC, Player, WallDecoration, WallObject

 


public interface Entity
extends Identifiable, Interactable, Vector3D
Represents an in-game model.

 

do you even java docs bro

Didnt read the full page

Posted

Just a quick update:

Seems like getInteracting is broken because it always returns null no matter what my character is doing? lol

Even when mining its null.

[INFO][Bot #1][11/19 01:28:50 PM]: interacting: null
[INFO][Bot #1][11/19 01:28:50 PM]: interacting: null
[INFO][Bot #1][11/19 01:28:50 PM]: interacting: null
[INFO][Bot #1][11/19 01:28:51 PM]: interacting: null
[INFO][Bot #1][11/19 01:28:51 PM]: interacting: null
[INFO][Bot #1][11/19 01:28:51 PM]: interacting: null
[INFO][Bot #1][11/19 01:28:51 PM]: interacting: null
[INFO][Bot #1][11/19 01:28:51 PM]: interacting: null

 

Posted (edited)
3 minutes ago, atoo said:

Just a quick update:

Seems like getInteracting is broken because it always returns null no matter what my character is doing? lol

Even when mining its null.


[INFO][Bot #1][11/19 01:28:50 PM]: interacting: null
[INFO][Bot #1][11/19 01:28:50 PM]: interacting: null
[INFO][Bot #1][11/19 01:28:50 PM]: interacting: null
[INFO][Bot #1][11/19 01:28:51 PM]: interacting: null
[INFO][Bot #1][11/19 01:28:51 PM]: interacting: null
[INFO][Bot #1][11/19 01:28:51 PM]: interacting: null
[INFO][Bot #1][11/19 01:28:51 PM]: interacting: null
[INFO][Bot #1][11/19 01:28:51 PM]: interacting: null

 

Did you try it with another Entity to come to the conclusion it's broken? :boge:

Maybe try another entity and see

Edited by Viston
Posted

Character.getInteracting() only works if the other Entity is a Character, aka a Player or NPC. To detect which rock is being mined, you can get a good guess via the players rotation. Note you can be mining a rock and not be near the rock under some circumstances, so don't consider this 100% reliable.

	private RS2Object getRock(Player p) {
		Position facing = p.getPosition();
		int rotation = p.getRotation();
		
		// Determine offset
		if (rotation < 256)       facing = facing.translate( 0, -1);
		else if (rotation < 768)  facing = facing.translate(-1,  0);
		else if (rotation < 1280) facing = facing.translate( 0,  1);
		else if (rotation < 1792) facing = facing.translate( 1,  0);
		else                      facing = facing.translate( 0, -1);
		
		// Search objects at facing position for "Rocks"
		return getObjects().get(facing.getX(), facing.getY())
				.stream().filter(o -> "Rocks".equals(o.getName()))
				.findFirst().get();
	}

I haven't tested this code but should be a good start.

  • Like 1

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