EvilAsh25

CC-Attack

May 7th, 2020 (edited)
2,162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.57 KB | None | 0 0
  1. --This script is designed to work with Bizhawk
  2. --This script assumes a pre-made state on Quicksave Slot 0, 1 enemy, with % hit selected (next X press would attack)
  3.  
  4. --Set the correct memory domain
  5. --memory.usememorydomain("System Bus")
  6.  
  7. --define variables
  8. wins = 0
  9. miss = 0
  10. total = 0
  11. save_state_slot = 0 -- which quickload slot to load from
  12. counter = 0
  13. pervious = 0
  14. HPaddr = 0x0DBDD8
  15. --HPaddr = 0x0DD2F0
  16. file = io.open('attack_' ..tostring(emu.framecount()) ..'.txt', "a")
  17. io.output(file)
  18. io.write("---Streak---\n")
  19.  
  20. --Wait function for advancing 1 frame and displaying results on the screen
  21. function Wait(number)
  22.     for i=0,number-1 do
  23.         emu.frameadvance()
  24.         --display the HP
  25.         gui.text(330,150,'HP: '..(memory.read_u16_le(HPaddr)) )
  26.        
  27.         gui.text(330,170,'Total: '..total)
  28.        
  29.         if(total ~= 0) then
  30.             gui.text(330,210,'Hit: '..wins..' ('..(math.floor(1000 * wins / (total)) / 10)..'%)')
  31.             gui.text(330,230,'Miss: '..miss..' ('..(math.floor(1000 * miss / (total)) / 10)..'%)')
  32.         end
  33.     end
  34. end
  35.  
  36. --the main loop, this runs forever
  37. while true do
  38.     --load the savestate
  39.     savestate.loadslot(save_state_slot);
  40.     --wait, then save state for the next round
  41.     Wait(1);
  42.     savestate.saveslot(save_state_slot);
  43.    
  44.     HPStart = memory.read_u16_le(HPaddr)
  45.    
  46.     wait = 30
  47.     --run the attack loop
  48.     while true do
  49.         joypad.set({R2=true}, 1)
  50.         joypad.set({Cross=true}, 1)
  51.         wait = wait - 1
  52.         Wait(1);
  53.         --wait for the attack to resolve
  54.         if ((wait == 0) or (memory.read_u16_le(HPaddr) ~= HPStart)) then break end
  55.     end
  56.    
  57.     --read the variables we need to record data
  58.     HPEnd = memory.read_u16_le(HPaddr);
  59.    
  60.     if (HPStart ~= HPEnd) then
  61.         --hit
  62.         wins = wins + 1
  63.         if(previous == 0) then
  64.             --increment the counter
  65.             counter = counter + 1;
  66.         else
  67.             --write to file
  68.             io.write('Miss: ', counter, '\n')
  69.             counter = 1
  70.         previous = 0
  71.         end
  72.     else
  73.         --miss
  74.         miss = miss + 1
  75.         if(previous == 1) then
  76.             --increment the counter
  77.             counter = counter + 1;
  78.         else
  79.             --write to file
  80.             io.write('Hit : ', counter, '\n')
  81.             counter = 1
  82.         previous = 1
  83.         end
  84.     end
  85.        
  86.     total = total + 1;
  87.    
  88.     --we are finished, record the data, set total number of trials here
  89.     if(total == 10000) then
  90.         if(previous == 1) then
  91.             io.write('Miss: ', counter, '\n')
  92.         else
  93.             io.write('Hit : ', counter, '\n')
  94.         end
  95.         io.write('\n')
  96.         io.write('Total     : ', total, '\n')
  97.         io.write('Total Hit : ', wins, ' (', (math.floor(1000 * wins / (total)) / 10), '%)\n')
  98.         io.write('Total Miss: ', miss, ' (', (math.floor(1000 * miss / (total)) / 10), '%)\n')
  99.         io.close(file)
  100.         break
  101.     end
  102.     Wait(1);
  103.    
  104. end
Add Comment
Please, Sign In to add comment