diff options
-rw-r--r-- | Smashing-rocks-has-a-chance-to-contain-items.md | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/Smashing-rocks-has-a-chance-to-contain-items.md b/Smashing-rocks-has-a-chance-to-contain-items.md new file mode 100644 index 0000000..8926824 --- /dev/null +++ b/Smashing-rocks-has-a-chance-to-contain-items.md @@ -0,0 +1,100 @@ +In HGSS, XY and ORAS, it is possible to use Rock Smash and instead of encountering a Pokemon (or nothing...), you could also find an item from a small table of potential item drops. + +This tutorial will go over how to achieve that functionality in pokecrystal. (This feature was adapted from [Polished Crystal](https://github.com/Rangi42/polishedcrystal), huge thanks to Rangi!) + + + +## Contents +1. [Modify the overworld functionality](#1-modify-the-overworld-functionality) +2. [Adding the rock item code](#2-adding-the-rock-item-code) + + +## 1. Modify the overworld functionality + +First, we must edit the `RockSmashScript` within [engine/events/overworld.asm](../blob/master/engine/events/overworld.asm): + +```diff + callasm RockMonEncounter + readmem wTempWildMonSpecies +- iffalse .done ++ iffalse .no_battle + randomwildmon + startbattle + reloadmapafterbattle +-.done + end + ++.no_battle ++ callasm RockItemEncounter ++ iffalse .no_item ++ opentext ++ verbosegiveitem ITEM_FROM_MEM ++ closetext ++.no_item ++ end +``` + +These changes stop the `RockSmashScript` from ending if it doesn't find a Pokemon, jumping to `.no_battle` if the game does not startle a Pokemon hiding within the rock, and then calling `RockItemEncounter` to determine whether or not an item will be rolled. If no item is rolled, the script will jump to `.no_item`, ending the script and giving the player nothing. + +But `RockItemEncounter` has yet to be defined, so these changes on their own will not work. + + +## 2. Adding the rock item code +We have to define `RockItemEncounter`, and a suitable place to put it would be in [engine/events/checkforhiddenitems.asm](../blob/master/engine/events/checkforhiddenitems.asm) at the bottom of the script: + +```diff +.GetFarByte: + ld a, [wBuffer1] + call GetFarByte + inc hl + ret ++ ++RockItemEncounter: ++ ld hl, .RockItems ++ call Random ++.loop ++ sub [hl] ++ jr c, .ok ++rept 2 ++ inc hl ++endr ++ jr .loop ++.ok ++ ld a, [hli] ++ cp $ff ++ ld a, NO_ITEM ++ jr z, .done ++ ld a, [hli] ++.done ++ ld [wScriptVar], a ++ ret ++ ++.RockItems: ++ db 1, MAX_REVIVE ++ db 2, THICK_CLUB ++ db 4, NUGGET ++ db 6, STAR_PIECE ++ db 12, BIG_PEARL ++ db 18, ETHER ++ db 24, HARD_STONE ++ db 24, SOFT_SAND ++ db 48, PEARL ++ db 64, BRICK_PIECE ++ db 48, NO_ITEM ++ db -1 ++ +``` + +For starters, `RockItemEncounter` will load the `.RockItems` table into `hl`, and then call `Random`. `Random` is what the game uses to generate a lot of random statistics and variables, a good example would be the stats and specific Pokemon of a wild encounter. + +It rolls a chance to obtain an item, and if true, then `Random` will pick an item from the `.RockItems` table. The numerical values next to each item on the table is the percentage chance the player will receive said item, in this scenario a `MAX_REVIVE` has a chance of 1%. + +If `Random` rolls and lands on `NO_ITEM`(48%), then no item will be given, and the script will jump to `.done`, and back to executing the rest of the `RockSmashScript`. + +If `Random` rolls and lands on any item in the table, it loads it into memory and heads back to the `.no_battle` part of `RockSmashScript`, giving the player whatever item `Random` found. + + + +And there you have it, the player can now find items within smashed rocks! You can add your own items and chances by editing the `.RockItems` table in `checkhiddenitems.asm`, or even add something more complex like the Fossils/Old Amber from RBY. + +
\ No newline at end of file |