Skip to content
PhoenixBound edited this page Aug 16, 2020 · 24 revisions

Credit to paccy for this tutorial in the Simple Modifications Pokecommunity thread. The tutorial was modified by ExpoSeed.

This tutorial will make all TMs infinitely reusable, unholdable by Pokemon, unsellable to shops, and also removes the number from appearing in the Bag.

Contents

  1. Don't consume TMs on use
  2. Treat TMs as HMs in the bag
  3. Don't allow TM selling and rebuying

1. Don't consume TMs on use

Normally, the game checks if the item used was a TM or an HM, and consumes the item if it was a TM. We can just simply remove this check.

Edit src/party_menu.c:

static void Task_LearnedMove(u8 taskId)
{
    struct Pokemon *mon = &gPlayerParty[gPartyMenu.slotId];
    s16 *move = &gPartyMenu.data1;
    u16 item = gSpecialVar_ItemId;

    if (move[1] == 0)
    {
        AdjustFriendship(mon, FRIENDSHIP_EVENT_LEARN_TMHM);
-       if (item < ITEM_HM01_CUT)
-           RemoveBagItem(item, 1);
    }
    GetMonNickname(mon, gStringVar1);
    StringCopy(gStringVar2, gMoveNames[move[0]]);
    StringExpandPlaceholders(gStringVar4, gText_PkmnLearnedMove3);
    DisplayPartyMenuMessage(gStringVar4, TRUE);
    ScheduleBgCopyTilemapToVram(2);
    gTasks[taskId].func = Task_DoLearnedMoveFanfareAfterText;
}

If you were to stop here, TMs can still be given to Pokemon and you can still see the number in the bag. The next step will address this.

2. Treat TMs as HMs in the bag

struct Item has a field importance. If this field has a nonzero value, then the item is treated like a key item, and cannot be held, tossed, or deposited in the PC, and it will not display an item count in the bag.

Edit src/data/items.h:

    [ITEM_TM01_FOCUS_PUNCH] =
    {
        .name = _("TM01"),
        .itemId = ITEM_TM01_FOCUS_PUNCH,
        .price = 3000,
        .description = sTM01Desc,
+       .importance = 1,
        .pocket = POCKET_TM_HM,
        .type = 1,
        .fieldUseFunc = ItemUseOutOfBattle_TMHM,
        .secondaryId = 0,
    },

You will need to repeat the above for every TM.

But there is still an issue: TMs can still be sold. This will be addressed in the next step.

3. Don't allow TM selling and rebuying

If you were to see what determines if an item can be sold, you will find that any item with a price of 0 cannot be sold. So it's as simple as setting the TM prices to 0, right? Wrong. Setting the item price to 0 also means that the buying price will also be 0!

In order to avoid this, we will need to modify the logic that checks for whether an item can be sold. All we need to do is check if the item ID is a TM. Edit the Task_ItemContext_Sell function of src/item_menu.c:

-    if (ItemId_GetPrice(gSpecialVar_ItemId) == 0)
+    if (ItemId_GetPrice(gSpecialVar_ItemId) == 0 || ItemId_GetPocket(gSpecialVar_ItemId) == POCKET_TM_HM)
     {
         CopyItemName(gSpecialVar_ItemId, gStringVar2);
         StringExpandPlaceholders(gStringVar4, gText_CantBuyKeyItem);
         DisplayItemMessage(taskId, 1, gStringVar4, BagMenu_InitListsMenu);
     }

The last issue to take care of is that TMs that the player already has can be bought again for no effect. This step is technically optional, but it is nice to have that bit of polish.

We will first need to add a new string. Edit include/strings.h:

 extern const u8 gText_InBagVar1[];
 extern const u8 gText_Var1AndYouWantedVar2[];
 extern const u8 gText_HereYouGoThankYou[];
 extern const u8 gText_NoMoreRoomForThis[];
+extern const u8 gText_YouAlreadyHaveThis[];
 extern const u8 gText_ThankYouIllSendItHome[];
 extern const u8 gText_ThanksIllSendItHome[];
 extern const u8 gText_SpaceForVar1Full[];
 extern const u8 gText_ThrowInPremierBall[];

Edit src/strings.c:

 const u8 gText_ThanksIllSendItHome[] = _("Thanks!\nI'll send it to your PC at home.");
 const u8 gText_YouDontHaveMoney[] = _("You don't have enough money.{PAUSE_UNTIL_PRESS}");
 const u8 gText_NoMoreRoomForThis[] = _("You have no more room for this\nitem.{PAUSE_UNTIL_PRESS}");
+const u8 gText_YouAlreadyHaveThis[] = _("You already have this item.{PAUSE_UNTIL_PRESS}");
 const u8 gText_SpaceForVar1Full[] = _("The space for {STR_VAR_1} is full.{PAUSE_UNTIL_PRESS}");
 const u8 gText_AnythingElseICanHelp[] = _("Is there anything else I can help\nyou with?");
 const u8 gText_CanIHelpWithAnythingElse[] = _("Can I help you with anything else?");

Now to add the code that prevents the rebuying. Edit the Task_BuyMenu function of src/shop.c:

             if (!IsEnoughMoney(&gSaveBlock1Ptr->money, gShopDataPtr->totalCost))
             {
                 BuyMenuDisplayMessage(taskId, gText_YouDontHaveMoney, BuyMenuReturnToItemList);
             }
+            else if (ItemId_GetPocket(itemId) == POCKET_TM_HM && CheckBagHasItem(itemId, 1))
+            {
+                BuyMenuDisplayMessage(taskId, gText_YouAlreadyHaveThis, BuyMenuReturnToItemList);
+            }
             else
             {

And that's it!

Notes: Pokemon will replenish their PP if a TM move is forgotten and relearned.

Alternatively, see this commit for an implementation by Karathan that turns TMs and HMs into a bitfield, freeing up some saveblock space. This saves space, but is slightly more complex.

Clone this wiki locally