Created
February 16, 2017 23:47
-
-
Save EvilAsh25/2789c8ca525782ecce2a3c32ab614032 to your computer and use it in GitHub Desktop.
Dragon Warrior 2 Lua Script for testing Dodge chance
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
--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 | |
dodge = 0 | |
hit = 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,'Dodge: '..dodge..' ('..(math.floor(1000 * dodge / (total)) / 10)..'%)') | |
gui.text(30,230,'Hit : '..hit..' ('..(math.floor(1000 * hit / (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); | |
--run the attack loop | |
for i=0,10 do | |
Wait(math.random(5)+1); --wait a random number of frames | |
joypad.set({A=true}, 1) | |
end | |
--wait for the battle to resolve | |
Wait(200); | |
--read the variables we need to record data | |
HP_Midd = memory.readbyte(0x063B); | |
if HP_Midd < HP_Midd_start then | |
--Middenhall was hit | |
hit = hit + 1; | |
else | |
--Middenhall Dodged | |
dodge = dodge + 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