Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function encounterCheck() {
- var area = loadByte(0x02000214);
- var subarea = loadByte(0x02000215);
- var steps = loadWord(0x020003F4);
- var prev = loadWord(0x020003F8);
- // If area is an overworld area, fail
- if (area < 0x80) {
- return false;
- }
- area -= 0x80;
- // If steps since last check < 64, fail
- if (steps - prev < 0x40) {
- return false;
- }
- prev = steps;
- storeWord(prev, 0x020003F8);
- // Get the encounter rate curve index associated with this area
- // Lower index = steeper curve = encounter rate rises more quickly
- var curve = loadByte(0x080099BC + area * 0x10 + subarea);
- // Count roughly equals number of encounter checks before this one
- var count = (steps / 0x40);
- // Rate no longer increases after 16 encounter checks
- if (count >= 0x11) {
- count = 0x10;
- }
- // Load the current encounter rate for this check
- var rate = loadByte(0x08009934 + count * 8 + curve);
- if (rand(0x20) >= rate) {
- return false;
- } else {
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement