Skip to content

Instantly share code, notes, and snippets.

@EvilAsh25
Created January 21, 2019 16:37
Show Gist options
  • Save EvilAsh25/0c7d6c6d06587757eec51b430307c35e to your computer and use it in GitHub Desktop.
Save EvilAsh25/0c7d6c6d06587757eec51b430307c35e to your computer and use it in GitHub Desktop.
DW2 Run Chance Lua
--This script is designed to work with Bizhawk
--This script assumes a pre-made state on Quicksave Slot 0
--Set the correct memory domain
memory.usememorydomain("System Bus")
--define variables
run = 0
fail = 0
total = 0
save_state_slot = 0 -- which quickload slot to load from
rng1 = 0
rng2 = 0
--Wait function for advancing 1 frame and displaying results on the screen
function Wait(number)
for i=0,number-1 do
emu.frameadvance()
gui.text(10,228,'Total: '..total)
--gui.text(350,40,'Total: '..total)
if(total ~= 0) then
gui.text(10,244,'Run : '..run..' ('..(math.floor(1000 * run / (total)) / 10)..'%)')
gui.text(10,260,'Fail: '..fail..' ('..(math.floor(1000 * fail / (total)) / 10)..'%)')
--gui.text(350,60,'Run : '..run..' ('..(math.floor(1000 * run / (total)) / 10)..'%)')
--gui.text(350,80,'Fail: '..fail..' ('..(math.floor(1000 * fail / (total)) / 10)..'%)')
end
end
end
--the main loop, this runs forever
while true do
--load the savestate
savestate.loadslot(save_state_slot);
--load the previous rng values back into the state
memory.writebyte(0x0032,rng1);
memory.writebyte(0x0033,rng2);
Wait(math.random(5)+1); --wait a random number of frames
joypad.set({A=true}, 1)
--wait for the run to resolve
Wait(150);
--read the variables we need to record data
value = memory.readbyte(0x068F);
if value ~= 0 then
--Success
run = run + 1;
else
--Fail
fail = fail + 1;
end
total = total + 1;
--save the RNG values for the next loop
rng1 = memory.readbyte(0x0032)
rng2 = memory.readbyte(0x0033)
Wait(1);
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment