CryZe

Wind Waker - Superswim Script

Oct 16th, 2014
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.02 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. targetX = 100028.0078
  9. targetZ = 26550.85938
  10. earliestArrivalFrame = 10000000000
  11.  
  12. function getX()
  13.     return tonumber(memory.readfloat(0x3b7af4))
  14. end
  15.  
  16. function getZ()
  17.     return tonumber(memory.readfloat(0x3b7afc))
  18. end
  19.  
  20. function getTargetX()
  21.     return targetX
  22. end
  23.  
  24. function getTargetZ()
  25.     return targetZ
  26. end
  27.  
  28. function getDistance()
  29.     local x = getX() - getTargetX()
  30.     local z = getZ() - getTargetZ()
  31.    
  32.     return math.sqrt(x * x + z * z)
  33. end
  34.  
  35. function getAir()
  36.     return tonumber(memory.readword(0x3bdc62))
  37. end
  38.  
  39. function getSpeed()
  40.     return tonumber(memory.readfloat(0xAD1220))
  41. end
  42.  
  43. function getFrame()
  44.     return emu.framecount()
  45. end
  46.  
  47. function getArrivalFrame()
  48.     local d = getDistance()
  49.     local v = getSpeed()
  50.     local t0 = getFrame()
  51.     local air = getAir()
  52.    
  53.     local x = -4 * d + (v * v)
  54.     print(v)
  55.    
  56.     if x < 0 then
  57.         return t0 + 200000
  58.     end
  59.    
  60.     local swimFrames = 0.5 * (v - math.sqrt(x))
  61.    
  62.     if air < swimFrames then
  63.         return t0 + 200000
  64.     else
  65.         return t0 + swimFrames
  66.     end
  67. end
  68.  
  69. local startframe = getFrame()
  70. while getAir() > 0 do
  71.     if (getFrame() > startframe + 300) then
  72.         -- Save the state so we can use it for the next frame
  73.         savestate.save(101)
  74.  
  75.         -- Release for 2 frames
  76.         joypad.joystick(128,0)
  77.         emu.frameadvance()
  78.         joypad.joystick(128,128)
  79.         emu.frameadvance()
  80.        
  81.         -- Calculate arrival frame
  82.         local arrivalFrame = getArrivalFrame()
  83.         --print(getDistance())
  84.        
  85.         -- Check if it's earlier
  86.         if arrivalFrame < earliestArrivalFrame then
  87.             earliestArrivalFrame = arrivalFrame
  88.             -- Save the state cause it's the best one so far
  89.             savestate.save(100)
  90.         end
  91.        
  92.         -- Reload the state for the current frame
  93.         savestate.load(101)
  94.     end
  95.    
  96.     -- Charge the superswim by flipping the analogue stick
  97.     if math.mod(getFrame(), 2) ~= 0 then --if odd frame, stick down right
  98.         joypad.joystick(0,66)
  99.     else --if even frame, stick down left
  100.         joypad.joystick(255,66)
  101.     end
  102.    
  103.     -- Go to the next frame
  104.     emu.frameadvance()
  105. end
Advertisement
Add Comment
Please, Sign In to add comment