Jump to content

Looking for Code/Snippet/Advice with Looting/Healing


Embarrassment

Recommended Posts

Hi, I've been reading through a lot of random tutorials and snippets trying to find things about looting items and how to use the api properly for that. I would appreciate any help with how people set-up looting kills and eating food to heal in combat scripts. I don't need full explanations, just maybe someones code to look at or maybe the proper API functions to use. Thanks

Link to comment
Share on other sites

Take a look at GroundItems and Skills in the API. You could eat based off the percent of health they have with:

if(myPlayer().getHealth() <= 30) { //change 30 to lowest percent you will tolerate
//code here
}

Or you could check the current health using:
 

if(getSkills().getDynamic(Skill.HITPOINTS) <= 25)) { //change 25 to lowest health you will tolerate
//code here
}

Did not post loot example since there may be better ways. For Black Dragons script I was working on, I checked based off what items were on the ground. Problem with that is other players leaving loot on the ground.

Hope this helped a bit.
 

Edited by bob10
  • Like 2
Link to comment
Share on other sites

This is exactly what I was looking for. Thank you so much. Yeah, I'd like to know how people set-up loot your own kills. 

 

Edit - So that code grabs the health of your player, do I then manipulate inventory/entity API to find and eat a specified food?

Edited by Embarrassment
Link to comment
Share on other sites

This is exactly what I was looking for. Thank you so much. Yeah, I'd like to know how people set-up loot your own kills. 

 

Edit - So that code grabs the health of your player, do I then manipulate inventory/entity API to find and eat a specified food?

Sorry, meant to check back soon.

To eat a specific food:

getInventory().getItem(379).interact("Eat"); // using int
getInventory().getItem("Lobster").interact("Eat"); // using String
getInventory().getItemInSlot(0).interact("Eat"); // slot 

Eat from a variety of foods: *Twin showed me Filters. Like using when needed.

@SuppressWarnings("unchecked")
getInventory().getItem(new Filter<Item>() {
   @Override
   public boolean match(Item item) {
         return item != null 
                      && food_list.contains(item.getName()); //food_list = list formed based on foods the user entered
   }
});

 

 

Edited by bob10
Link to comment
Share on other sites

This is everything I needed. Thank you guys for being so helpful. 

 

Edit - Still looking for some information on looting individual kills. Trying to make a bot that doesn't run around like a chicken with it's head cut-off grabbing things. Cheers. Working on combat script for multiple monster types in obscure places. IE (not alkharid, not cows, not stronghold). :)

Edited by Embarrassment
Link to comment
Share on other sites

This is everything I needed. Thank you guys for being so helpful.

Edit - Still looking for some information on looting individual kills. Trying to make a bot that doesn't run around like a chicken with it's head cut-off grabbing things. Cheers. Working on combat script for multiple monster types in obscure places. IE (not alkharid, not cows, not stronghold). :)

Would recommend looking at the mobs position when it dies (there will be an animation for it), and wait until there are GroundItems for it.

Also, use filters when possible. They're really good!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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