Advertisement
Kirkq

Dragster Lua

Sep 8th, 2017
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.59 KB | None | 0 0
  1. -- Dragster lua Stepmania-style script by Kirkq
  2.  
  3. ---- Written in haste, so the code looks pretty bad. I got a 5.64 (while cheating, so not legit) with this after a couple hours.
  4.  
  5. -- For learning or for a Stepmania chart, up to you.
  6.  
  7. -- For practice only, times aren't legit if you're using this script live. The script cheats for practice purposes.
  8. -- If you want to record a video file to play along with, that seems fine to me at least, others' opinions may vary.
  9. -- If you want to try the input from a video, I'd recommend turning on the "random frame shifter"
  10. -- 3 lines from the bottom and recording a long video to play in the background.
  11. -- Having this running on any emulator while you're also playing even on a separate emulator is pretty shady in my opinion.
  12. -- If you're gonna post a 5.57, don't use the script in a shady manner.
  13.  
  14. -- To my understanding, the game only reads input every other frame at 60 fps, correct me if I'm wrong.
  15. -- This means every button must be held two frames. This is why it seems like inputs drop sometimes.
  16. -- Buttons need held the frame they are on the line, and the frame after.
  17.  
  18. -- The practicing of the start sequence may be more useful via audio cues,
  19. -- but the feedback here with green and red text on the first three shifts is very useful.
  20. -- The first three shifts are almost everything in achieving a 5.57 vs a 5.61.
  21.  
  22. -- The press of the right button keeps you 1/8 frame aligned while the script is running. Reminder: This is for PRACTICE ONLY.
  23. -- I slid most of the wider frame windows one frame from the end to make them wider.
  24. -- The first three shifts are extremely tight, most of the rest is 3-5 frame windows.
  25. -- You can let go of B slightly early on the last hold of left. If you're a frame late you blow your engine.
  26. -- Review Omni's sheet for frame windows.
  27.  
  28. --Button Array
  29. --L D U R B
  30.  
  31. NUM_BUTTONS=5
  32. NUM_ROWS=300
  33. NUM_SHOWN=50
  34.  
  35. START_FRAME=120
  36. SHIFT_OFFSET=0 -- Shift one frame prior to sheet
  37.  
  38. LEFT=1
  39. DOWN=2
  40. UP=3
  41. RIGHT=4
  42. B=5
  43.  
  44. function printMemoryDomains(x,y)
  45. local list = {}
  46. list = memory.getmemorydomainlist()
  47. local curr = memory.getcurrentmemorydomain()
  48. local num = table.getn(list)
  49. local i
  50. gui.text(x,y,"Current: " .. curr)
  51. for i=0,num do
  52. gui.text(x,y + 15*(i+1),list[i])
  53. end
  54. end
  55.  
  56. --Init Array - Create and zero the array
  57. --i is buttons
  58. --j is frame number
  59. --0 is no hit, 1 is hit
  60. array = {}
  61. for i = 1,NUM_BUTTONS do
  62. array[i] = {}
  63. for j = -200,NUM_ROWS+200 do
  64. array[i][j] = 0
  65. end
  66. end
  67.  
  68. array[RIGHT][START_FRAME - 79 + SHIFT_OFFSET]=1
  69.  
  70. --Left is Shift, B is gas
  71.  
  72. -- Shift
  73. array[LEFT][START_FRAME + 0 + SHIFT_OFFSET]=1
  74. array[LEFT][START_FRAME +15 + SHIFT_OFFSET]=1 -- 3 Frame Window
  75. array[LEFT][START_FRAME +33 + SHIFT_OFFSET]=1
  76. array[LEFT][START_FRAME +52 + SHIFT_OFFSET]=1 -- Frame Perfect
  77. array[LEFT][START_FRAME +81 + SHIFT_OFFSET-1]=1 -- 5 frame window
  78. array[LEFT][START_FRAME +92 + SHIFT_OFFSET]=1 -- 2 frame window
  79. array[LEFT][START_FRAME +105 + SHIFT_OFFSET-1]=1 -- 6 frame window
  80. array[LEFT][START_FRAME +114 + SHIFT_OFFSET-1]=1 -- 7 frame window
  81. array[LEFT][START_FRAME +123 + SHIFT_OFFSET-1]=1 -- 6 frame window
  82. array[LEFT][START_FRAME +137 + SHIFT_OFFSET+2]=1 -- 5 frame window
  83. -- The earlier you go in the frame windows, the more distance you lose. So you need to at least be generally towards the end of them.
  84. -- The last clutch 5 frame window doesn't affect distance
  85.  
  86. --137 to 167 it is required, holding shift freezes your speed, so you no longer have to maintain TACH at all
  87. for n = 137+2,167 do
  88. array[LEFT][START_FRAME+ n + SHIFT_OFFSET]=1
  89. end
  90.  
  91. -- Gas
  92. for n = -3,139 do
  93. array[B][START_FRAME + n] = 1
  94. end
  95. array[B][START_FRAME + 16] = 0 --3 Frame Window
  96. array[B][START_FRAME + 34] = 0
  97. --array[B][START_FRAME + 150] = 1
  98. --array[B][START_FRAME + 158] = 1
  99. --array[B][START_FRAME + 166] = 1
  100. --array[B][START_FRAME + 174] = 1
  101. --array[B][START_FRAME + 182] = 1
  102.  
  103. currframe=0
  104. even = 0
  105. odd = 1
  106.  
  107. textfile = "DragsterDump2"
  108. dumpfile = textfile..".txt"
  109. io.output(dumpfile)
  110.  
  111. dumpflag=1
  112. --memory.writebyte(0x01,2,"Main RAM")
  113.  
  114. speed2tachs = 999
  115. speed2frame = 999
  116. speed2timerB = 999
  117. speed3tachs = 999
  118. speed3frame = 999
  119. speed3timerB = 999
  120. speed4tachs = 999
  121. speed4frame = 999
  122. speed4timerB = 999
  123. --savestate.loadslot(1)
  124. memory.writebyte(0x01,0x02,"Main RAM")
  125. while true do
  126. --memory.writebyte(0x01,7) --Set optimal start
  127. --memory.writebyte(0x0D,159) --Set optimal start
  128. --printMemoryDomains(400,400)
  129. px=memory.readbyte(0x3A,"Main RAM")
  130. spx=memory.readbyte(0x42,"Main RAM")
  131. speed=memory.readbyte(0x40,"Main RAM")
  132. tach=memory.readbyte(0x28,"Main RAM")
  133. frame=memory.readbyte(0x01,"Main RAM")
  134. timerA=memory.readbyte(0x33,"Main RAM")
  135. timerB=memory.readbyte(0x35,"Main RAM")
  136. frame = frame % 16
  137. gui.text(400,230,"Speed:" .. speed)
  138. gui.text(400,245,"Tach:" .. tach)
  139. gui.text(400,260,"Frame:" .. frame)
  140. gui.text(400,275,"TimerA:" .. timerA)
  141. gui.text(400,290,"TimerB:" .. timerB)
  142. gui.text(400,305,px)
  143. gui.text(400,320,spx/256)
  144.  
  145. if speed == 2 then
  146. speed2tachs=tach --15 or 18
  147. speed2frame=frame --14
  148. speed2timerB=timerB --6
  149. end
  150. if speed == 32 or speed == 33 then
  151. speed3tachs=tach --26 or 24
  152. speed3frame=frame --10
  153. speed3timerB=timerB --96
  154. end
  155. if speed == 70 or speed == 71 then
  156. speed4tachs=tach --26 or 24
  157. speed4frame=frame --2
  158. speed4timerB=timerB --38
  159. end
  160.  
  161. if speed2tachs ~= 999 then
  162. if (speed2tachs == 15 or speed2tachs == 18) then
  163. gui.text(400,160,speed2tachs, "green")
  164. else
  165. gui.text(400,160,speed2tachs, "red")
  166. end
  167. end
  168. if speed2frame ~= 999 then
  169. if speed2frame == 10 then
  170. gui.text(400,175,speed2frame, "green")
  171. else
  172. gui.text(400,175,speed2frame, "red")
  173. end
  174. end
  175. if speed2timerB ~= 999 then
  176. if speed2timerB == 6 then
  177. gui.text(400,190,speed2timerB, "green")
  178. else
  179. gui.text(400,190,speed2timerB, "red")
  180. end
  181. end
  182.  
  183. if speed3tachs ~= 999 then
  184. if (speed3tachs == 26 or speed3tachs == 24 or speed3tachs == 23) then
  185. gui.text(440,160,speed3tachs, "green")
  186. else
  187. gui.text(440,160,speed3tachs, "red")
  188. end
  189. end
  190.  
  191. if speed3frame ~= 999 then
  192. if speed3frame == 10 then
  193. gui.text(440,175,speed3frame, "green")
  194. else
  195. gui.text(440,175,speed3frame, "red")
  196. end
  197. end
  198. if speed3timerB ~= 999 then
  199. if speed3timerB == 96 then
  200. gui.text(440,190,speed3timerB, "green")
  201. else
  202. gui.text(440,190,speed3timerB, "red")
  203. end
  204. end
  205.  
  206. if speed4tachs ~= 999 then
  207. if (speed4tachs == 26 or speed4tachs == 24) then
  208. gui.text(480,160,speed4tachs, "green")
  209. else
  210. gui.text(480,160,speed4tachs, "red")
  211. end
  212. end
  213.  
  214. if speed4frame ~= 999 then
  215. if speed4frame == 2 then
  216. gui.text(480,175,speed4frame, "green")
  217. else
  218. gui.text(480,175,speed4frame, "red")
  219. end
  220. end
  221. if speed4timerB ~= 999 then
  222. if speed4timerB == 38 then
  223. gui.text(480,190,speed4timerB, "green")
  224. else
  225. gui.text(480,190,speed4timerB, "red")
  226. end
  227. end
  228.  
  229. --if dumpflag == 1 then
  230. -- if speed > 0 then
  231. -- io.write(speed .. " " .. tach .. " " .. frame)
  232. -- io.write("\n")
  233. -- end
  234. -- end
  235.  
  236. --gui.text(30,45,"Currframe: " .. currframe)
  237. basex=20
  238. basey=100
  239. flag = 0
  240. for n=-10,NUM_SHOWN do
  241. if n==0 then
  242. --gui.text(basex+0,basey, "-------------------------------")
  243. gui.text(basex,basey-8, "========================")
  244. end
  245. for m=1,NUM_BUTTONS do
  246. if array[m][currframe+n] == 1 then
  247. if m == LEFT then
  248. if array[m][currframe+n-1] == 1 then
  249. disp = "|"
  250. else
  251. disp = "L"
  252. if n==0 then
  253. flag = 1
  254. end
  255. end
  256. elseif m == B then
  257. if array[m][currframe+n-1] == 1 then
  258. disp = "|"
  259. else
  260. disp = "B"
  261. if n==0 then
  262. flag = 1
  263. end
  264. end
  265. elseif m == RIGHT then
  266. disp = "R"
  267. if n==0 then
  268. flag = 1
  269. end
  270. end
  271. if even == 1 then
  272. offset2 = 0
  273. else
  274. offset2 = 8
  275. end
  276. --if n==0 then
  277. -- if flag == 1 and even == 1 then
  278. -- gui.text(basex+0,basey, "-------------------------------", "green")
  279. -- end
  280. --end
  281. if disp ~= "|" then
  282. gui.text(basex+m*20,basey+n*16+offset2,disp)
  283. end
  284. end
  285. end
  286. end
  287. if flag == 1 then
  288. --for q=1,60 do
  289. -- gui.text(270,20+q*16,"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
  290. --end
  291. if even == 1 then
  292. even = 1
  293. --os.execute("echo \7") -- Make windows beep, but steal control of window.
  294. end
  295. end
  296. emu.frameadvance()
  297. -- 60 fps vs 30 fps
  298. if even == 1 then
  299. currframe=currframe+1
  300. even = 0
  301. odd = 1
  302. elseif odd == 1 then
  303. even = 1
  304. odd = 0
  305. end
  306. if currframe > NUM_ROWS then
  307. dumpflag=0
  308. --io.output():close()
  309. currframe=13
  310. speed2tachs = 999
  311. speed2frame = 999
  312. speed2timerB = 999
  313. speed3tachs = 999
  314. speed3frame = 999
  315. speed3timerB = 999
  316. speed4tachs = 999
  317. speed4frame = 999
  318. speed4timerB = 999
  319. --currframe = math.random(0, 7) -- Slide frame number
  320. end
  321. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement