Advertisement
Dabomstew

yellow lag difference lua test

Aug 13th, 2015
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. savestate.save("basestate.lel")
  2. memory.usememorydomain("System Bus")
  3. local PREDELAY = 1
  4. local LENGTH = 2
  5. local POSTDELAY = 3
  6. local inputs = {
  7. A = {0,0,0},
  8. B = {0,0,0},
  9. Right = {0,0,0},
  10. Left = {0,0,0},
  11. Up = {0,0,0},
  12. Down = {0,0,0}
  13. }
  14.  
  15. function process()
  16. for button,vars in pairs(inputs) do
  17. if vars[PREDELAY] > 0 then
  18. vars[PREDELAY] = vars[PREDELAY] - 1
  19.  
  20. elseif vars[LENGTH] > 0 then
  21. vars[LENGTH] = vars[LENGTH] - 1
  22. joypad.set({[button]=true})
  23.  
  24. elseif vars[POSTDELAY] > 0 then
  25. vars[POSTDELAY] = vars[POSTDELAY] - 1
  26. end
  27. end
  28. end
  29.  
  30. function input(button,predelay,length,postdelay)
  31. if inputs[button][PREDELAY] > 0
  32. or inputs[button][LENGTH] > 0
  33. or inputs[button][POSTDELAY] > 0 then
  34. return
  35. end
  36.  
  37. inputs[button][PREDELAY] = predelay
  38. inputs[button][LENGTH] = length
  39. inputs[button][POSTDELAY] = postdelay
  40. end
  41.  
  42. local fight_menu = 193
  43. function get_battle_pos()
  44. return memory.read_u8(0xcc30)
  45. end
  46.  
  47. function get_igtframes()
  48. return memory.read_u8(0xda40)*216000 + memory.read_u8(0xda42)*3600 + memory.read_u8(0xda43)*60 + memory.read_u8(0xda44)
  49. end
  50.  
  51. while true do
  52. local spindir = 0
  53.  
  54. while true do
  55. if memory.read_u8(0xd056) ~= 0 then
  56. break
  57. end
  58. if emu.framecount() % 4 == 0 then
  59. if spindir == 0 then
  60. input("Down",0,2,0)
  61. elseif spindir == 1 then
  62. input("Right",0,2,0)
  63. elseif spindir == 2 then
  64. input("Up",0,2,0)
  65. elseif spindir == 3 then
  66. input("Left",0,2,0)
  67. end
  68.  
  69. spindir = (spindir + 1) % 4
  70. end
  71.  
  72. process()
  73. emu.frameadvance()
  74. end
  75.  
  76. local frameCount = emu.framecount()
  77. local fc2 = get_igtframes()
  78. local battle_state = 0
  79. local battlemon = memory.read_u8(0xcfe4)
  80. while true do
  81. if memory.read_u8(0xd056) == 0 then
  82. break
  83. end
  84. if battlemon == 0 and memory.read_u8(0xcfe4) ~= 0 then
  85. battlemon = memory.read_u8(0xcfe4)
  86. end
  87. local pos = get_battle_pos()
  88. if pos == fight_menu then
  89. joypad.set({Left=nil, Right=true, Down=true, A=nil})
  90. else
  91. if battle_state == 0 then
  92. joypad.set({Right=nil, Down=nil, A=true})
  93. else
  94. joypad.set({Right=nil, Down=nil, A=nil})
  95. end
  96. battle_state = 1 - battle_state
  97. end
  98. emu.frameadvance()
  99. end
  100. local intermediate = true
  101. local movecount = 0
  102. local movingdown = false
  103. while true do
  104. if memory.read_u8(0xcfc4) ~= 0 and intermediate then
  105. intermediate = false
  106. print("encounter with "..battlemon.." lasted "..(emu.framecount()-frameCount).." frames or "..(get_igtframes()-fc2).." igtframes")
  107. end
  108. if memory.read_u8(0xd056) ~= 0 then
  109. break
  110. end
  111. if memory.read_u8(0xd363) == 0 then
  112. -- move up
  113. if movingdown then
  114. movecount = movecount + 1
  115. if movecount == 4 then
  116. break
  117. end
  118. movingdown = false
  119. end
  120. joypad.set({B=true,Right=true})
  121. emu.frameadvance()
  122. else
  123. if movingdown == false then
  124. movecount = movecount + 1
  125. if movecount == 4 then
  126. break
  127. end
  128. movingdown = true
  129. end
  130. joypad.set({B=true,Left=true})
  131. emu.frameadvance()
  132. end
  133. end
  134. if memory.read_u8(0xd056) == 0 then
  135. for i=1,25 do
  136. emu.frameadvance()
  137. end
  138. end
  139. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement