Advertisement
Guest User

Katam Analyse Helper transform probabilities

a guest
Sep 7th, 2024
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.88 KB | Gaming | 0 0
  1. -- this luascript is for analyzing helper kirbys "random transformations" probabilities
  2. -- go to any room where there is no helper kirby and let this run for hours.
  3.  
  4. function text(x, y, text, color, backcolor)
  5.     if backcolor==nil then backcolor=0x00000000 end
  6.     gui.drawText(x, y, text,color,backcolor,10,"Arial")
  7. end
  8.  
  9. local abilityNames= { -- ability, yellow count, red count, green count
  10. [00] = {"Normal", 0, 0, 0},
  11. [01] = {"Fire", 0, 0, 0},
  12. [02] = {"Ice", 0, 0, 0},
  13. [03] = {"Burning", 0, 0, 0},
  14. [04] = {"Wheel", 0, 0, 0},
  15. [05] = {"Parasol", 0, 0, 0},
  16. [06] = {"Cutter", 0, 0, 0},
  17. [07] = {"Beam", 0, 0, 0},
  18. [08] = {"Stone", 0, 0, 0},
  19. [09] = {"Bomb", 0, 0, 0},
  20. [10] = {"Throw", 0, 0, 0},
  21. [11] = {"Sleep", 0, 0, 0},
  22. [12] = {"Cook", 0, 0, 0},
  23. [13] = {"Laser", 0, 0, 0},
  24. [14] = {"UFO", 0, 0, 0},
  25. [15] = {"Spark", 0, 0, 0},
  26. [16] = {"Tornado", 0, 0, 0},
  27. [17] = {"Hammer", 0, 0, 0},
  28. [18] = {"Sword", 0, 0, 0},
  29. [19] = {"Cupid", 0, 0, 0},
  30. [20] = {"Fighter", 0, 0, 0},
  31. [21] = {"Magic", 0, 0, 0},
  32. [22] = {"Smash", 0, 0, 0},
  33. [23] = {"Mini", 0, 0, 0},
  34. [24] = {"Crash", 0, 0, 0},
  35. [25] = {"Missile", 0, 0, 0},
  36. [26] = {"Master", 0, 0, 0}
  37. }
  38.  
  39. local yellow_ability_old    = memory.read_u8(0x02118B)
  40. local red_ability_old       = memory.read_u8(0x021333)
  41. local green_ability_old     = memory.read_u8(0x0214DB)
  42.  
  43. local yellow_total_count    = 0
  44. local red_total_count       = 0
  45. local green_total_count     = 0
  46.  
  47. local show_percent          = false
  48. local speed_mode            = true
  49. local left_clicked_frames   = 0
  50. local right_clicked_frames  = 0
  51.  
  52. local projected_framecount  = 0
  53. local seeking               = false
  54. local seek_step             = 300
  55. local next_screenshot_frame = 5000
  56. local next_screenshot_step  = 500000
  57.  
  58. client.SetGameExtraPadding(0,100,240,100)
  59. memory.usememorydomain("EWRAM")
  60.  
  61. event.onexit(function()
  62.     client.SetGameExtraPadding(0,0,0,0)
  63.     console.clear()
  64. end)
  65.  
  66. while true do
  67.  
  68.     --check new ability
  69.     local yellow_ability    = memory.read_u8(0x02118B)
  70.     local red_ability       = memory.read_u8(0x021333)
  71.     local green_ability     = memory.read_u8(0x0214DB)
  72.    
  73.     local check_value       = memory.read_u8(0x022953) -- zero when resetting and on the menu, nonzero when ingame
  74.    
  75.     --process new ability
  76.     if check_value > 0 then
  77.         if yellow_ability ~= yellow_ability_old and yellow_ability < 27 then
  78.             if yellow_ability ~= 0 then
  79.                 abilityNames[yellow_ability][2] = abilityNames[yellow_ability][2] + 1
  80.                 yellow_total_count = yellow_total_count + 1
  81.             end
  82.         end
  83.         if red_ability ~= red_ability_old and red_ability < 27 then
  84.             if red_ability ~= 0 then
  85.                 abilityNames[red_ability][3] = abilityNames[red_ability][3] + 1
  86.                 red_total_count = red_total_count + 1
  87.             end
  88.         end
  89.         if green_ability ~= green_ability_old and green_ability < 27 then
  90.             if green_ability ~= 0 then
  91.                 abilityNames[green_ability][4] = abilityNames[green_ability][4] + 1
  92.                 green_total_count = green_total_count + 1
  93.             end
  94.         end
  95.     end
  96.    
  97.     -- toggle view on click
  98.     if input.getmouse().Left then
  99.         left_clicked_frames = left_clicked_frames + 1
  100.     else
  101.         left_clicked_frames = 0
  102.     end
  103.     if left_clicked_frames == 1 then
  104.         show_percent = not show_percent
  105.     end
  106.    
  107.     -- toggle speed mode
  108.     if input.getmouse().Middle then
  109.         right_clicked_frames = right_clicked_frames + 1
  110.     else
  111.         right_clicked_frames = 0
  112.     end
  113.     if right_clicked_frames == 1 then
  114.         speed_mode = not speed_mode
  115.     end
  116.    
  117.     if speed_mode and not seeking then
  118.         projected_framecount = emu.framecount() + seek_step
  119.         client.seekframe(projected_framecount)
  120.         seeking = true
  121.     end
  122.     if speed_mode and seeking then
  123.         if emu.framecount() >= projected_framecount then
  124.             seeking = false
  125.         end
  126.     end
  127.    
  128.     --screenshot every once in a while in case emu crashes overnight, i want to see the results..
  129.     if emu.framecount() > next_screenshot_frame then
  130.         next_screenshot_frame = next_screenshot_frame + next_screenshot_step
  131.         client.screenshot("HELPER_ANALYSE_ABILITY_GET_" .. emu.framecount() .. ".png")
  132.         print("i did screenshot")
  133.     end
  134.    
  135.     --text on screen
  136.     local abilities     = ""
  137.     local yellow_count  = ""
  138.     local red_count     = ""
  139.     local green_count   = ""
  140.     local yellow_percent = 0
  141.     local red_percent = 0
  142.     local green_percent = 0
  143.     for i=1, #abilityNames do
  144.         abilities       = abilities .. abilityNames[i][1] .. "\n"
  145.         if show_percent then
  146.             if yellow_total_count == 0 then
  147.                 yellow_percent = 0
  148.             else
  149.                 yellow_percent = 100 * (abilityNames[i][2] / yellow_total_count)
  150.             end
  151.             if red_total_count == 0 then
  152.                 red_percent = 0
  153.             else
  154.                 red_percent = 100 * (abilityNames[i][3] / red_total_count)
  155.             end
  156.             if green_total_count == 0 then
  157.                 green_percent = 0
  158.             else
  159.                 green_percent = 100 * (abilityNames[i][4] / green_total_count )
  160.             end
  161.             yellow_count    = yellow_count .. math.floor(yellow_percent) .. "%\n"
  162.             red_count       = red_count .. math.floor(red_percent) .. "%\n"
  163.             green_count     = green_count .. math.floor(green_percent) .. "%\n"
  164.         else
  165.             yellow_count    = yellow_count .. abilityNames[i][2] .. "\n"
  166.             red_count       = red_count .. abilityNames[i][3] .. "\n"
  167.             green_count     = green_count .. abilityNames[i][4] .. "\n"
  168.         end
  169.        
  170.         -- last
  171.         if i == #abilityNames then
  172.         abilities       = abilities .. "TOTAL: "
  173.             yellow_count    = yellow_count .. yellow_total_count
  174.             red_count       = red_count .. red_total_count
  175.             green_count     = green_count .. green_total_count
  176.         end
  177.     end
  178.    
  179.     if show_percent then
  180.         text(20,20,"Left Click to show transformation counts.", 0xFFFFFFFF)
  181.     else
  182.         text(20,20,"Left Click to show percentages.", 0xFFFFFFFF)
  183.     end
  184.    
  185.     if speed_mode then
  186.         text(20,40,"Middle Click for normal speed.", 0xFFFFFFFF)
  187.     else
  188.         text(20,40,"Middle Click for high speed.", 0xFFFFFFFF)
  189.     end
  190.    
  191.    
  192.     text(260,0,abilities,   0xFFFFFFFF)
  193.     text(300,0,yellow_count,0xFFFFFF00)
  194.     text(340,0,red_count,   0xFFFF0000)
  195.     text(380,0,green_count, 0xFF00FF00)
  196.    
  197.     --update old ability
  198.     yellow_ability_old  = yellow_ability
  199.     red_ability_old     = red_ability
  200.     green_ability_old   = green_ability
  201.    
  202.     emu.frameadvance()
  203. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement