Advertisement
Guest User

MMZX enemy drops lua

a guest
May 6th, 2015
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.20 KB | None | 0 0
  1. health_addr = 0x0214F7B2
  2. Hx_energy_addr = 0x0214F895
  3. money_addr = 0x0214F870
  4. lives_addr = 0x0214F86C
  5. pItem = "big health"
  6. nItem = "void"
  7. count = 0
  8. switch = 0
  9. ID = 3
  10. loop = {4, 9, 34, 3, 9, 4, 9, 0}
  11. loopC = {0, 0, 0, 0, 0, 0, 0, 0}
  12. loops = {}
  13.  
  14. function writeHealth(amount)
  15.     memory.writebyte(health_addr, amount)
  16. end
  17.  
  18. function readHealth()
  19.     return memory.readbyte(health_addr)
  20. end
  21.  
  22. function writeEnergy(amount)
  23.     memory.writebyte(Hx_energy_addr, amount)
  24. end
  25.  
  26. function readEnergy()
  27.     return memory.readbyte(Hx_energy_addr)
  28. end
  29.  
  30. function writeMoney(amount)
  31.     memory.writeword(money_addr, amount)
  32. end
  33.  
  34. function readMoney()
  35.     return memory.readword(money_addr)
  36. end
  37.  
  38. function writeLives(amount)
  39.     memory.writebyte(lives_addr, amount)
  40. end
  41.  
  42. function readLives()
  43.     return memory.readbyte(lives_addr)
  44. end
  45.  
  46. function cheatRNG(value)
  47.     memory.writedword(0x02108790, value)
  48. end
  49.  
  50. function initValues()
  51.     writeHealth(1)
  52.     writeEnergy(0)
  53.     writeMoney(0)
  54.     writeLives(0)
  55. end
  56.  
  57. function controlValues()
  58.     local curHealth = readHealth()
  59.     local curEnergy = readEnergy()
  60.     local curMoney = readMoney()
  61.     local curLives = readLives()
  62.     local item = "Nothing"
  63.     ID = 3
  64.     if curHealth == 5 then
  65.         item = "small health"
  66.         ID = 2
  67.     elseif curHealth > 5 then
  68.         item = "big health"
  69.         ID = 1
  70.     end
  71.     if curEnergy == 4 then
  72.         item = "small energy"
  73.         ID = 5
  74.     elseif curEnergy > 4 then
  75.         item = "big energy"
  76.         ID = 4
  77.     end
  78.     if curMoney == 4 then
  79.         item = "small money"
  80.         ID = 7
  81.     elseif curMoney > 4 then
  82.         item = "big money"
  83.         ID = 6
  84.     end
  85.     if curLives == 1 then
  86.         item = "life up"
  87.         ID = 8
  88.     end
  89.    
  90.     if (item == pItem) then
  91.         count = count + 1
  92.     else
  93.         switch = 1
  94.         nItem = item
  95.     end
  96.  
  97.     return item
  98. end
  99.  
  100. function openLog(mode)
  101.     return io.open("item_rng.log", mode)
  102. end
  103.  
  104. function beginLog()
  105.     local f = openLog("a")
  106.     f:write("------------------\n")
  107.     f:close()
  108. end
  109.  
  110. function writeLine(text)
  111.     local f = openLog("a")
  112.     f:write(text, "\n")
  113.     f:close()
  114. end
  115.  
  116. -- Save states
  117. function save()
  118.     local obj = savestate.create()
  119.     savestate.save(obj)
  120.     return obj
  121. end
  122.  
  123. s = save()
  124.  
  125. function load()
  126.     savestate.load(s)
  127. end
  128.  
  129. function input()
  130.     joypad.set(1, { ['L'] = 1})
  131. end
  132.  
  133. beginLog()
  134. local rngcheat = -1
  135.  
  136. while true do
  137.   load()
  138.   initValues()
  139.   cheatRNG(rngcheat)
  140.  
  141.   for i = 1, 1 do
  142.     cheatRNG(rngcheat)
  143.     emu.frameadvance()
  144.     cheatRNG(rngcheat)
  145.   end
  146.  
  147.   for i = 1, 22 do
  148.     input()
  149.     cheatRNG(rngcheat)
  150.     emu.frameadvance()
  151.     cheatRNG(rngcheat)
  152.   end
  153.  
  154.   controlValues()
  155.  
  156.   if (switch == 1) then
  157.     writeLine(count.. " ".. pItem)
  158.     if (pItem == "big health") then
  159.         ID = 1
  160.     elseif (pItem == "small health") then
  161.         ID = 2
  162.     elseif (pItem == "Nothing") then
  163.         ID = 3
  164.     elseif (pItem == "big energy") then
  165.         ID = 4
  166.     elseif (pItem == "small energy") then
  167.         ID = 5
  168.     elseif (pItem == "big money") then
  169.         ID = 6
  170.     elseif (pItem == "small money") then
  171.         ID = 7
  172.     elseif (pItem == "life up") then
  173.         ID = 8
  174.     end
  175.  
  176.     loopC[ID] = count - loop[ID]
  177.     pItem = nItem
  178.     switch = 0
  179.     count = 1
  180.     if (nItem == "big health") then
  181.         writeLine("")
  182.         table.insert(loops, loopC)
  183.         print(loopC)
  184.         writeLine("")
  185.         loopC = {0, 0, 0, 0, 0, 0, 0, 0}
  186.     end
  187.   end
  188.  
  189.   rngcheat = rngcheat + 1
  190. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement