This article describes how to manipulate items in the game, including how to give/take items, count how many of an item a player has, check what kind of item an item is, and so forth.
Giving the player an item Edit
There are 3 ways to give the player an item:
|Script||What it does|
| || This script gives the player an item. As elsewhere, the "POTION" in the script is the internal name of the item.
Two messages are shown: one states that the item has been received (and if it is a TM/HM, the move it teaches is also stated), and the second message states the player has put it in the appropriate pocket of their Bag. If the item is Leftovers, the first message will say that "some Leftovers" have been received.
This script should be used when receiving an item from an NPC, because it displays the message that the player has "obtained" it (i.e. from another person, rather than finding it).
| ||This script works the same as the above, except that the first message shown states that the player has found the item (rather than obtained it). Also, if the item cannot be added to the Bag, the second message instead says the Bag is full, and the item is not picked up.|
| || This particular script is used by the above two methods. It does the actual adding of the item to the Bag, and does not display any messages.
If the Bag becomes full in the middle of adding several items, then as many as possible of the item will be added (the rest are ignored), but it will be treated as if no items had been picked up (i.e. it will still return FALSE).
You should check beforehand whether the player has enough space to store all the items to be added. This won't normally be a problem, though, as by default all Bag pockets are infinite in size.
You will not normally ever use this script.
All three scripts above will return TRUE if the item has been added to the player's Bag, and FALSE if it hasn't.
As a slot in the Bag can only hold a maximum of 99 of an item, if you attempt to give the player more than this amount, the excess will start filling up a new slot. For example, if the player has 97 Potions and the game gives them 5 more, 2 of the extra Potions will go into the existing slot and the other 3 will go into a new slot.
Giving multiple items Edit
The first two scripts in the table above can also give more than 1 of an item. Here are examples of this:
Kernel.pbReceiveItem(PBItems::POKEBALL,5) Kernel.pbReceiveItem(PBItems::ORANBERRY,2,_I("Oran Berries")) Kernel.pbItemBall(PBItems::POTION,2) Kernel.pbItemBall(PBItems::WISEGLASSES,3,_I("pairs of Wise Glasses"))
In addition to the item, there are two other parameters: the quantity and the "plural". Both are optional parameters; if the quantity is blank, 1 of the item will be added as in the table above.
If the script is giving more than 1 of the item, and the "plural" is not given, then the messages displayed will add an "s" onto the end of the item name (e.g. "Poké Balls", "Potions"). If a "plural" is given, then the "plural" will be used instead of the item name (e.g. "Oran Berries", "pairs of Wise Glasses").
You should give a "plural" if it wouldn't look right to just add an "s" onto the end of the item name. If it would look right, then simply ignore the "plural" parameter.
Deleting an item from the Bag Edit
To delete an item that the player has, use the following script:
To delete several of the same item, add the quantity as a second parameter, like so:
This script returns TRUE if the item has been removed, and FALSE if it hasn't. It does not display any messages to indicate whether the item has been removed.
Note that if you try to delete more of an item than there are in the Bag, then as many as possible of that item will be deleted (i.e. all of them), but then this script will still return FALSE (because it didn't manage to delete as many as it should have).
Before deleting an item, you should check that the player has at least as many of that item as you want to delete, so that the script can execute fully.
Counting items in the Bag Edit
To determine how many of a particular item the player currently has, use the following script:
This script returns a value, and does nothing else on its own. It should either be stored as a variable, or be used as part of a check comparing this value to another value, e.g.
itemquant=$PokemonBag.pbQuantity(:POTION) $game_variables=$PokemonBag.pbQuantity(:POTION) $PokemonBag.pbQuantity(:POTION)==5 $PokemonBag.pbQuantity(:POTION)>0
Checking whether the player has at least 1 of an item is done for certain Key Items, such as Key Cards. These items have no effects themselves, but doors open when interacted with so long as the player has the item in their Bag. This is done by using the last example in a Conditional Branch.
Choosing an item from the Bag Edit
To make the player choose an item from the Bag, use either version of the following script:
This method returns the ID of the chosen item (or 0 if no item was chosen). The argument is optional, and is the number of the Global Variable in which the returned value is stored (in addition to returning the value).
To make the player choose from a specific list of items, use the following script:
pbChooseItemFromList(_I("Choose an item"),1,:POTION,:REPEL,:POKEBALL)
This method returns the ID of the chosen item, or -1 if the choice was cancelled. The second argument (the number
1 here) is the Global Variable in which the returned value is stored (in addition to returning the value).
Any number of items can be listed. Only items which the player has at least 1 of will appear in the list. If the player has none of the listed items, then the method will immediately return/store 0 without displaying the message or listing anything.
Other checks Edit
Below is a list of other ways an item can be checked or manipulated.
| ||Returns the name of the item.|
| ||Returns the value of the item, i.e. the price the player would pay when buying it. The selling price of an item is half its buying price.|
| ||Returns TRUE if the item is a Key Item or a HM (i.e. something that cannot be tossed/sold); returns FALSE otherwise.|
| ||Returns TRUE if the item is a Key Item (i.e. is stored in Bag pocket 8); returns FALSE otherwise.|
| ||Returns TRUE if the item is a TM or a HM; returns FALSE otherwise.|
| ||Returns TRUE if the item is a TM; returns FALSE otherwise.|
| ||Returns TRUE if the item is a HM; returns FALSE otherwise.|
| ||Returns TRUE if the move can be taught by any HM; returns FALSE otherwise.|
| ||Returns the Bag pocket number this item is stored in.|
| ||Returns TRUE if the item is a Mail item; returns FALSE otherwise.|
| ||Returns TRUE if the item is a Poké Ball or a Snag Ball; returns FALSE otherwise.|
| || Returns TRUE if the item is a Snag Ball, or if it is a Poké Ball while |
| ||Returns TRUE if the item is a berry; returns FALSE otherwise.|
| || Returns the location of the nearest hidden item; returns |
| ||Returns TRUE if there is space in the Bag for the given number of the given item; returns FALSE if there isn't.|