Jump to content

Interacting entity


Parameter

Recommended Posts

We'll have to do with this as long as it's not hooked, I needed this for my script and I decided to share it with you people.

 

public Entity getInteracting(final org.osbot.script.rs2.model.Character<?> character) {
        try {
            final ClassLoader loader = provider.bot.I();
            final Field field = loader.loadClass("aw").getDeclaredField("ao");
            field.setAccessible(true);
            final int index = field.getInt(character.instance) * 1850266567;
            final XClient client = provider.client.instance;
            if (index == -1) {
                return null;
            } else if (index > 32767) {
                final XPlayer[] players = client.getLocalPlayers();
                return new Player(players[index - 32768]);
            } else {
                final XNPC[] npcs = client.getLocalNpcs();
                return new NPC(npcs[index]);
            }
        } catch (final Exception e) {
            provider.log(e.getMessage());
        }
        return null;
    }

Probably self explanatory but it uses the bots classloader to load class aw (entity/character/actor) and retrieve field ao (interacting index). It then changes the modifier of this field to public. If index = -1 (no interacting entity) it returns null, if the index is higher than 32767 (the size of the npc array), the interacting entity is a player and therefor it gets the player array (obviously unmodified) and subtracts 32768 from the index to get the index in the player array. If the index is not higher than 32767 (so 32767 and lower) it'll just get the instance out of the unmodified npc array and return a new NPC.
 
Images:
 
68lqN.jpg
 
68ltq.jpg
 
68lwf.jpg
Edited by Parameter
  • Like 2
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...