Advertisement
Abahbob

Superswimming Script

Oct 13th, 2014
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.03 KB | None | 0 0
  1. --[[
  2. states:
  3. 1: start
  4. 100: fastest
  5. 101: main superswim states
  6. 102: down 1 frame
  7. ]]
  8. fastestFrame = 10000000000
  9. fastestSpeed = 0
  10. function checkAir()
  11. checkFinished()
  12. print(tonumber(memory.readfloat(0xac0444))) --speed address, changes every map
  13.     if memory.readword(0x3bdc62) == 0 then --air address, shouldn't ever change
  14.         return false
  15.     end
  16.     if tonumber(memory.readfloat(0xac0444)) > -50 then --speed address, changes every map
  17.         return false
  18.     end
  19.     return true
  20. end
  21.  
  22. function keepSwimming()
  23.     while checkAir() do
  24.         joypad.joystick(128,128) -- neutral stick
  25.         emu.frameadvance()
  26.     end
  27. end
  28.  
  29.  
  30. function getToSpeed(x)
  31. while tonumber(memory.readfloat(0xac0444)) > -x do --speed address, changes every map
  32.         if math.mod(emu.framecount(), 2) ~= 0 then --if odd frame, stick down right
  33.             joypad.joystick(0,186) --right
  34.             emu.frameadvance()
  35.         else --if even frame, stick down left
  36.             joypad.joystick(255,186) --left
  37.             emu.frameadvance()
  38.         end
  39. end
  40. end
  41.  
  42. function getToFrame(x)
  43. while emu.framecount() < x do
  44.         if math.mod(emu.framecount(), 2) ~= 0 then --if odd frame, stick down right
  45.             joypad.joystick(0,186) --right
  46.             emu.frameadvance()
  47.         else --if even frame, stick down left
  48.             joypad.joystick(255,186) --left
  49.             emu.frameadvance()
  50.         end
  51. end
  52. end
  53.  
  54. function checkFinished()
  55. if tonumber(memory.readfloat(0xac0444)) > -1 then --speed address, changes every map
  56.     if emu.framecount() < fastestFrame then
  57.         savestate.save(100)
  58.         fastestFrame = emu.framecount()
  59.         end
  60.     end
  61. end
  62.  
  63. running = true
  64. while running do
  65.     if emu.framecount() == 900 then --load state late so it won't mess up audio or crash
  66.         savestate.load(1)
  67.         startFrame = emu.framecount() --get start frame for comparisons
  68.     end
  69.     if emu.framecount() > 1000 then getToSpeed(1450) end --use getToFrame or getToSpeed so you don't waste an hour of failing a ton of superswims
  70.     while (emu.framecount() > 1000) and running do --start after loading the first state   
  71.         if emu.framecount() > fastestFrame then running = false end
  72.         if math.mod(emu.framecount(), 2) ~= 0 then --if odd frame, stick down right
  73.             joypad.joystick(0,186) --right
  74.             emu.frameadvance()
  75.             savestate.save(101)
  76.             joypad.joystick(228,0) --first turn around, not straight to where you wannna go, based on previous input
  77.         else --if even frame, stick down left
  78.             joypad.joystick(255,186) --left
  79.             emu.frameadvance()
  80.             savestate.save(101)
  81.             joypad.joystick(10,0) --first turn around, not straight to where you wannna go, based on previous input
  82.         end
  83.         emu.frameadvance()
  84.         joypad.joystick(128,255) --opposite of direction you want to go
  85.         emu.frameadvance()
  86.         savestate.save(102)
  87.         keepSwimming() --first frame leaving
  88.         savestate.load(102)
  89.         joypad.joystick(128,255) --opposite of direction you want to go
  90.         emu.frameadvance()
  91.         emu.frameadvance()
  92.         -- savestate.save(103)
  93.         keepSwimming() --second frame leaving
  94.         savestate.load(101) --restart loop
  95.     end
  96. emu.frameadvance()
  97. if running == false then emu.message("OH MAN, WE IN THERE!") end --most important line in the code, do not remove.
  98. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement