The client is offline due to RuneScape update. You may see instance errors but this is due to the update and not actual instance errors. This should be resolved soon. Join our Discord for more information.

Find SceneObject interacting with/Count players trying to interact with the same SceneObject



  • Simple class.
    Allows you to query what SceneObject you're interacting with, or count players interacting with the same SceneObject as your player.
    Also has a function for getting the tile in-front of your player.

    public class InteractionHelper {
    
        public static int countPlayersOnMySceneObject(boolean animating){
            Player me = Players.getLocal();
            SceneObject myTarget = getSceneObjectLookingAt(me, animating);
            if(myTarget == null)
                return 0;
            int matched = 0;
            for(Player player : Players.getLoaded()){
                if(player == me) continue;
                if(getSceneObjectLookingAt(player, animating) == myTarget)
                    matched++;
            }
            return matched;
        }
    
        public static SceneObject getSceneObjectLookingAt(Player player, boolean animating){
            if (animating && !player.isAnimating())
                return null;
            Position fwd = GetForwardTile(player.getPosition(), player.getOrientation());
            SceneObject[] targets = SceneObjects.getAt(fwd);
            for (SceneObject target : targets) {
                if(target.getActions().length == 0 || target.getName() == null) continue;
                return target;
            }
            return null;
        }
    
        public static Position GetForwardTile(Position pos, int orientation){
            //Log.fine("Orientation: ", orientation);
            orientation = (int)(orientation / 256.0) * 256;
            switch (orientation){
                case 1024: return pos.translate(0, 1);//N
                case 1536: return pos.translate(1, 0);//E
                case 0: return pos.translate(0, -1);//S
                case 512: return pos.translate(-1, 0);//W
    
                case 1792: return pos.translate(1, -1);//SE
                case 256: return pos.translate(-1, -1);//SW
                case 768: return pos.translate(-1, 1);//NW
                case 1280: return pos.translate(1, 1);//NE
            }
            return pos.translate(0, 1);
        }
    
    }
    

 

58
Online

15.4k
Users

1.3k
Topics

18.6k
Posts