Advertisement
EvilAsh25

ChronoCross-FateAP

Dec 22nd, 2020 (edited)
623
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.92 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
  3.  
  4. --define variables here
  5. ap_addr = 0x0DBE8C --AP1
  6. trials = 20000
  7. file_prefix = "Fate_"
  8.  
  9. --program variables
  10. ap_value = 0
  11. ap_previous = 0
  12. ap_t = {}
  13. total = 0
  14. save_state_slot = 0 -- which quickload slot to load from
  15.  
  16. --Prints a Table with a format of (x,y)
  17. function tprint (t)
  18.     for k, v in pairs(t) do
  19.         io.write(k..', '..v..'\n')
  20.     end
  21. end
  22.  
  23. --Wait function for advancing 1 frame and displaying results on the screen
  24. function Wait(number)
  25.     for i=0,number-1 do
  26.         emu.frameadvance()
  27.         gui.text(30,170,'Total: '..total)
  28.         gui.text(30,190,'Last AP: '..ap_previous)
  29.     end
  30. end
  31.  
  32. --read the value of the address, if it doesnt exist in the Table, add it, otherwise increment
  33. function TableRecord(addr, t)
  34.     v = t[memory.readbyte(addr)]
  35.     if v == nil then
  36.         t[memory.readbyte(addr)] = 1
  37.     else
  38.         t[memory.readbyte(addr)] = v + 1
  39.     end
  40. end
  41.  
  42. --the main loop, this runs until the total number of trials are reached
  43. while true do
  44.     savestate.loadslot(save_state_slot);
  45.     --wait 2 frames (30fps game) and save the state, for changing the RNG for the next cycle
  46.     Wait(2);
  47.     savestate.saveslot(save_state_slot);
  48.    
  49.     --wait until the enemy AP updates to a good value
  50.     while ((ap_value == 33) or (ap_value == 0)) do
  51.         --press X and R2(in-game fast forward)
  52.         joypad.set({R2=true}, 1)
  53.         joypad.set({Cross=true}, 1)
  54.         Wait(2);
  55.         ap_value = memory.readbyte(ap_addr);
  56.     end
  57.        
  58.     --Record Values for this run
  59.     TableRecord(ap_addr, ap_t);
  60.     ap_previous = ap_value;
  61.     ap_value = 0;
  62.     total = total + 1;
  63.        
  64.     --check if we are finished, and print out the data to a file in CSV format
  65.     if(total == trials) then
  66.         file = io.open(file_prefix .. tostring(emu.framecount()) .. '.csv', "a")
  67.         io.output(file)
  68.        
  69.         io.write('Total, ', total, '\n')
  70.         io.write('\nAP, Count\n')
  71.         tprint(ap_t)
  72.         io.close(file)
  73.  
  74.         break
  75.     end
  76. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement