Jump to content

Looking for Code/Snippet/Advice with Looting/Healing


Recommended Posts

Posted

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

Posted (edited)

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
Posted (edited)

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
Posted (edited)

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
Posted

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!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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