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

Question How to use item in inventory on an object?

Discussion in 'Developer Support' started by stanm3, Aug 8, 2015.

  1. stanm3

    Joined:
    Aug 6, 2015
    Messages:
    4
    Likes Received:
    0
    How do I use an item in an inventory on a object? Like selecting food to cook on a range.

    What I've been doing is selecting object in inventory and then using Gameobject.click() to do this, however if there's someone in front of the object it doesn't work. What is the proper way to do this?

    Thanks.
     
  2. Derk

    Derk 12 year old normie

    Joined:
    Jan 8, 2015
    Messages:
    2,766
    Likes Received:
    1,339
    item1.interact("Use");
    item2.interact("Use -> " + item2.getName());

    That's for RS3.
     
    #2 Derk, Aug 8, 2015
    Last edited: Aug 8, 2015
  3. stanm3

    Joined:
    Aug 6, 2015
    Messages:
    4
    Likes Received:
    0
    I'm trying to make a script bot for OSRS.

    Had no luck with that method, GameObject.getName() doesnt exist,

    I even tried to manually enter name "Range" replacing getName that also doesnt work. it just hovers over the range continuously.
     
  4. SlashnHax

    Joined:
    Dec 10, 2014
    Messages:
    3,198
    Likes Received:
    1,041
    Just use .interact("Use", "Range"), the reason it's hovering is the action is "Use", not "Use -> Range"
     
  5. stanm3

    Joined:
    Aug 6, 2015
    Messages:
    4
    Likes Received:
    0
    Still not luck, These are the two lines that I have.

    Inventory.getItems(food).first().interact("Use");
    range.interact("Use", "Range");

    Right now it just selects the food item and mouse goes back and forth between the food item and range.
     
  6. SlashnHax

    Joined:
    Dec 10, 2014
    Messages:
    3,198
    Likes Received:
    1,041
    Yeah that's your logic. Try this
    Code (Text):
    1. if(Inventory.getSelectedItem() == null){
    2.     SpriteItem item = Inventory.getItems(food).first();
    3.     if(item != null)
    4.         item.interact("Use");
    5. } else {
    6.     GameObject range = GameObjects.getLoaded("Range").nearest();
    7.     if(range != null)
    8.         range.interact("Use", "Range");
    9. }
    That's from the top of my head so there may be some errors.
     
  7. stanm3

    Joined:
    Aug 6, 2015
    Messages:
    4
    Likes Received:
    0
    Now its just selecting the inventory object and hovers the range continuously changing mouse location of the hover.

    This is OSRS if that matters.

    Edit:
    I think this might be because "Use" isnt actually an action of range since range only has examine option. Is there a way to just right click on an object and click a menu item?
     
    #7 stanm3, Aug 9, 2015
    Last edited: Aug 9, 2015
  8. PhaseCoder

    Joined:
    Jan 1, 2015
    Messages:
    272
    Likes Received:
    26

    Gamobject name;

    name.getDef().getName();

    idk if thats wha you want i didnt read whole thread in a rush sorry
     
  9. Baddest Man on Earth

    Joined:
    Nov 26, 2014
    Messages:
    616
    Likes Received:
    246
    Don't know if this has been resolved, but...
    Code (Text):
    1. public static boolean useItemOnObject(SpriteItem item, GameObject object) {
    2.         if (item == null || object == null || !item.isValid() || !object.isValid())
    3.             return false;
    4.         if (item.interact("Use") && locatable(object,
    5.                 "Use", item.getDefinition().getName() + " -> " + object.getDefinition().getName())) {
    6.             return true;
    7.         }
    8.         return false;
    9.     }
    locatable method code:

    Code (Text):
    1. public static <I extends LocatableEntity> boolean locatable(I target, String action, String name) {
    2.         if (target == null || !target.isValid()) {
    3.             return false;
    4.         }
    5.         if (target.getVisibility() >= 80d) {
    6.             if (name.equals("")) {
    7.                 return target.interact(action);
    8.             } else {
    9.                 return target.interact(action, name);
    10.             }
    11.         } else {
    12.             if (target.distanceTo(Players.getLocal()) > 6d && target.getPosition().getPlane() == Players.getLocal().getPosition().getPlane()) {
    13.                 BresenhamPath.buildTo(target).step();
    14.                 return false;
    15.             } else {
    16.                 Camera.turnTo(target);
    17.                 return false;
    18.             }
    19.         }
    20.     }
    21.  
     
    takescake likes this.
  10. SlashnHax

    Joined:
    Dec 10, 2014
    Messages:
    3,198
    Likes Received:
    1,041
    Why 80d and 6d?
     
  11. Baddest Man on Earth

    Joined:
    Nov 26, 2014
    Messages:
    616
    Likes Received:
    246
    Dunno, habits from university. Prof took marks away if I didn't explicitly make it a double.
     
  12. SlashnHax

    Joined:
    Dec 10, 2014
    Messages:
    3,198
    Likes Received:
    1,041
    That's strange, you'd think they'd focus more on stuff like method names xD
     
  13. Aidden

    Aidden Author of MaxiBots

    Joined:
    Dec 3, 2013
    Messages:
    6,482
    Likes Received:
    990
    PhaseCoder is right. getName only exists in the definition so you must first store the definition and null check it. Then you can use getName on the definition.
    And this is correct too. Except item2 should be npc or whatever. And you should make sure to use proper logic to decide when to interact with the item and when to interact with the npc rather than just calling the mdirectly one after the other, because that can be buggy.
     

Share This Page

Loading...