Advertisement
Guest User

terranigma_rng_crit.lua

a guest
May 31st, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.20 KB | None | 0 0
  1. require "terranigma_rng"
  2.  
  3. local function computeMaxEnemyLuck(randomNumber)
  4.  
  5.     local playerLuck = memory.readbyte(0x7e0666)
  6.     local maxEnemyLuck = playerLuck + 8 - AND(randomNumber,0x7f)-1
  7.  
  8.     if AND(randomNumber,0x7f)<4 then
  9.       maxEnemyLuck = 99
  10.     end
  11.  
  12.     return maxEnemyLuck
  13. end
  14.  
  15. rng.set_title("Crits")
  16. rng.set_nr_rows(16)
  17. rng.set_nr_columns (2)
  18. rng.set_column_width(6)
  19. rng.set_text(function(x,y,counter,rn)
  20.  
  21.   -- Determine the highest enemy luck value that will still yield a critical, given the player's current luck stat, and the provided random number
  22.   local maxEnemyLuck = computeMaxEnemyLuck(rn)
  23.   local actualEnemyLuck = 40
  24.  
  25.   -- Default text color is red
  26.   local rngColor = 0xFF0000FF
  27.  
  28.   -- This random number will generate a critical hit -> green text
  29.   if actualEnemyLuck <= maxEnemyLuck then
  30.     rngColor = 0x00FF00FF
  31.   end
  32.  
  33.   -- Show the highest enemy luck value that will yield a crit
  34.   if maxEnemyLuck < 0 then
  35.     gui.text(x,y,string.upper(string.format('%02x: --',counter)),rngColor)
  36.   else
  37.     gui.text(x,y,string.upper(string.format('%02x: %02d',counter,maxEnemyLuck)),rngColor)
  38.   end
  39. end)
  40.  
  41. rng.show()
  42. while true do
  43.   emu.frameadvance()
  44. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement