summaryrefslogtreecommitdiff
path: root/Show-move-names-when-you-receive-a-TM-or-HM.md
blob: d818308e858b930db89c0e2730a8dcd45d860265 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
In Gen 2, acquiring a TM or HM would just say "*PLAYER* received TM##." when you're given one, or "*PLAYER* found TM##!" when you take an item ball or hidden item. Gen 3 made these messages more helpful by showing the name of the move that the TM/HM teaches. This tutorial will implement that little quality of life feature.


## Contents

1. [Define a routine to append move names after TM/HM item names](#1-define-a-routine-to-append-move-names-after-tmhm-item-names)
2. [Use the new routine in all cases where you acquire an item](#2-use-the-new-routine-in-all-cases-where-you-acquire-an-item)
3. [Update the hard-coded TM24 messages](#3-update-the-hard-coded-tm24-messages)


## 1. Define a routine to append move names after TM/HM item names

Edit [engine/overworld/scripting.asm](../blob/master/engine/overworld/scripting.asm):

```diff
+AppendTMHMMoveName::
+; a = item ID
+	ld a, [wNamedObjectIndex]
+	cp TM01
+	ret c
+; save item name buffer
+	push de
+; a = TM/HM number
+	ld c, a
+	farcall GetTMHMNumber
+	ld a, c
+; a = move ID
+	ld [wTempTMHM], a
+	predef GetTMHMMove
+	ld a, [wTempTMHM]
+; wStringBuffer1 = move name
+	ld [wNamedObjectIndex], a
+	call GetMoveName
+; hl = item name buffer
+	pop hl
+; append wStringBuffer1 to item name buffer
+	ld [hl], " "
+	inc hl
+	ld de, wStringBuffer1
+	jp CopyName2
```

This routine assumes that you've loaded the item ID in `[wNamedObjectIndex]`, and the *end* of the item name buffer in `de`. Then it converts the item ID to the corresponding TM/HM number, then converts that to the corresponding move ID, gets the name of the move, and appends that to the item name buffer (which is why we started with the end of the buffer).

(The move name is written to `wStringBuffer1`, so you can't also use that for the TM/HM name. You'd end up with issues like TM01 being called "DYNADYNAMICPUNCH".)


## 2. Use the new routine in all cases where you acquire an item

Edit [engine/overworld/scripting.asm](../blob/master/engine/overworld/scripting.asm) again:

```diff
 Script_verbosegiveitem:
 ; script command 0x9e
 ; parameters: item, quantity

 	call Script_giveitem
 	call CurItemName
 	ld de, wStringBuffer1
 	ld a, STRING_BUFFER_4
 	call CopyConvertedText
+	ld de, wStringBuffer4 + STRLEN("TM##")
+	call AppendTMHMMoveName
 	ld b, BANK(GiveItemScript)
 	ld de, GiveItemScript
 	jp ScriptCall
```

```diff
 Script_verbosegiveitemvar:
 ; script command 0x9f
 ; parameters: item, var

 	call GetScriptByte
 	cp ITEM_FROM_MEM
 	jr nz, .ok
 	ld a, [wScriptVar]
 .ok
 	ld [wCurItem], a
 	call GetScriptByte
 	call GetVarAction
 	ld a, [de]
 	ld [wItemQuantityChange], a
 	ld hl, wNumItems
 	call ReceiveItem
 	ld a, TRUE
 	jr c, .ok2
 	xor a
 .ok2
 	ld [wScriptVar], a
 	call CurItemName
 	ld de, wStringBuffer1
 	ld a, STRING_BUFFER_4
 	call CopyConvertedText
+	ld de, wStringBuffer4 + STRLEN("TM##")
+	call AppendTMHMMoveName
 	ld b, BANK(GiveItemScript)
 	ld de, GiveItemScript
 	jp ScriptCall
```

Edit [engine/events/misc_scripts.asm](../blob/master/engine/events/misc_scripts.asm):

```diff
 FindItemInBallScript::
 	callasm .TryReceiveItem
 	...

 .TryReceiveItem:
 	xor a
 	ld [wScriptVar], a
 	ld a, [wItemBallItemID]
 	ld [wNamedObjectIndex], a
 	call GetItemName
 	ld hl, wStringBuffer3
 	call CopyName2
+	ld de, wStringBuffer3 + STRLEN("TM##")
+	farcall AppendTMHMMoveName
 	ld a, [wItemBallItemID]
 	ld [wCurItem], a
 	ld a, [wItemBallQuantity]
 	ld [wItemQuantityChange], a
 	ld hl, wNumItems
 	call ReceiveItem
 	ret nc
 	ld a, $1
 	ld [wScriptVar], a
 	ret
```

Edit [engine/events/hidden_item.asm](../blob/master/engine/events/hidden_item.asm):

```diff
 HiddenItemScript::
 	opentext
 	readmem wHiddenItemID
 	getitemname STRING_BUFFER_3, USE_SCRIPT_VAR
+	callasm .append_tmhm_move_name
 	writetext .found_text
 	giveitem ITEM_FROM_MEM
 	iffalse .bag_full
 	callasm SetMemEvent
 	specialsound
 	itemnotify
 	sjump .finish

 .bag_full
 	buttonsound
 	writetext .no_room_text
 	waitbutton

 .finish
 	closetext
 	end
+
+.append_tmhm_move_name
+	ld de, wStringBuffer3 + STRLEN("TM##")
+	farcall AppendTMHMMoveName
+	ret
```


## 3. Update the hard-coded TM13 and TM24 messages

Edit [maps/Route39Farmhouse.asm](..blob/master/maps/Route39Farmhouse.asm):

```diff
Text_ReceivedTM13:
	text "<PLAYER> received"
-	line "TM13."
+	line "TM13 SNORE."
	done
```

Edit [maps/BlackthornGym1F.asm](../blob/master/maps/BlackthornGym1F.asm):

```diff
 BlackthornGymText_ReceivedTM24:
 	text "<PLAYER> received"
-	line "TM24."
+	line "TM24 DRAGONBREATH."
 	done
```

And edit [maps/DragonsDenB1F.asm](../blob/master/maps/DragonsDenB1F.asm):

```diff
 Text_ReceivedTM24:
 	text "<PLAYER> received"
-	line "TM24."
+	line "TM24 DRAGONBREATH."
 	done
```

Now we'll see the move name along with the TM/HM number when it's first acquired.

![Screenshot](screenshots/tm-move-names.png)

TODO: Show move names when buying TMs.