RNG fire emblem script LUA


SUBMITTED BY: Guest

DATE: Dec. 12, 2013, 2:52 a.m.

FORMAT: Lua

SIZE: 11.3 kB

HITS: 1001

  1. function nextrng(r1, r2, r3)
  2. return AND(XOR(SHIFT(r3, 5), SHIFT(r2, -11), SHIFT(r1, -1), SHIFT(r2, 15)),0xFFFF)
  3. end
  4. function rngsim(n)
  5. local rngbase=0x03000000
  6. local result = { memory.readword(rngbase+4), memory.readword(rngbase+2), memory.readword(rngbase+0) }
  7. for i = 4, n do
  8. result[i] = nextrng(result[i-3],result[i-2],result[i-1])
  9. end
  10. return result
  11. end
  12. function printstats(n)
  13. if n == 255 then
  14. n = "---"
  15. end
  16. return n
  17. end
  18. function setoperator()
  19. if j == 0 then
  20. op[ind] = "="
  21. elseif j == 1 then
  22. op[ind] = "<"
  23. elseif j == 2 then
  24. op[ind] = ">"
  25. elseif j == 3 then
  26. op[ind] = "<="
  27. elseif j == 4 then
  28. op[ind] = ">="
  29. elseif j == 5 then
  30. op[ind] = "!="
  31. end
  32. z = input.get()
  33. if z.left and otherpressed["left"] == false then
  34. otherpressed["left"] = true
  35. j = j - 1
  36. if j < 0 then
  37. j = 5
  38. end
  39. elseif z.right and otherpressed["right"] == false then
  40. otherpressed["right"] = true
  41. j = j + 1
  42. if j > 5 then
  43. j = 0
  44. end
  45. elseif z.enter and otherpressed["enter"] == false then
  46. otherpressed["enter"] = true
  47. ind = ind + 1
  48. j = 1
  49. a1 = " "
  50. a2 = " "
  51. elseif z.H and otherpressed["H"] == false then
  52. otherpressed["H"] = true
  53. if hit[ind] == "" then
  54. hit[ind] = true
  55. else
  56. hit[ind] = ""
  57. end
  58. end
  59. if not z.left and not z.right and not z.enter and not z.H then
  60. otherpressed["left"] = false
  61. otherpressed["right"] = false
  62. otherpressed["enter"] = false
  63. otherpressed["H"] = false
  64. end
  65. end
  66. function captureinput()
  67. if op[ind] == "" then
  68. for i = 0, 9 do
  69. local s = tostring(i)
  70. n = input.get()
  71. if n[s] then
  72. if numberpressed[s] == false then
  73. numberpressed[s] = true
  74. if a1 == " " then
  75. a1 = i
  76. rn[index] = tonumber(a1 .. "0")
  77. else
  78. a2 = i
  79. rn[index] = tonumber(a1 .. a2)
  80. index = index + 1
  81. op[ind] = "<"
  82. j = 1
  83. end
  84. break
  85. end
  86. else
  87. numberpressed[s] = false
  88. end
  89. end
  90. else
  91. setoperator()
  92. end
  93. end
  94. function emptyarray(x,n)
  95. for i=1, n, 1 do
  96. x[i] = ""
  97. end
  98. return x
  99. end
  100. function compareRN()
  101. local limit = ind-1
  102. local y, hits
  103. d = 1
  104. for i = 4, 501-limit, 1 do
  105. y = 0
  106. hits = 0
  107. x = limit
  108. list = {}
  109. for a = 1, x, 1 do
  110. if hit[a] == "" then
  111. list[a] = math.floor(rngs[i-1+a+hits]/655.36)
  112. else
  113. list[a] = math.floor((math.floor(rngs[i-1+a+hits]/655.36)+math.floor(rngs[i+a+hits]/655.36))/2)
  114. hits = hits + 1
  115. x = x + 1
  116. end
  117. end
  118. for a = 1, limit, 1 do
  119. if op[a] == "<" then
  120. if list[a] < rn[a] then
  121. y = y + 1
  122. end
  123. elseif op[a] == ">" then
  124. if list[a] > rn[a] then
  125. y = y + 1
  126. end
  127. elseif op[a] == "<=" then
  128. if list[a] <= rn[a] then
  129. y = y + 1
  130. end
  131. elseif op[a] == ">=" then
  132. if list[a] >= rn[a] then
  133. y = y + 1
  134. end
  135. elseif op[a] == "!=" then
  136. if list[a] ~= rn[a] then
  137. y = y + 1
  138. end
  139. elseif op[a] == "=" then
  140. if list[a] == rn[a] then
  141. y = y + 1
  142. end
  143. end
  144. end
  145. if y == ind-1 then
  146. if i == 4 then
  147. gui.text(178,(i-1)*8,"-->","cyan")
  148. else
  149. gui.text(212,(i-1)*8,"-->","cyan")
  150. end
  151. if d < 4 then
  152. dis[d] = i-4
  153. d = d + 1
  154. end
  155. end
  156. end
  157. end
  158. a1 = " "
  159. a2 = " "
  160. rn = {"","","","","","","","","",""}
  161. op = {"","","","","","","","","",""}
  162. hit = {"","","","","","","","","",""}
  163. d = 1
  164. dis = {"","",""}
  165. index = 1
  166. ind = 1
  167. numberpressed = {}
  168. for i = 0, 9, 1 do
  169. local s = tostring(i)
  170. numberpressed[s] = false
  171. end
  172. otherpressed = {}
  173. otherpressed["left"] = false
  174. otherpressed["right"] = false
  175. otherpressed["enter"] = false
  176. otherpressed["H"] = false
  177. local filter = 0
  178. local inputs = 0
  179. local php = 0x0203E064
  180. local phit = 0x0203E0C6
  181. local pdmg = 0x0203E0CA
  182. local pcrt = 0x0203E0CE
  183. local ehp = 0x0203E062
  184. local ehit = 0x0203E0C4
  185. local edmg = 0x0203E0C8
  186. local ecrt = 0x0203E0CC
  187. function obtainedexp()
  188. local level = 0x0202BD58
  189. local experience = 0x0202BD59
  190. local total = 0
  191. for i = 0, 7, 1 do
  192. total = total + (memory.readbyte(level+(i*72))*100)
  193. if memory.readbyte(experience+(i*72)) ~= 255 then
  194. total = total + memory.readbyte(experience+(i*72))
  195. end
  196. end
  197. return total
  198. end
  199. while true do
  200. local nsim = 20
  201. rngs = rngsim(503)
  202. for i = 1, nsim do
  203. gui.text(228, 8*(i-1), string.format("%3d", rngs[i]/655.36))
  204. end
  205. gui.text(0,0,"Filter Mode: ")
  206. c = input.get()
  207. if c.Q then
  208. filter = 1
  209. elseif c.W then
  210. filter = 0
  211. inputs = 0
  212. end
  213. if filter == 0 then
  214. gui.text(48,0," Off")
  215. gui.text(0,16,"Player")
  216. gui.text(0,24,"HP: " .. printstats(memory.readbyte(php)))
  217. gui.text(0,32,"Hit: " .. printstats(memory.readbyte(phit)))
  218. gui.text(0,40,"Damage: " .. printstats(memory.readbyte(pdmg)))
  219. gui.text(0,48,"Crit: " .. printstats(memory.readbyte(pcrt)))
  220. gui.text(0,64,"Enemy")
  221. gui.text(0,72,"HP: " .. printstats(memory.readbyte(ehp)))
  222. gui.text(0,80,"Hit: " .. printstats(memory.readbyte(ehit)))
  223. gui.text(0,88,"Damage: " .. printstats(memory.readbyte(edmg)))
  224. gui.text(0,96,"Crit: " .. printstats(memory.readbyte(ecrt)))
  225. index = 1
  226. end
  227. if filter == 1 then
  228. for i = 1, 10, 1 do
  229. gui.text(0,8+(i*8),rn[i])
  230. gui.text(20,8+(i*8),op[i])
  231. if hit[i] == true then
  232. gui.text(40,8+(i*8),"<- Hit")
  233. end
  234. end
  235. if rn[1] ~= "" and inputs == 0 then
  236. dis = emptyarray(dis,3)
  237. compareRN()
  238. end
  239. n = input.get()
  240. if n.I then
  241. rn = emptyarray(rn,10)
  242. index = 1
  243. op = emptyarray(op,10)
  244. ind = 1
  245. hit = emptyarray(hit,10)
  246. inputs = 1
  247. elseif n.O or ind > 10 then
  248. inputs = 0
  249. end
  250. if inputs == 1 then
  251. joypad.set(1,{" "})
  252. captureinput()
  253. gui.text(132,0,"On")
  254. elseif inputs == 0 then
  255. gui.text(132,0,"Off")
  256. if rn[1] ~= "" then
  257. if dis[1] == "" then
  258. gui.text(0,104,"Distance: ---")
  259. elseif dis[1] ~= "" and dis[2] == "" then
  260. gui.text(0,104,"Distance: " .. dis[1])
  261. elseif dis[1] ~= "" and dis[2] ~= "" and dis[3] == "" then
  262. gui.text(0,104,string.format("Distance: %d - %d",dis[1],dis[2]))
  263. else
  264. gui.text(0,104,string.format("Distance: %d - %d - %d",dis[1],dis[2],dis[3]))
  265. end
  266. end
  267. end
  268. gui.text(48,0," On -- Input Mode: ")
  269. end
  270. gui.text(210,0,"RNG1:")
  271. gui.text(210,8,"RNG2:")
  272. gui.text(210,16,"RNG3:")
  273. gui.text(194,24,"Next RNs:")
  274. emu.frameadvance()
  275. end

comments powered by Disqus