Hello, I'm not very good at these introductions, but this is a simple script that allows the player to Auto Heal their party from the Pause Menu.
It calculates the most efficient order to use healing items in terms of buy price, and there are a few options that the developer can pick that allows them to pick which items are and aren't used.
Please give Credit to Swdfm if using!
Swdfm
Here is the Script:
To install, either place in the Scripts section above Main, or convert to a .rb file and put it in the Plugins folder.
It calculates the most efficient order to use healing items in terms of buy price, and there are a few options that the developer can pick that allows them to pick which items are and aren't used.
Please give Credit to Swdfm if using!
Swdfm
Here is the Script:
To install, either place in the Scripts section above Main, or convert to a .rb file and put it in the Plugins folder.
Spoiler:
Code:
#===============================================================================
# Auto Heal in Pokémon Essentials v20
# By Swdfm
#===============================================================================
# Settings
#===============================================================================
# Position within Pause Menu
AUTO_HEAL_PRIORITY = 41
# Include Revives?
# 0 for No
# 1 for Always
# 2 for Ask Player
INCLUDE_REVIVES = 1
# Use items like Berry Juice and Lava Cookie
USE_SPECIAL_ITEMS = false
# Heal Statuses when Auto Healing
AUTO_HEAL_STATUSES = true
# How does the auto Heal calculate
# 0 for Priority in order of party order
# 1 for Priority in order of lowest HP first
# 2 for trying to get team as healthy as possible equally
AUTO_HEAL_PRIORITY_TYPE = 0
#===============================================================================
MenuHandlers.add(:pause_menu, :auto_heal, {
"name" => _INTL("Auto Heal"),
"order" => AUTO_HEAL_PRIORITY,
"condition" => proc { next !$player.party.empty? && $bag },
"effect" => proc { |menu|
pbPlayDecisionSE
include_revives = INCLUDE_REVIVES == 1
if INCLUDE_REVIVES == 2
include_revives = pbConfirmMessage(_INTL("Include Revives during this Auto Heal?"))
end
pbAutoHeal(include_revives)
next
}
})
#===============================================================================
# How much does each item heal?
#===============================================================================
def pbGetHealAmount
ret = {
:POTION => 20,
:SUPERPOTION => 50,
:HYPERPOTION => 200,
:MAXPOTION => -1,
:FULLRESTORE => -1,
:FRESHWATER => 50,
:SODAPOP => 60,
:LEMONADE => 80,
:MOOMOOMILK => 80
}
if USE_SPECIAL_ITEMS
ret[:BERRYJUICE] = 20
ret[:ORANBERRY] = 10
ret[:SITRUSBERRY] = 0.25
ret[:ENERGYPOWDER] = 50
ret[:ENERGYROOT] = 200
if !Settings::RAGE_CANDY_BAR_CURES_STATUS_PROBLEMS
ret[:RAGECANDYBAR] = 20
end
end
if Settings::REBALANCED_HEALING_ITEM_AMOUNTS
ret[:SUPERPOTION] = 60
ret[:HYPERPOTION] = 120
ret[:FRESHWATER] = 30
ret[:SODAPOP] = 50
ret[:LEMONADE] = 70
if USE_SPECIAL_ITEMS
ret[:ENERGYPOWDER] = 60
ret[:ENERGYROOT] = 120
end
end
return ret
end
#===============================================================================
# Revival Items in order of priority
#===============================================================================
def pbGetRevivalItems
return [:REVIVE, :MAXREVIVE, :MAXHONEY, :REVIVALHERB]
end
#===============================================================================
# What status does each status item heal?
#===============================================================================
def pbAutoHeal_GetStatusItems
ret = {
:AWAKENING => :SLEEP,
:POKEFLUTE => :SLEEP,
:ANTIDOTE => :POISON,
:BURNHEAL => :BURN,
:PARALYZEHEAL => :PARALYSIS,
:PARALYZHEAL => :PARALYSIS,
:ICEHEAL => :FROZEN,
:FULLHEAL => :ALL,
:FULLRESTORE => :ALL
}
if USE_SPECIAL_ITEMS
ret[:CHESTOBERRY] = :SLEEP
ret[:BLUEFLUTE] = :SLEEP
ret[:PECHABERRY] = :POISON
ret[:RAWSTBERRY] = :BURN
ret[:CHERIBERRY] = :PARALYSIS
ret[:ASPEARBERRY] = :FROZEN
ret[:LAVACOOKIE] = :ALL
ret[:OLDGATEAU] = :ALL
ret[:CASTELIACONE] = :ALL
ret[:LUMIOSEGALETTE] = :ALL
ret[:SHALOURSABLE] = :ALL
ret[:BIGMALASADA] = :ALL
ret[:PEWTERCRUNCHIES] = :ALL
ret[:LUMBERRY] = :ALL
ret[:HEALPOWDER] = :ALL
if Settings::RAGE_CANDY_BAR_CURES_STATUS_PROBLEMS
ret[:RAGECANDYBAR] = :ALL
end
end
return ret
end
#===============================================================================
# Nitty Gritty Past Here
# Don't Modify Unless You Know What You're Doing!
#===============================================================================
# Main Auto Heal Script
#===============================================================================
def pbAutoHeal(include_revives = false)
pbAutoHeal_Revival if include_revives
pbAutoHeal_Status if AUTO_HEAL_STATUSES
pbAutoHeal_Healing
pbMessage(_INTL("Your Pokémon have been healed!"))
end
#===============================================================================
# Healing Phase
#===============================================================================
# Auto Heal: Healing: Main Script
#===============================================================================
def pbAutoHeal_Healing
m_inv = pbGetMockInventory
m_party = pbGetMockParty
while !m_inv.keys.empty? && !m_party.keys.empty?
pbAutoHeal_Round(m_inv, m_party)
m_inv = pbGetMockInventory
m_party = pbGetMockParty
end
end
#===============================================================================
# Auto Heal: Healing: Calculate Which Healing Items Are Left
#===============================================================================
def pbGetMockInventory
ret = {}
hash = pbGetHealAmount
for k in hash.keys
next if $bag.quantity(k) == 0
ret[k] = $bag.quantity(k)
end
return ret
end
#===============================================================================
# Auto Heal: Healing: Get Party Members That Need Healing
#===============================================================================
def pbGetMockParty
ret = {}
count = -1
for i in $player.party
count += 1
next if i.egg?
next if i.fainted?
hp_left = i.totalhp - i.hp
next if hp_left == 0
ret[count] = hp_left
end
return ret
end
#===============================================================================
# Auto Heal: Healing: Does A "Round" Of Healing
# ie. Picks an item and a Pokemon to use it in, and uses it
#===============================================================================
def pbAutoHeal_Round(m_inv, m_party)
p = $player.party[pbCalculateAutoHealPriority(m_party)[0]]
price_rates = {}
for i in m_inv.keys
price_rates[i] = pbGetPriceOfOneHitpointBasedOnItem(p, i)
end
keys = price_rates.keys.sort{ |a, b| price_rates[a] <=> price_rates[b] }
item = keys[0]
pbUseHealItemOnPokemonSilent(p, item)
end
#===============================================================================
# Auto Heal: Healing: Calculate Which Pokemon To Heal Next
#===============================================================================
def pbCalculateAutoHealPriority(party)
keys = party.keys
case AUTO_HEAL_PRIORITY_TYPE
when 0
keys = keys.sort
when 1
keys = keys.sort{ |a, b| party[a] <=> party[b] }
when 2
keys = keys.sort{ |a, b|
($player.party[a].hp / $player.party[a].totalhp) <=> ($player.party[b].hp / $player.party[b].totalhp)
}
end
return keys
end
#===============================================================================
# Auto Heal: Healing: Returns How Much $ each HP costs to heal
#===============================================================================
def pbGetPriceOfOneHitpointBasedOnItem(p, item)
amt = pbGetHealAmountOfItemOnPokemon(p, item)
price = GameData::Item.get(item).price
return price / amt # Float!
end
#===============================================================================
# Auto Heal: Healing: Heals The Pokemon and uses up the item
#===============================================================================
def pbUseHealItemOnPokemonSilent(p, item)
h_amount = pbGetHealAmount[item]
if h_amount == -1
p_addn = p.totalhp - t.hp
elsif h_amount == 0.25
p_addn = [p.totalhp - t.hp, (p.totalhp / 4).round].min
else
p_addn = [h_amount, p.totalhp - p.hp].min
end
p.hp += p_addn
$bag.remove(item, 1)
end
#===============================================================================
# Auto Heal: Healing: Calculates How Much An Item Heals A Pokemon
#===============================================================================
def pbGetHealAmountOfItemOnPokemon(p, item)
hp_left = p.totalhp - p.hp
amt = pbGetHealAmount[item]
return 0 if !amt
return hp_left if amt == -1
return p.totalhp / 4 if amt == 0.25
return [amt, hp_left].min
end
#===============================================================================
# Status Phase
#===============================================================================
# Auto Heal: Status: Main Script
#===============================================================================
def pbAutoHeal_Status
statuses = [
:SLEEP, :POISON, :BURN, :PARALYSIS, :FROZEN
]
for status in statuses
m_party = pbGetMockParty_Status(status)
m_inv = pbGetMockInventory_Status(status)
while !m_party.keys.empty? && !m_inv.keys.empty?
p = $player.party[m_party.keys[0]]
item = pbCalculateStatusItemToUse(status, m_inv)
pbAutoHeal_HealStatusOfPokemon(p, item)
m_party = pbGetMockParty_Status(status)
m_inv = pbGetMockInventory_Status(status)
end
end
end
#===============================================================================
# Auto Heal: Status: Get Party Members That Need Statuses Healing
#===============================================================================
def pbGetMockParty_Status(status)
ret = {}
count = -1
for i in $player.party
count += 1
next if i.egg?
next unless i.status == status
ret[count] = :Yes
end
return ret
end
#===============================================================================
# Auto Heal: Status: Calculate Which Status Healing Items Are Left
#===============================================================================
def pbGetMockInventory_Status(status)
ret = {}
hash = pbAutoHeal_GetStatusItems
for k in hash.keys
next unless [:ALL, status].include?(hash[k])
next if $bag.quantity(k) == 0
ret[k] = hash[k]
end
return ret
end
#===============================================================================
# Auto Heal: Status: Works Out Which Status Item To Use
#===============================================================================
def pbCalculateStatusItemToUse(status, m_inv)
singles = []
alls = []
# Prefers items that heal one status over those that heal all
for i in m_inv.keys
if m_inv[i] == :ALL
alls.push(i)
else
singles.push(i)
end
end
singles = singles.sort{|a, b|
GameData::Item.get(a).price <=>
GameData::Item.get(b).price
}
alls = alls.sort{|a, b|
GameData::Item.get(a).price <=>
GameData::Item.get(b).price
}
ret = []
ret += singles
ret += alls
return ret[0]
end
#===============================================================================
# Auto Heal: Status: Heals the status and consumes the item
#===============================================================================
def pbAutoHeal_HealStatusOfPokemon(p, item)
p.status = :NONE
p.hp = p.totalhp if item == :FULLRESTORE
$bag.remove(item, 1)
end
#===============================================================================
# Revival Phase
#===============================================================================
def pbAutoHeal_Revival
for i in $player.party
next unless i.fainted? # Egg Check already there!
for r_i in pbGetRevivalItems
next if $bag.quantity(r_i) == 0
if r_i == :REVIVE
i.hp = [i.totalhp / 2 .floor, 1].max # Shedinja!
else
i.hp = i.totalhp
end
$bag.remove(r_i, 1)
break
end
end
end