Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- savestate.save("basestate.lel")
- memory.usememorydomain("System Bus")
- local PREDELAY = 1
- local LENGTH = 2
- local POSTDELAY = 3
- local inputs = {
- A = {0,0,0},
- B = {0,0,0},
- Right = {0,0,0},
- Left = {0,0,0},
- Up = {0,0,0},
- Down = {0,0,0}
- }
- function process()
- for button,vars in pairs(inputs) do
- if vars[PREDELAY] > 0 then
- vars[PREDELAY] = vars[PREDELAY] - 1
- elseif vars[LENGTH] > 0 then
- vars[LENGTH] = vars[LENGTH] - 1
- joypad.set({[button]=true})
- elseif vars[POSTDELAY] > 0 then
- vars[POSTDELAY] = vars[POSTDELAY] - 1
- end
- end
- end
- function input(button,predelay,length,postdelay)
- if inputs[button][PREDELAY] > 0
- or inputs[button][LENGTH] > 0
- or inputs[button][POSTDELAY] > 0 then
- return
- end
- inputs[button][PREDELAY] = predelay
- inputs[button][LENGTH] = length
- inputs[button][POSTDELAY] = postdelay
- end
- local fight_menu = 193
- function get_battle_pos()
- return memory.read_u8(0xcc30)
- end
- function get_igtframes()
- return memory.read_u8(0xda40)*216000 + memory.read_u8(0xda42)*3600 + memory.read_u8(0xda43)*60 + memory.read_u8(0xda44)
- end
- while true do
- local spindir = 0
- while true do
- if memory.read_u8(0xd056) ~= 0 then
- break
- end
- if emu.framecount() % 4 == 0 then
- if spindir == 0 then
- input("Down",0,2,0)
- elseif spindir == 1 then
- input("Right",0,2,0)
- elseif spindir == 2 then
- input("Up",0,2,0)
- elseif spindir == 3 then
- input("Left",0,2,0)
- end
- spindir = (spindir + 1) % 4
- end
- process()
- emu.frameadvance()
- end
- local frameCount = emu.framecount()
- local fc2 = get_igtframes()
- local battle_state = 0
- local battlemon = memory.read_u8(0xcfe4)
- while true do
- if memory.read_u8(0xd056) == 0 then
- break
- end
- if battlemon == 0 and memory.read_u8(0xcfe4) ~= 0 then
- battlemon = memory.read_u8(0xcfe4)
- end
- local pos = get_battle_pos()
- if pos == fight_menu then
- joypad.set({Left=nil, Right=true, Down=true, A=nil})
- else
- if battle_state == 0 then
- joypad.set({Right=nil, Down=nil, A=true})
- else
- joypad.set({Right=nil, Down=nil, A=nil})
- end
- battle_state = 1 - battle_state
- end
- emu.frameadvance()
- end
- local intermediate = true
- local movecount = 0
- local movingdown = false
- while true do
- if memory.read_u8(0xcfc4) ~= 0 and intermediate then
- intermediate = false
- print("encounter with "..battlemon.." lasted "..(emu.framecount()-frameCount).." frames or "..(get_igtframes()-fc2).." igtframes")
- end
- if memory.read_u8(0xd056) ~= 0 then
- break
- end
- if memory.read_u8(0xd363) == 0 then
- -- move up
- if movingdown then
- movecount = movecount + 1
- if movecount == 4 then
- break
- end
- movingdown = false
- end
- joypad.set({B=true,Right=true})
- emu.frameadvance()
- else
- if movingdown == false then
- movecount = movecount + 1
- if movecount == 4 then
- break
- end
- movingdown = true
- end
- joypad.set({B=true,Left=true})
- emu.frameadvance()
- end
- end
- if memory.read_u8(0xd056) == 0 then
- for i=1,25 do
- emu.frameadvance()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement