Resource Old School Emote Player

Discussion in 'Tutorials & Resources' started by sothatsit, Apr 7, 2015.

  1. Hey, this is a simple class i made to allow you to play emotes in old school.

    Code (Text):
    1. import com.runemate.game.api.hybrid.input.Mouse;
    2. import com.runemate.game.api.hybrid.local.hud.InteractableRectangle;
    3. import com.runemate.game.api.hybrid.local.hud.interfaces.InterfaceComponent;
    4. import com.runemate.game.api.hybrid.local.hud.interfaces.Interfaces;
    5. import com.runemate.game.api.hybrid.util.Filter;
    6. import com.runemate.game.api.hybrid.util.calculations.Random;
    7.  
    8. import java.util.List;
    9.  
    10. public class Emotes {
    11.  
    12.     public enum Emote {
    13.         YES,
    14.         NO,
    15.         BOW,
    16.         ANGRY,
    17.         THINK,
    18.         WAVE,
    19.         SHRUG,
    20.         CHEER,
    21.         BECKON,
    22.         LAUGH,
    23.         JUMP_FOR_JOY,
    24.         YAWN,
    25.         DANCE,
    26.         JIG,
    27.         SPIN,
    28.         HEADBANG,
    29.         CRY,
    30.         BLOW_KISS,
    31.         PANIC,
    32.         RASPBERRY,
    33.         CLAP,
    34.         SALUTE,
    35.         GOBLIN_BOW,
    36.         GOBLIN_SALUTE,
    37.         GLASS_BOX,
    38.         CLIMB_ROPE,
    39.         LEAN,
    40.         GLASS_WALL,
    41.         IDEA,
    42.         STAMP,
    43.         FLAP,
    44.         SLAP_HEAD,
    45.         ZOMBIE_WALK,
    46.         ZOMBIE_DANCE,
    47.         SCARED,
    48.         RABBIT_HOP,
    49.         ZOMBIE_HAND,
    50.         SKILL_CAPE;
    51.  
    52.         public String getAction() {
    53.             return name().toLowerCase().replace('_', ' ');
    54.         }
    55.     }
    56.  
    57.     public static class EmoteFilter extends Filter<InterfaceComponent> {
    58.  
    59.         private Emote emote;
    60.  
    61.         public EmoteFilter(Emote emote) {
    62.             this.emote = emote;
    63.         }
    64.  
    65.         @Override
    66.         public boolean accepts(InterfaceComponent interfaceComponent) {
    67.             for(String action : interfaceComponent.getActions()) {
    68.                 if(action.equalsIgnoreCase(emote.getAction())) {
    69.                     return true;
    70.                 }
    71.             }
    72.             return false;
    73.         }
    74.     }
    75.  
    76.     public static boolean isEmotesTabOpen() {
    77.         InterfaceComponent tab = getEmotesTabComponent();
    78.  
    79.         if(tab == null) {
    80.             return false;
    81.         }
    82.  
    83.         return tab.getTextureId() >= 0;
    84.     }
    85.  
    86.     public static void openEmotesTab() {
    87.         InterfaceComponent tab = getEmotesTabComponent();
    88.  
    89.         if(tab == null) {
    90.             return;
    91.         }
    92.  
    93.         tab.interact("Emotes");
    94.     }
    95.  
    96.     public static InterfaceComponent getEmotesTabComponent() {
    97.         return Interfaces.newQuery().actions("Emotes").visible().results().first();
    98.     }
    99.  
    100.     public static InterfaceComponent getEmotesInventoryComponent() {
    101.         return Interfaces.getAt(216, 1);
    102.     }
    103.  
    104.     public static InterfaceComponent getEmoteComponent(Emote emote) {
    105.         InterfaceComponent emotesInv = getEmotesInventoryComponent();
    106.  
    107.         if(emotesInv == null || !emotesInv.isValid()) {
    108.             return null;
    109.         }
    110.  
    111.         List<InterfaceComponent> emotes = emotesInv.getComponents(new EmoteFilter(emote));
    112.  
    113.         if(emotes.size() <= 0) {
    114.             return null;
    115.         }
    116.  
    117.         InterfaceComponent emoteComponent = emotes.get(0);
    118.  
    119.         return emoteComponent;
    120.     }
    121.  
    122.     public static float getEmoteScroll(Emote emote) {
    123.         return getEmoteScroll(getEmoteComponent(emote));
    124.     }
    125.  
    126.     public static float getEmoteScroll(InterfaceComponent emoteComponent) {
    127.         if(emoteComponent == null) {
    128.             return -1f;
    129.         }
    130.  
    131.         InterfaceComponent inventory = getEmotesInventoryComponent();
    132.  
    133.         if(inventory == null) {
    134.             return -1f;
    135.         }
    136.  
    137.         int minY = Integer.MAX_VALUE;
    138.         int maxY = Integer.MIN_VALUE;
    139.  
    140.         for(InterfaceComponent comp : inventory.getComponents()) {
    141.             InteractableRectangle bounds = comp.getBounds();
    142.  
    143.             if(bounds.y < minY) {
    144.                 minY = bounds.y;
    145.             }
    146.  
    147.             if(bounds.y > maxY) {
    148.                 maxY = bounds.y;
    149.             }
    150.         }
    151.  
    152.         int y = emoteComponent.getBounds().y - minY;
    153.  
    154.         return (float) y / (float) (maxY - minY);
    155.     }
    156.  
    157. public static boolean isEmoteVisible(Emote emote) {
    158.     return isEmoteVisisble(getEmoteComponent(emote));
    159. }
    160.  
    161.     public static boolean isEmoteVisisble(InterfaceComponent emoteComponent) {
    162.         if(emoteComponent == null) {
    163.             return false;
    164.         }
    165.  
    166.         InterfaceComponent inventory = getEmotesInventoryComponent();
    167.  
    168.         if(inventory == null) {
    169.             return false;
    170.         }
    171.  
    172.         InteractableRectangle inv = inventory.getBounds();
    173.         InteractableRectangle emote = emoteComponent.getBounds();
    174.  
    175.         return emote.y >= inv.y - 5 && emote.y + emote.height <= inv.y + inv.height + 5;
    176.     }
    177.  
    178.     public static float getScroll() {
    179.         InterfaceComponent scrollBox = Interfaces.getAt(216, 2, 0);
    180.         InterfaceComponent scrollBar = Interfaces.getAt(216, 2, 1);
    181.  
    182.         int maxScroll = scrollBox.getHeight() - scrollBar.getHeight();
    183.         int scroll = scrollBar.getBounds().y - scrollBox.getBounds().y;
    184.  
    185.         return (float) scroll / (float) maxScroll;
    186.     }
    187.  
    188.     public static void scrollTo(Emote emote) {
    189.         scrollTo(getEmoteScroll(emote));
    190.     }
    191.  
    192.     public static void scrollTo(InterfaceComponent emotesComponent) {
    193.         scrollTo(getEmoteScroll(emotesComponent));
    194.     }
    195.  
    196.     public static void scrollTo(float scroll) {
    197.         InterfaceComponent scrollBox = Interfaces.getAt(216, 2, 0);
    198.         InterfaceComponent scrollBar = Interfaces.getAt(216, 2, 1);
    199.  
    200.         int maxScroll = scrollBox.getHeight() - scrollBar.getHeight();
    201.  
    202.         int fromY = scrollBar.getBounds().y - scrollBox.getBounds().y;
    203.         int toY = (int) (scroll * maxScroll);
    204.  
    205.         int difY = toY - fromY;
    206.         difY = Random.nextInt(difY - 5, difY + 5);
    207.  
    208.         int difX = Random.nextInt(-5, 5);
    209.  
    210.         Mouse.move(scrollBar);
    211.  
    212.         Mouse.press(Mouse.Button.LEFT);
    213.  
    214.         int x = Mouse.getPosition().x + difX - 5;
    215.         int y = Mouse.getPosition().y + difY - 5;
    216.         int width = 11;
    217.         int height = 11;
    218.  
    219.         InteractableRectangle rect = new InteractableRectangle(x, y, width, height);
    220.  
    221.         Mouse.move(rect);
    222.  
    223.         Mouse.release(Mouse.Button.LEFT);
    224.     }
    225.  
    226.     public static void runEmote(Emote emote) {
    227.         if(!isEmotesTabOpen()) {
    228.             openEmotesTab();
    229.  
    230.             if(!isEmotesTabOpen()) {
    231.                 return;
    232.             }
    233.         }
    234.  
    235.         if(!isEmoteVisible(emote)) {
    236.             scrollTo(emote);
    237.  
    238.             if(!isEmoteVisible(emote)) {
    239.                 return;
    240.             }
    241.         }
    242.  
    243.         InterfaceComponent component = getEmoteComponent(emote);
    244.  
    245.         if(component != null) {
    246.             component.click();
    247.         }
    248.     }
    249.  
    250. }

    To use it all you have to do is something like:

    Code (Text):
    1. if(Players.getLocal().getAnimationId() <= -1) {
    2.     Emotes.runEmote(Emotes.Emote.BLOW_KISS);
    3. }

    This will run the blow kiss animation if your not already running an animation.
    Note: the animation doesn't have to be an emote, any animation will cause you to not run the emote

    You do not have to worry about opening the emotes tab or scrolling to the emote, this will do it for you :).

    Enjoy!
     
    #1 sothatsit, Apr 7, 2015
    Last edited: Apr 7, 2015
    EvilCabbage likes this.
  2. @Cloud consider API addition.
     
  3. Made a smallified version for you:

    Code (Text):
    1. import com.runemate.game.api.hybrid.input.Mouse;
    2. import com.runemate.game.api.hybrid.local.hud.InteractableRectangle;
    3. import com.runemate.game.api.hybrid.local.hud.interfaces.InterfaceComponent;
    4. import com.runemate.game.api.hybrid.local.hud.interfaces.Interfaces;
    5. import com.runemate.game.api.hybrid.util.Filter;
    6. import com.runemate.game.api.hybrid.util.calculations.Random;
    7.  
    8. public class Emotes {
    9.  
    10.     public enum Emote {
    11.         YES, NO, BOW, ANGRY,
    12.         THINK, WAVE, SHRUG, CHEER,
    13.         BECKON, LAUGH, JUMP_FOR_JOY, YAWN,
    14.         DANCE, JIG, SPIN, HEADBANG,
    15.         CRY, BLOW_KISS, PANIC, RASPBERRY,
    16.         CLAP, SALUTE, GOBLIN_BOW, GOBLIN_SALUTE,
    17.         GLASS_BOX, CLIMB_ROPE, LEAN, GLASS_WALL,
    18.         IDEA, STAMP, FLAP, SLAP_HEAD,
    19.         ZOMBIE_WALK, ZOMBIE_DANCE, SCARED, RABBIT_HOP,
    20.         ZOMBIE_HAND, SKILL_CAPE
    21.     }
    22.  
    23.     public static class EmoteFilter extends Filter<InterfaceComponent> {
    24.  
    25.         private Emote emote;
    26.  
    27.         public EmoteFilter(Emote emote) {
    28.             this.emote = emote;
    29.         }
    30.  
    31.         @Override
    32.         public boolean accepts(InterfaceComponent interfaceComponent) {
    33.             return interfaceComponent.getActions().stream().anyMatch(action -> action.equalsIgnoreCase(emote.name().replace('_', ' ')));
    34.         }
    35.     }
    36.  
    37.     public static boolean isEmotesTabOpen() {
    38.         InterfaceComponent tab = getEmotesTabComponent();
    39.         return tab != null && tab.getTextureId() >= 0;
    40.     }
    41.  
    42.     public static boolean openEmotesTab() {
    43.         InterfaceComponent tab = getEmotesTabComponent();
    44.         return tab != null && tab.isValid() && ((tab.getTextureId() < 0 && tab.interact("Emotes")) || tab.getTextureId() >= 0);
    45.     }
    46.  
    47.     public static InterfaceComponent getEmotesTabComponent() {
    48.         return Interfaces.newQuery().actions("Emotes").visible().results().first();
    49.     }
    50.  
    51.     public static InterfaceComponent getEmotesInventoryComponent() {
    52.         return Interfaces.getAt(216, 1);
    53.     }
    54.  
    55.     public static InterfaceComponent getEmoteComponent(Emote emote) {
    56.         InterfaceComponent emotesInv, emotes;
    57.         return ((emotesInv = getEmotesInventoryComponent()) == null || !emotesInv.isValid() ? null : emotesInv.getComponents(new EmoteFilter(emote)).stream().findFirst().get());
    58.     }
    59.  
    60.     public static float getEmoteScroll(Emote emote) {
    61.         return getEmoteScroll(getEmoteComponent(emote));
    62.     }
    63.  
    64.     public static float getEmoteScroll(InterfaceComponent emoteComponent) {
    65.         InterfaceComponent inventory = getEmotesInventoryComponent();
    66.         int minY = (inventory == null || !inventory.isValid() ? -1 : inventory.getComponents().stream().mapToInt(comp -> comp.getBounds().y).min().getAsInt());
    67.         int maxY = (inventory == null || !inventory.isValid() ? -1 : inventory.getComponents().stream().mapToInt(comp -> comp.getBounds().y).max().getAsInt());
    68.         return (inventory == null || !inventory.isValid() || emoteComponent == null || !emoteComponent.isValid() ? -1f : (float) (emoteComponent.getBounds().y - minY) / (float) (maxY - minY));
    69.     }
    70.  
    71.     public static boolean isEmoteVisible(Emote emote) {
    72.         InterfaceComponent invent = getEmotesInventoryComponent(), emoteComp = getEmoteComponent(emote);
    73.         InteractableRectangle inv, emo;
    74.         return isEmotesTabOpen() && emoteComp != null && emoteComp.isValid() && invent != null && invent.isValid() && (emo = emoteComp.getBounds()).y >= (inv = invent.getBounds()).y && emo.y + emo.height <= inv.y + inv.height;
    75.     }
    76.  
    77.     public static float getScroll() {
    78.         InterfaceComponent scrollBox = Interfaces.getAt(216, 2, 0), scrollBar = Interfaces.getAt(216, 2, 1);
    79.         return (float) (scrollBar.getBounds().y - scrollBox.getBounds().y) / (float) (scrollBox.getHeight() - scrollBar.getHeight());
    80.     }
    81.  
    82.     public static boolean scrollTo(Emote emote) {
    83.         return isEmoteVisible(emote) || (scrollTo(getEmoteScroll(emote)) && isEmoteVisible(emote));
    84.     }
    85.  
    86.     public static boolean scrollTo(float scroll) {
    87.         InterfaceComponent scrollBox = Interfaces.getAt(216, 2, 0), scrollBar = Interfaces.getAt(216, 2, 1);
    88.         int difY = ((int) (scroll * (scrollBox.getHeight() - scrollBar.getHeight()))) - (scrollBar.getBounds().y - scrollBox.getBounds().y) + Random.nextInt(-5, 5);
    89.  
    90.         Mouse.move(scrollBar);
    91.         Mouse.press(Mouse.Button.LEFT);
    92.         Mouse.move(new InteractableRectangle(Mouse.getPosition().x + Random.nextInt(-5, 5), Mouse.getPosition().y + difY, 11, 11));
    93.         Mouse.release(Mouse.Button.LEFT);
    94.  
    95.         return true;
    96.     }
    97.  
    98.     public static boolean runEmote(Emote emote) {
    99.         InterfaceComponent component = getEmoteComponent(emote);
    100.         return (openEmotesTab() && scrollTo(emote) && component != null && component.click());
    101.     }
    102.  
    103. }
    104.  
    --- Double Post Merged, Apr 8, 2015, Original Post Date: Apr 8, 2015 ---
    Re-written using the ScrollBar util i made (https://www.runemate.com/community/threads/old-school-scroll-bar-util.1955/):

    Code (Text):
    1. package me.sothatsit.dancingformoney.util;
    2.  
    3. import com.runemate.game.api.hybrid.local.hud.interfaces.InterfaceComponent;
    4. import com.runemate.game.api.hybrid.local.hud.interfaces.Interfaces;
    5. import com.runemate.game.api.hybrid.util.Filter;
    6.  
    7. public class Emotes {
    8.  
    9.     public enum Emote {
    10.         YES, NO, BOW, ANGRY,
    11.         THINK, WAVE, SHRUG, CHEER,
    12.         BECKON, LAUGH, JUMP_FOR_JOY, YAWN,
    13.         DANCE, JIG, SPIN, HEADBANG,
    14.         CRY, BLOW_KISS, PANIC, RASPBERRY,
    15.         CLAP, SALUTE, GOBLIN_BOW, GOBLIN_SALUTE,
    16.         GLASS_BOX, CLIMB_ROPE, LEAN, GLASS_WALL,
    17.         IDEA, STAMP, FLAP, SLAP_HEAD,
    18.         ZOMBIE_WALK, ZOMBIE_DANCE, SCARED, RABBIT_HOP,
    19.         ZOMBIE_HAND, SKILL_CAPE
    20.     }
    21.  
    22.     public static class EmoteFilter extends Filter<InterfaceComponent> {
    23.  
    24.         private Emote emote;
    25.  
    26.         public EmoteFilter(Emote emote) {
    27.             this.emote = emote;
    28.         }
    29.  
    30.         @Override
    31.         public boolean accepts(InterfaceComponent interfaceComponent) {
    32.             return interfaceComponent.getActions().stream().anyMatch(action -> action.equalsIgnoreCase(emote.name().replace('_', ' ')));
    33.         }
    34.     }
    35.  
    36.     public static boolean isEmotesTabOpen() {
    37.         InterfaceComponent tab = getEmotesTabComponent();
    38.         return tab != null && tab.getTextureId() >= 0;
    39.     }
    40.  
    41.     public static boolean openEmotesTab() {
    42.         InterfaceComponent tab = getEmotesTabComponent();
    43.         return tab != null && tab.isValid() && ((tab.getTextureId() < 0 && tab.interact("Emotes")) || tab.getTextureId() >= 0);
    44.     }
    45.  
    46.     public static InterfaceComponent getEmotesTabComponent() {
    47.         return Interfaces.newQuery().actions("Emotes").visible().results().first();
    48.     }
    49.  
    50.     public static InterfaceComponent getEmoteComponent(Emote emote) {
    51.         InterfaceComponent emotesInv, emotes;
    52.         return ((emotesInv = Interfaces.getAt(216, 1)) == null || !emotesInv.isValid() ? null : emotesInv.getComponents(new EmoteFilter(emote)).stream().findFirst().get());
    53.     }
    54.  
    55.     public static float getEmoteScroll(Emote emote) {
    56.         return getEmoteScroll(getEmoteComponent(emote));
    57.     }
    58.  
    59.     public static float getEmoteScroll(InterfaceComponent emoteComponent) {
    60.         return ScrollBar.getEmotesScrollBar().getScroll(emoteComponent);
    61.     }
    62.  
    63.     public static boolean isEmoteVisible(Emote emote) {
    64.         InterfaceComponent emoteComp = getEmoteComponent(emote);
    65.         return ScrollBar.getEmotesScrollBar().isVisible(emoteComp);
    66.     }
    67.  
    68.     public static float getScroll() {
    69.         return ScrollBar.getEmotesScrollBar().getCurrentScroll();
    70.     }
    71.  
    72.     public static boolean scrollTo(Emote emote) {
    73.         return isEmoteVisible(emote) || (scrollTo(getEmoteScroll(emote)) && isEmoteVisible(emote));
    74.     }
    75.  
    76.     public static boolean scrollTo(float scroll) {
    77.         return ScrollBar.getEmotesScrollBar().scrollTo(scroll);
    78.     }
    79.  
    80.     public static boolean runEmote(Emote emote) {
    81.         InterfaceComponent component = getEmoteComponent(emote);
    82.         return (openEmotesTab() && scrollTo(emote) && component != null && component.click());
    83.     }
    84.  
    85. }
    86.  
     

Share This Page

Loading...