Eat some food
Description: Similar to the SmartBandage script, it uses the best food available to heal you up.
Notes: Updated by Peter Provost (http://www.peterprovost.org/) to work w/ 1.11.2 changes. Also included a number of new food items.
How to use: bind to key or execute on demand
-- Use the most approriate food to heal. Find it anywhere in the player's
-- inventory.
-- The algorithm is as follows:
-- Our goal is to heal the target to at least 95 percent of his/her maximum
-- (adjustable below).
-- Identify the best food to eat to meet the healing need.
-- Try to find it in the player's inventory. If not found, try
-- the next food item and so on up the line. If we didn't find a bandage,
-- then go back and try to find the bandage just smaller than the desired bandage.
-- If not found, try the next smaller bandage and so on.
--
-- NOTE: This requires the FindContainerItemByName() and p() functions found
-- elsewhere on this wiki.
--
TARGET_HEALTH_PCT = 95
-- these MUST be listed in ascending order of potency
-- Keep in mind not All of the food is listed here. There are dozens,
-- potentially hundreds of food items. The ones listed here are basic
-- and common, you can change them to suit your needs
fooditems = {
{"Spiced Wolf Meat", 61}, -- +2 Well-fed buff
{"Herb Baked Egg", 61},
{"Shiny Red Apple", 61},
{"Brilliant Smallfish", 61},
{"Slitherskin Mackerel", 61},
{"Charred Wolf Meat", 61},
{"Roasted Boar Meat",61},
{"Tough Jerky", 61},
{"Roasted Boar Meat", 61},
{"Darnassian Bleu",61},
{"Boiled Clams", 243}, -- +4 Well-fed buff
{"Coyote Steak",243}, -- +4 Well-fed buff
{"Crab Cake", 243}, -- +4 Well-fed buff
{"Dry Pork Ribs", 243}, -- +4 Well-fed buff
{"Goretusk Liver Pie", 243}, -- +4 Well-fed buff
{"Blood Sausage", 243}, -- +4 Well-fed buff
{"Haunch of Meat", 243},
{"Freshly Baked Bread", 243},
{"Tel'Abim Banana", 243},
{"Smoked Bear Meat", 243},
{"Longjaw Mudsnapper",243},
{"Curiously Tasty Omelet", 552}, -- +6 Well-fed buff
{"Goblin Deviled Clams", 552}, -- +6 Well-fed buff
{"Moist Cornbread", 552},
{"Dwarven Mild", 552},
{"Spongy Morel", 552},
{"Mutton Chop", 552},
{"Raw Greater Sagefish", 567},
{"Soothing Turtle Bisque", 874}, -- +8 Well-fed buff
{"Tasty Lion Steak", 874}, -- +8 Well-fed buff
{"Delicious Cave Mold", 875},
{"Wild Hog Shank", 875},
{"Mystery Stew", 875},
{"Mulgore Spice Bread", 875},
{"Frog Leg Stew", 875},
{"Soft Banana Bread", 1392},
{"Spider Sausage", 1392},
}
if (not UnitIsFriend("player","target")) then
TargetUnit("player")
end
-- As far as I can temm, UnitInParty("target") doesn't work on yourself
-- since the 1.11.2 patch. Commenting it out until I figure out whether I
-- care or not.
-- if (not UnitInParty("target")) then
-- return
-- end
need = (UnitHealthMax("target") * TARGET_HEALTH_PCT/100) - UnitHealth("target")
if (need <= 0) then
p("## You don't need to eat anything right now")
return
end
desiredFooditemsIdx = table.getn(fooditems)
for idx,b in fooditems do
if (b[2] >= need) then
desiredFooditemsIdx = idx
break
end
end
b = fooditems[desiredFooditemsIdx]
p("## Food: "..UnitName("target").." needs "..need.." HP, I'll try to use a "..b[1].."("..b[2]..")")
bag, slot = nil, nil
for i = desiredFooditemsIdx, table.getn(fooditems) do
bag, slot = FindItemInInventory(fooditems[i][1])
if (bag ~= nil) then
p("## Food: Eating "..fooditems[i][1].." ("..fooditems[i][2]..") on "..UnitName("target"))
UseContainerItem(bag, slot)
return
end
end
for i = desiredFooditemsIdx - 1, 1, -1 do
bag, slot = FindItemInInventory(fooditems[i][1])
if (bag ~= nil) then
p("## Fooditems: Using "..fooditems[i][1].." ("..fooditems[i][2]..") on "..UnitName("target"))
UseContainerItem(bag, slot)
return
end
end
p("## Sorry, could not find food, make some or buy some")