diff options
| author | Idain <luiscarlosholguinperez@outlook.com> | 2021-11-16 21:17:58 -0400 |
|---|---|---|
| committer | Idain <luiscarlosholguinperez@outlook.com> | 2021-11-16 21:17:58 -0400 |
| commit | 8564a8c67b3bf5026c8e5376bece0261949f20c6 (patch) | |
| tree | 0ab6d5a7aa61bbafb866a2fc8cf360fdeed6abfc | |
| parent | 2701784311542c2b5af3d8c9f72f859374bbab56 (diff) | |
Use the "percent" symbol instead of plain bytes.
| -rw-r--r-- | Smashing-rocks-has-a-chance-to-contain-items.md | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/Smashing-rocks-has-a-chance-to-contain-items.md b/Smashing-rocks-has-a-chance-to-contain-items.md index 2bda45f..f9bba07 100644 --- a/Smashing-rocks-has-a-chance-to-contain-items.md +++ b/Smashing-rocks-has-a-chance-to-contain-items.md @@ -69,20 +69,21 @@ We have to define `RockItemEncounter`, and a suitable place to put it would be i + 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 2 percent, MAX_REVIVE ++ db 2 percent, THICK_CLUB ++ db 2 percent, NUGGET ++ db 2 percent, STAR_PIECE ++ db 4 percent, BIG_PEARL ++ db 8 percent, ETHER ++ db 10 percent, HARD_STONE ++ db 10 percent, SOFT_SAND ++ db 20 percent, PEARL ++ db 25 percent, BRICK_PIECE + db -1 ``` -For starters, `RockItemEncounter` will load the `.RockItems` table into `hl`, and then call `Random`, which will load a random byte (i.e., a value between 0 and 255) in `a`. With this random value generated, it performs comparisons against the probabilities encoded in the `.RockItems` table, picking an item with the listed odds (out of 256: in the example, there's a 1 in 256 chance of getting a Max Revive, and a 64 in 256 (or 1 in 4) chance of getting a Brick Piece). +For starters, `RockItemEncounter` will load the `.RockItems` table into `hl`, and then call `Random`, which will load a random byte (i.e., a value between 0 and 255) in `a`. With this random value generated, it performs comparisons against the probabilities encoded in the `.RockItems` table, picking an item with the listed odds (out of 256: in the example, there's a 2 percent [or 5 in 256] chance of getting a Max Revive, and a 25 percent [or 64 in 256] chance of getting a Brick Piece). For more info about how the `percent` symbol works, go to [macros/data.asm](https://github.com/pret/pokecrystal/blob/master/macros/data.asm). + Since the probabilities in the table add up to less than 256, the `db -1` line at the end indicates the end of the table. If this line is reached, the function will load a 0 (which represents `NO_ITEM`), indicating that the rocks didn't contain an item. If this is the case, the `iffalse .no_item` line in the script will skip giving an item to the player. Otherwise, the selected item, which will have already been loaded into the script variable (`wScriptVar`) by the function, will be awarded to the player by the script. 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. |
