Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- states:
- 1: start
- 100: fastest
- 101: main superswim states
- 102: down 1 frame
- ]]
- targetX = 100028.0078
- targetZ = 26550.85938
- earliestArrivalFrame = 10000000000
- function getX()
- return tonumber(memory.readfloat(0x3b7af4))
- end
- function getZ()
- return tonumber(memory.readfloat(0x3b7afc))
- end
- function getTargetX()
- return targetX
- end
- function getTargetZ()
- return targetZ
- end
- function getDistance()
- local x = getX() - getTargetX()
- local z = getZ() - getTargetZ()
- return math.sqrt(x * x + z * z)
- end
- function getAir()
- return tonumber(memory.readword(0x3bdc62))
- end
- function getSpeed()
- return tonumber(memory.readfloat(0xAD1220))
- end
- function getFrame()
- return emu.framecount()
- end
- function getArrivalFrame()
- local d = getDistance()
- local v = getSpeed()
- local t0 = getFrame()
- local air = getAir()
- local x = -4 * d + (v * v)
- print(v)
- if x < 0 then
- return t0 + 200000
- end
- local swimFrames = 0.5 * (v - math.sqrt(x))
- if air < swimFrames then
- return t0 + 200000
- else
- return t0 + swimFrames
- end
- end
- local startframe = getFrame()
- while getAir() > 0 do
- if (getFrame() > startframe + 300) then
- -- Save the state so we can use it for the next frame
- savestate.save(101)
- -- Release for 2 frames
- joypad.joystick(128,0)
- emu.frameadvance()
- joypad.joystick(128,128)
- emu.frameadvance()
- -- Calculate arrival frame
- local arrivalFrame = getArrivalFrame()
- --print(getDistance())
- -- Check if it's earlier
- if arrivalFrame < earliestArrivalFrame then
- earliestArrivalFrame = arrivalFrame
- -- Save the state cause it's the best one so far
- savestate.save(100)
- end
- -- Reload the state for the current frame
- savestate.load(101)
- end
- -- Charge the superswim by flipping the analogue stick
- if math.mod(getFrame(), 2) ~= 0 then --if odd frame, stick down right
- joypad.joystick(0,66)
- else --if even frame, stick down left
- joypad.joystick(255,66)
- end
- -- Go to the next frame
- emu.frameadvance()
- end
Advertisement
Add Comment
Please, Sign In to add comment