Advertisement
biosp4rk

Zero Mission - Metroid Script

Mar 30th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.66 KB | None | 0 0
  1. -- Metroids do not spawn until they are on screen. They do not directly use Samus's X or Y position.
  2. -- When a Metroid starts spawning, it is given a delay between 1 and 61 frames before it will finish spawning.
  3. -- The delay is calculated by: EnemyRN * 4 + 1
  4. -- When a Metroid is inactive, the script displays the next five times a Metroid will be given the minimum amount of delay (which is 1 frame).
  5. -- When a Metroid is active, the script displays the delay it was given when it started spawning, as well as the timer used for the delay. You can use the timer to verify that the calculated delay was correct.
  6. -- The timer is used for other things once the Metroid has finished spawning, so you can ignore its value.
  7. -- Note: the delay is not calculated correctly for Metroids that are already spawning when you enter the room. You'll have to use the timer value to find a favorable delay.
  8.  
  9. 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 }
  10. wait = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
  11.  
  12. while true do
  13.     local counter1 = memory.readbyte(0x3000C77) + 1
  14.     local counter2 = memory.readword(0x3000002) + 1
  15.     local number = 0
  16.    
  17.     for i=0,23 do
  18.         if memory.readbyte(0x30001C9 + i*56) == 0x64 then
  19.             -- check if metroid is active
  20.             local status = memory.readbyte(0x30001AC + i*56)
  21.             local pose = memory.readbyte(0x30001D0 + i*56)
  22.            
  23.             if pose == 1 and AND(status, 2) == 0 then
  24.                 gui.text(3, 11 + number * 8, "Inactive", "red")
  25.                
  26.                 -- calculate when metroid will spawn
  27.                 local timer1 = counter1
  28.                 local timer2 = counter2
  29.                 local enemyX, enemyY = memory.readword(0x30001B0 + i*56), memory.readword(0x30001AE + i*56)
  30.                 local addVal = i + enemyX + enemyY
  31.                 local enRN = rns[((timer1 + 1 + bit.rshift(timer2 + 1, 4) + addVal) % 32) + 1]
  32.                 wait[i] = enRN * 4 + 1
  33.                
  34.                 -- find next 5 times metroid will spawn as fast as possible
  35.                 local delay = -1
  36.                 for j=0,4 do
  37.                     enRN = -1
  38.                     while enRN ~= 0 do
  39.                         enRN = rns[((timer1 + bit.rshift(timer2, 4) + addVal) % 32) + 1]
  40.                         timer1 = timer1 + 1
  41.                         timer2 = timer2 + 1
  42.                         delay = delay + 1
  43.                     end
  44.                     gui.text(39 + j*12, 11 + number*8, delay)
  45.                     timer1 = timer1 + 1
  46.                     timer2 = timer2 + 1
  47.                     delay = delay + 1
  48.                 end
  49.             else
  50.                 gui.text(3, 11 + number * 8, "Active", "green")
  51.                 -- display how much the metroid's spawn was delayed
  52.                 gui.text(31, 11 + number * 8, wait[i])
  53.                 -- display timer for the delay
  54.                 gui.text(42, 11 + number * 8, memory.readword(0x30001D8 + i*56))
  55.             end
  56.  
  57.             number = number + 1
  58.         else
  59.             wait[i] = 0
  60.         end
  61.     end
  62.    
  63.     vba.frameadvance()
  64.  
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement