---
description: Section 7.G
---

# Improved Item AI

[**Eevee Expo Link**](https://eeveeexpo.com/resources/1537/)

[**PokeCommunity Link**](https://www.pokecommunity.com/threads/improved-item-ai-dbk-add-on-v21-1.529639/#post-10844983)

[**Download Link**](https://www.mediafire.com/file/2k49k40hg6zocg9/Improved_Item_AI.zip/file)

This plugin builds upon the Deluxe Battle Kit to improve upon the AI when it comes to using items from the inventory. This will generally allow AI trainers to use items more intelligently and less wastefully. AI trainers will now also consider using items to restore HP, PP, or cure the status conditions of their entire party, and not just their active Pokemon.

This also expands upon the types of items the AI is able to use in battle, allowing them to access all of the same items that the player would be able to use. This means you can give NPC's more unique items that they normally wouldn't know how to use, such as Ethers, Guard Spec. or even more obscure things like the Poke Flute.

***

<mark style="background-color:orange;">**AI Item Scores**</mark>

This plugin overhauls how the AI determines to use items by implementing a "scoring" system that works very similarly to how the AI scores moves to determine which to use. While playing in debug mode, you can even turn on battle logging to be able to view the AI's decision making in regards to items within the game console.

In the plugin file `[001] Battle_AI`, you will find the following settings:

```ruby
ITEM_FAIL_SCORE    = 20
ITEM_USELESS_SCORE = 60
ITEM_BASE_SCORE    = 100
```

These are what determines the base values the AI utilizes when it comes to scoring moves. These are identical values used for move calculation, and works similarly here. You may adjust these to your liking.

***

<mark style="background-color:orange;">**Item Utilities**</mark>

This plugin adds several scripting utilities to the Battle class that may be used to make coding your own AI handlers a bit easier. Below I'll cover each new method included:

<details>

<summary>Utilities</summary>

* `pbItemHealsHP?(item, onlyHP = false)`\
  This returns true if the `item` ID entered is a healing item. This includes any item included in the `HP_HEAL_ITEMS` hash or the `FULL_RESTORE_ITEMS` array in the `AI_UseItem` section in Essentials. If `onlyHP` is set to true, then this will only return true if the item heals HP only with no other effects (basically, this would exclude Full Restore items).\

* `pbItemCuresStatus?(item, oneStatus = false)`\
  This returns true if the `item` ID entered is an item that cures status conditions. This includes any item included in the `ONE_STATUS_CURE_ITEMS` or `ALL_STATUS_CURE_ITEMS` arrays in the `AI_UseItem` section in Essentials. If `oneStatus` is set to true, then this will only return true if the item only heals one particular status condition (basically, this would exclude Full Heal items).\

* `pbItemRaisesStats?(item, oneStat = false)`\
  This returns true if the `item` ID entered is an item that raises a battler's stats. This includes any item included in the `ONE_STAT_RAISE_ITEMS` hash or the `ALL_STATS_RAISE_ITEMS` array in the `AI_UseItem` section in Essentials. If `oneStat` is set to true, then this will only return true if the item only raises one particular stat (basically, this would exclude items like Max Mushrooms).\

* `pbItemRevivesFainted?(item)`\
  This returns true if the `item` ID entered is an item that revives fainted Pokemon. This includes any item included in the `REVIVE_ITEMS` hash in the `AI_UseItem` section in Essentials.\

* `pbItemRestoresPP?(item, mode = 0)`\
  This returns true if the `item` ID entered is an item that restores PP. This includes any item included in the `PP_HEAL_ITEMS` or `ALL_MOVE_PP_HEAL_ITEMS` hashes in the `[001] Battle_AI` file in this plugin. If `mode` is set to 1, then this will only return true for Ether-like items that only restore the PP for a single move. If `mode` is set to 2, then this will only return true for Elixir-like items that restore the PP for all moves. Otherwise, this will return true if the item is either.\

* `pbGetItemValue(item, itemType)`\
  Returns the value of the entered `item` ID. The "value" of an item is based on what symbol is entered as the item's `itemType`.
  * When `:potion`, the item's value is how much HP it heals.
  * When `:ether`, the item's value is how much PP it restores to a single move.
  * When `:elixir`, the item's value if how much PP is restored to all moves.
  * When `:stats`, the item's value is how many stages this item increases a stat by.
  * When `:revive`, the item's value is a 7 if the item fully revives, and a 5 otherwise.\

* `pbHasHealingItem?(idxBattler, healAmt, itemType)`\
  Returns true if the trainer who owns the battler with the entered index `idxBattler` has a healing item in their inventory of a certain `itemType` that heals less than `healAmt`. This can be used to check if a trainer has weaker healing items in their inventory, or a healing item that restores less than a certain value.\
  \
  The `itemType` is set to `:potion` by default, which checks specifically for HP restoring items. However, you can set this to `:ether` or `:elixir` instead, if you want to check for specific types of PP restoring items rather than HP. The `healAmt` is set to 1000 by default, which is enough to cover every healing item in the game (since things like Max Potion have a healing value of 999).

</details>
