1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Question Best way to use Inventory SpriteItem on a GameObjetct?

Discussion in 'Developer Support' started by LucasSousa, Feb 28, 2017.

  1. LucasSousa

    Joined:
    Jan 25, 2015
    Messages:
    121
    Likes Received:
    19
    I have a item x in my inventory and I need use it on a object y.

    I didn't found a direct method like

    Code (Text):
    1. x.useOn(y);
    then I tried some stuff (strange...) like

    Code (Text):
    1. x.interact("Use");
    2. y.click();
    This really didn't worked hahah

    So, what a correct way to do this?
     
  2. Savior

    Savior Java Warlord

    Joined:
    Nov 17, 2014
    Messages:
    4,906
    Likes Received:
    2,748
    1) Interact with item 1
    2) Interact with item 2

    Use the development toolkit or similiar to find out the correct actions.
     
    LucasSousa likes this.
  3. LucasSousa

    Joined:
    Jan 25, 2015
    Messages:
    121
    Likes Received:
    19
    This has probability to works? While this, let me take a look on dev toolkit.

    Code (Text):
    1. x.interact("Use");
    2. //action 0 or ++...
    3. y.interact(y.getDefinition().getActions().get(0));
     
  4. Savior

    Savior Java Warlord

    Joined:
    Nov 17, 2014
    Messages:
    4,906
    Likes Received:
    2,748
    Using definitions alone wont work
     
  5. LucasSousa

    Joined:
    Jan 25, 2015
    Messages:
    121
    Likes Received:
    19
    Well... I find a "simply" way to use the item.

    Created a Task to "Use" item and a Task to y.click().

    At least it is working... I'll watch the performance.
     
  6. Swych

    Joined:
    Dec 9, 2016
    Messages:
    2,975
    Likes Received:
    1,024
    It seems like you've got it figured out. There's no method that using an item on another item/object/npc at the moment. I'll include a snippet from my construction bot which gets the noted planks in the inventory to use on the butler to unnote them.
    Code (Text):
    1. SpriteItem notedPlank = Inventory.newQuery().ids(bot.getRequiredNotedID()).results().first();
    2. // The noted id is assigned upon plank selection in GUI
    3.  
    4. if (notedPlank.click()) {
    5.       if (butler.interact("Use")) {
    6.             getLogger().log("Used planks on butler.");
    7.             bot.setCurrentStatus("Used planks on butler");
    8.       }
    9. }
     
  7. Party

    Party Client Developer

    Joined:
    Oct 12, 2015
    Messages:
    3,708
    Likes Received:
    1,606
    Interacting with an object whilst you have another selected (for OSRS at least) is

    Code (Javascript):
    1. SpriteItem#interact("Use", selected +  " -> " + target)
     
  8. Defeat3d

    Defeat3d Primate

    Joined:
    Oct 30, 2014
    Messages:
    3,025
    Likes Received:
    1,890
    Code (Text):
    1.     default <T1 extends Interactable, T2 extends Interactable> boolean combine(final T1 i1, final T2 i2) {
    2.         final String n1;
    3.         final String n2;
    4.         if ((n1 = getName(i1)) != null && (n2 = getName(i2)) != null) {
    5.             final SpriteItem selected = Inventory.getSelectedItem();
    6.             if (selected != null) {
    7.                 if (selected.equals(i1)) {
    8.                     return i2.interact("Use", n1 + " -> " + n2);
    9.                 } else if (selected.equals(i2)) {
    10.                     return i1.interact("Use", n2 + " -> " + n1);
    11.                 } else {
    12.                     return Interaction.deselectItem() && i1.interact("Use", n1) && i2.interact("Use", n1 + " -> " + n2);
    13.                 }
    14.             } else {
    15.                 return i1.interact("Use", n1) && i2.interact("Use", n1 + " -> " + n2);
    16.             }
    17.         }
    18.         return false;
    19.     }
    Taken from an interface but you should be able to figure out how to get it working.
     
  9. Gengsta

    Gengsta Community Manager

    Joined:
    Apr 7, 2015
    Messages:
    1,392
    Likes Received:
    763
    OSRS bot devs... Always overcomplicated :kappa:
     
  10. Defeat3d

    Defeat3d Primate

    Joined:
    Oct 30, 2014
    Messages:
    3,025
    Likes Received:
    1,890
    What do u mean
     
  11. Savior

    Savior Java Warlord

    Joined:
    Nov 17, 2014
    Messages:
    4,906
    Likes Received:
    2,748
    Whats the generics doing there?
     
  12. Defeat3d

    Defeat3d Primate

    Joined:
    Oct 30, 2014
    Messages:
    3,025
    Likes Received:
    1,890
    Allows you to do different combinations than just SpriteItem -> SpriteItem.
     
  13. Savior

    Savior Java Warlord

    Joined:
    Nov 17, 2014
    Messages:
    4,906
    Likes Received:
    2,748
    Lol just have Interactable as parameter :nickyoung:
     
  14. Defeat3d

    Defeat3d Primate

    Joined:
    Oct 30, 2014
    Messages:
    3,025
    Likes Received:
    1,890
    It used to be in something abstract that used 2 generic interacbles. >.>
     

Share This Page

Loading...