Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dragon Warrior 4 Lua Script for testing the Demon Hammer
--This script is designed to work with Bizhawk
--This script assumes a pre-made state on Quicksave Slot 0, with 1 enemy,
--Ragnar the only alive party member, and the Demon Hammer equipped
--Set the correct memory domain
memory.usememorydomain("System Bus")
--define variables
wins = 0
miss = 0
total = 0
save_state_slot = 0 -- which quickload slot to load from
rng1 = 0
rng2 = 0
rng3 = 0
--Wait function for advancing 1 frame and displaying results on the screen
function Wait(number)
for i=0,number-1 do
emu.frameadvance()
--display the enemy HP
gui.text(120,150,'HP: '..(memory.readbyte(0x727E) + memory.readbyte(0x727F) * 256))
gui.text(30,170,'Total: '..total)
if(total ~= 0) then
gui.text(30,210,'Crit: '..wins..' ('..(math.floor(1000 * wins / (total)) / 10)..'%)')
gui.text(30,230,'Miss: '..miss..' ('..(math.floor(1000 * miss / (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(0x0012,rng1);
memory.writebyte(0x0013,rng2);
memory.writebyte(0x050D,rng3);
--run the attack loop
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)
--0x43 means that Ragnar attacked
if (memory.readbyte(0x7324) == 0x43) then break end
end
--wait for the attack to resolve
Wait(60);
--read the variables we need to record data
HP = memory.readbyte(0x727E);
if HP == 0 then
--crit
wins = wins + 1;
else
--miss
miss = miss + 1;
end
total = total + 1;
--save the RNG values for the next loop
rng1 = memory.readbyte(0x0012)
rng2 = memory.readbyte(0x0013)
rng3 = memory.readbyte(0x050D)
Wait(1);
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.