Skip to content

Instantly share code, notes, and snippets.

@EvilAsh25
Created February 17, 2017 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EvilAsh25/a880a09009fd8b5bbe78a9a5c5ce6ae3 to your computer and use it in GitHub Desktop.
Save EvilAsh25/a880a09009fd8b5bbe78a9a5c5ce6ae3 to your computer and use it in GitHub Desktop.
Dragon Warrior 2 Lua Script for testing the chances of who in the party is targeted
--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
midd = 0
cann = 0
moon = 0
miss = 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(30,170,'Total: '..total)
if(total ~= 0) then
gui.text(30,210,'Middenhall: '..midd..' ('..(math.floor(1000 * midd / (total)) / 10)..'%)')
gui.text(30,230,'Cannock : '..cann..' ('..(math.floor(1000 * cann / (total)) / 10)..'%)')
gui.text(30,250,'Moonbrooke: '..moon..' ('..(math.floor(1000 * moon / (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);
HP_Midd_start = memory.readbyte(0x063B);
HP_Cann_start = memory.readbyte(0x064D);
HP_Moon_start = memory.readbyte(0x065F);
--run the attack loop until we see someone's HP drop
while true do
Wait(math.random(5)+1); --wait a random number of frames
joypad.set({A=true}, 1)
Wait(1);
joypad.set({A=false}, 1)
if (memory.readbyte(0x063B) ~= HP_Midd_start) then break
elseif (memory.readbyte(0x064D) ~= HP_Cann_start) then break
elseif (memory.readbyte(0x065F) ~= HP_Moon_start) then break end
end
--read the variables we need to record data
HP_Midd = memory.readbyte(0x063B);
HP_Cann = memory.readbyte(0x064D);
HP_Moon = memory.readbyte(0x065F);
if HP_Midd < HP_Midd_start then
midd = midd + 1;
elseif HP_Cann < HP_Cann_start then
cann = cann + 1;
elseif HP_Moon < HP_Moon_start then
moon = moon + 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