Advertisement
biosp4rk

Metroid Fusion - Eyedoor Script

Apr 20th, 2016
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.22 KB | None | 0 0
  1. rns = { 13, 2, 6, 8, 7, 9, 14, 10, 2, 4, 14, 4, 12, 15, 13, 12, 11, 1, 3, 15, 0, 6, 7, 8, 11, 5, 0, 3, 5, 1, 9, 10 }
  2. timers = { }
  3.  
  4. function Calculate(num, counter, index, enemyX, enemyY)
  5.     local frame
  6.     local enRN
  7.    
  8.     -- determine when it will open
  9.     if num == 0 then
  10.         timers[0] = memory.readbyte(0x300016E + index*56)
  11.     else
  12.         frame = counter + timers[num-1]
  13.         enRN = rns[((frame + bit.rshift(frame, 4) + index + enemyX + enemyY) % 32) + 1]
  14.         timers[num] = timers[num-1] + 61 + enRN * 4
  15.     end
  16.    
  17.     -- determine if it will shoot
  18.     frame = counter + timers[num] + 7
  19.     enRN = rns[((frame + bit.rshift(frame, 4) + index + enemyX + enemyY) % 32) + 1]
  20.    
  21.     -- display
  22.     gui.text(3, 19 + num*8, timers[num])
  23.    
  24.     if enRN <= 6 then
  25.         gui.text(20, 19 + num*8, "O", "green")
  26.     else
  27.         gui.text(20, 19 + num*8, "X", "red")
  28.     end
  29. end
  30.  
  31. while true do
  32.  
  33.     local index = -1
  34.     local pose
  35.    
  36.     for i=0,23 do
  37.         local id = memory.readbyte(0x300015D + i*56)
  38.         if id >= 0x8F and id <= 0x9E then
  39.             index = i
  40.             pose = memory.readbyte(0x3000164 + index*56)
  41.             break
  42.         end
  43.     end
  44.    
  45.     if index ~= -1 and pose < 0x58 then
  46.         -- display eyedoor activation region
  47.         local cameraX, cameraY = memory.readword(0x3001228), memory.readword(0x300122A)
  48.         local enemyX, enemyY = memory.readword(0x3000144 + index*56), memory.readword(0x3000142 + index*56)
  49.  
  50.         local xStart = bit.arshift(enemyX - 0x1C0 - cameraX, 2)
  51.         local yStart = bit.arshift(enemyY - 0x80 - cameraY, 2)
  52.         local xEnd = bit.arshift(enemyX + 0x1C0 - cameraX, 2)
  53.         local yEnd = bit.arshift(enemyY + 0x80 - cameraY, 2)
  54.    
  55.         gui.box(xStart, yStart, xEnd, yEnd, "#00F00020", "#20C020")
  56.    
  57.         -- check if in range
  58.         local samusX, samusY = memory.readword(0x300125A), memory.readword(0x300125C)
  59.         if math.abs(samusX - enemyX) < 0x1C0 and math.abs(samusY - enemyY) < 0x80 then
  60.             gui.text(3, 11, "In", "green")
  61.         else
  62.             gui.text(3, 11, "Out", "red")
  63.         end
  64.    
  65.         if pose >= 0x18 and pose <= 0x20 then
  66.             -- eyedoor is open
  67.             local timer = memory.readbyte(0x300016E + index*56)
  68.             gui.text(3, 19, timer)
  69.         else
  70.             -- calculate when eyedoor will open
  71.             local counter = memory.readword(0x3000002)
  72.             for n=0,3 do
  73.                 Calculate(n, counter, index, enemyX, enemyY)
  74.             end
  75.         end
  76.     end
  77.    
  78.     vba.frameadvance()
  79.  
  80. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement