Advertisement
Guest User

ff4_lua_script.lua

a guest
Jan 26th, 2020
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. -- --------------------------- --
  2. -- Final Fantasy IV LUA script --
  3. -- --
  4. -- By: Pasky13 --
  5. -- --------------------------- --
  6.  
  7. -- Globals
  8.  
  9. char_atbm = {0, 0, 0, 0, 0}
  10. enemy_atbm = {0, 0, 0, 0, 0, 0, 0, 0}
  11.  
  12. local function ecords_y(y)
  13. local ex = bit.lshift(bit.band(y,0x0F),3) +0x0C - 0x16
  14. return ex
  15. end
  16.  
  17. local function ecords_x(x)
  18. local ey = bit.rshift(bit.band(x,0xF0),1) + 8 + 0x10
  19. return ey
  20. end
  21.  
  22. local function drawatb_e(x,y,atb,e)
  23. gui.box(x-3, y-4, x+17, y-1, 0x00000000, 0x000000FF)
  24.  
  25. if atb == 0 then
  26. enemy_atbm[e] = 0
  27. gui.box(x-3, y-4, x+17, y-1, 0xFF0000C0, 0000000000)
  28.  
  29. else
  30. if enemy_atbm[e] == 0 then
  31. enemy_atbm[e] = atb
  32. end
  33.  
  34. gui.box(x-3, y-4, (x-3)+20-((20/enemy_atbm[e])*atb), y-1, 0xFF0000C0, 0000000000)
  35. gui.text(x-3,y-8, enemy_atb[e] .. "/" .. enemy_atbm[e]) -- KIRCH, originally commented out
  36.  
  37. end
  38. end
  39.  
  40. local function drawatb_c(x,y,atb,c)
  41. gui.box(x-3, y-4, x+17, y-1, 0x00000000, 0x000000FF)
  42.  
  43. if atb == 0 then
  44. char_atbm[c] = 0
  45. gui.box(x-3, y-4, x+17, y-1, 0x0000FFC0, 0000000000)
  46.  
  47. else
  48. if char_atbm[c] == 0 then
  49. char_atbm[c] = atb
  50. end
  51.  
  52. gui.box(x-3, y-4, (x-3)+20-((20/char_atbm[c])*atb), y-1, 0xFFFF00C0, 0000000000)
  53. gui.text(x-3,y-8, character_atb[c] .. "/" .. char_atbm[c]) -- KIRCH, originally commented
  54.  
  55. end
  56. end
  57.  
  58. -- For who knows what reason, the data of the characters are not in order, so this fix it
  59. local function fix(character)
  60. fix_order = {3, 1, 5, 2, 4}
  61. return fix_order[character]
  62. end
  63.  
  64. while true do
  65.  
  66. character_atb = {}
  67. character_x = {}
  68. character_y = {}
  69.  
  70. for c=1, 5 do
  71. character_atb[fix(c)] = memory.readbyte(0x7E2A07 + 0x15*(c-1))
  72. character_x[fix(c)] = memory.readbyte(0x7EEFC5 + 0x10*(c-1))
  73. character_y[fix(c)] = memory.readbyte(0x7EEFC6 + 0x10*(c-1))
  74. end
  75.  
  76.  
  77. enemy_atb = {}
  78. enemy_cur_hp = {}
  79. enemy_max_hp = {}
  80. enemy_xy = {}
  81.  
  82. for e=1, 8 do
  83. enemy_atb[e] = memory.readbyte(0x7E2A70 + 0x15*(e-1))
  84. enemy_cur_hp[e] = memory.readword(0x7E2287 + 0x80*(e-1))
  85. enemy_max_hp[e] = memory.readword(0x7E2289 + 0x80*(e-1))
  86. enemy_xy[e] = memory.readbyte(0x7E29A5 + 0x01*(e-1))
  87. end
  88.  
  89. battle = memory.readbyte(0x7E0201)
  90. attack = memory.readbyte(0x7E3581) -- normal 00, back 08
  91.  
  92. if battle ~= 0x85 then
  93.  
  94. for c=1, 5 do
  95. drawatb_c(character_x[c], character_y[c], character_atb[c], c)
  96. end
  97.  
  98. for e=1, 8 do
  99. if enemy_cur_hp[e] > 0 then
  100. gui.text( ecords_x(enemy_xy[e]), ecords_y(enemy_xy[e]), e .. " " .. enemy_cur_hp[e] .. "/" .. enemy_max_hp[e] )
  101. drawatb_e(ecords_x(enemy_xy[e]), ecords_y(enemy_xy[e]), enemy_atb[e], e)
  102. end
  103. end
  104.  
  105. else
  106.  
  107. for i=1,5 do
  108. char_atbm[i] = 0
  109. end
  110.  
  111. for i=1,8 do
  112. enemy_atbm[i] = 0
  113. end
  114. end
  115.  
  116. snes9x.frameadvance()
  117.  
  118. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement