This has been driving me nuts for a while so:
Language: lua
memory.usememorydomain("IWRAM")
local frame_start = emu.framecount()
function waitframe(frame)
while (frame >= 0) do
emu.frameadvance()
frame = frame-1
end
end
--[[Start the script as you select an opponent to attack
Algorithim:
1. Record current frame
2. Make a savestate
3. Press "A"
4. Advance 100 frames
5. Check to see if attack hit/missed. If missed, skip to step 7. If hit proceed to next step
6. Check if it had critical hit. If so stop. If not, continue. Don't check if move is ID 0xC4
7. Load the state
8. Advance 1 frame
9. Repeat from step 2
]]--
while true do
local frame_now = emu.framecount()
local frame_dif = 0 --difference between this frame and start frame
if (frame_dif ~= (frame_now - frame_start)) then
savestate.saveslot(1)
end
joypad.set({A = 1})
emu.frameadvance()
waitframe(500)
console.log("Reached 1")
--if memory.readbyte(0x2C14) == 61 then
if memory.readbyte(0x2A0B) > 0 then --damage you deal
break
else
frame_dif = frame_dif + 1
savestate.loadslot(1)
console.log("Dif"..(frame_now - frame_start))
console.log("Frame now: "..frame_now)
console.log("Reached 2")
end
emu.frameadvance()
end
Specifically this part:
else
frame_dif = frame_dif + 1
savestate.loadslot(1)
console.log("Dif"..(frame_now - frame_start))
console.log("Frame now: "..frame_now)
console.log("Reached 2")
end
Maybe I'm going nuts, or just my computer, but I swear whenever I remove or comment out the console sections, savestate.loadslot(1) never triggers. It oddly works fine (ignoring the console spam) if I add it back however. Also please ignore the comment on critical hits; I haven't implemented it yet.