Created
January 21, 2019 16:36
-
-
Save EvilAsh25/c8b8ab48cc029523fc392277def83f60 to your computer and use it in GitHub Desktop.
DW2 Encounter Rate Lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--For Bizhawk | |
--Set the correct memory domain | |
memory.usememorydomain("System Bus") | |
--emu.speedmode("maximum") | |
save_state_slot = 0 | |
trials = 0 | |
encounters = 0 | |
function Wait(number) | |
--Actually a "wait counter" but all waits are for one frame except for the one where I want to delay to show the frame counter | |
for i=0,number-1 do | |
emu.frameadvance() | |
gui.text(10,10, 'Encounters: '..encounters..'/'..trials..' ('..(math.floor(encounters*10000/trials)/100)..'%)') | |
end | |
end | |
while trials < 100000 do | |
savestate.loadslot(save_state_slot); | |
--Throw random values into the random RNG seed (two bytes) and the counter and the thing next to the counter | |
memory.writebyte(0x0032,math.random(0xFF)) | |
memory.writebyte(0x0033,math.random(0xFF)) | |
Wait(math.random(0x0F)) | |
savestate.saveslot(save_state_slot); | |
--Coordinates are {0x28},{0x29} | |
starting_loc = memory.readbyte(0x29) | |
--for i=0,36 do --more than enough frames to take two steps | |
for i=0,86 do --more than enough frames to take two steps in swamp | |
joypad.set({Down=true}, 1) | |
Wait(1) | |
if memory.readbyte(0x29) == starting_loc + 2 then | |
break | |
end | |
end | |
if memory.readbyte(0x29) == starting_loc + 1 then | |
encounters = encounters + 1 | |
end | |
trials = trials + 1 | |
Wait(1) | |
end | |
while true do | |
Wait(1) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment