Advertisement
EvilAsh25

DW4 - kill single metal script

Jan 18th, 2017
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.24 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, with 1 Metal slime
  3.  
  4. --Set the correct memory domain
  5. memory.usememorydomain("System Bus")
  6.  
  7. --define variables
  8. wins = 0
  9. runs = 0
  10. para = 0
  11. total = 0
  12. save_state_slot = 0 -- which quickload slot to load from
  13. rng1 = 0
  14. rng2 = 0
  15. rng3 = 0
  16.  
  17. --Wait function for advancing 1 frame and displaying results on the screen
  18. function Wait(number)
  19.     for i=0,number-1 do
  20.         emu.frameadvance()
  21.         --display the metal slime's HP
  22.         gui.text(120,150,'HP: '..(memory.readbyte(0x727E) + memory.readbyte(0x727F) * 256))
  23.        
  24.         gui.text(30,170,'Total: '..total)
  25.        
  26.         if(total ~= 0) then
  27.             gui.text(30,210,'Wins: '..wins..' ('..(math.floor(1000 * wins / (total)) / 10)..'%)')
  28.             gui.text(30,230,'Run: '..runs..' ('..(math.floor(1000 * runs / (total)) / 10)..'%)')
  29.             gui.text(30,250,'Para: '..para..' ('..(math.floor(1000 * para / (total)) / 10)..'%)')
  30.         end
  31.     end
  32. end
  33.  
  34. --the main loop, this runs forever
  35. while true do
  36.     --load the savestate (a single Metal Slime)
  37.     savestate.loadslot(save_state_slot);
  38.    
  39.     --load the previous rng values back into the state
  40.     memory.writebyte(0x0012,rng1);
  41.     memory.writebyte(0x0013,rng2);
  42.     memory.writebyte(0x050D,rng3);
  43.  
  44.     --while the metal slime's HP is still greater than 0, run the attack loop
  45.     while (memory.readbyte(0x727E) > 0x00) do
  46.         Wait(math.random(5)+1); --wait a random number of frames
  47.         joypad.set({A=true}, 1)
  48.         Wait(1);
  49.         joypad.set({A=false}, 1)
  50.        
  51.         --this reads the status byte and detects if the metal slime ran away, and breaks the loop
  52.         if (memory.readbyte(0x727A) == 0x01) then break end
  53.     end
  54.    
  55.         --read the variables we need to record data
  56.         status = memory.readbyte(0x727A);      
  57.                    
  58.         if status == 0x01 then
  59.             --this means the slime ran
  60.             runs = runs + 1;
  61.         elseif status == 0xE0 then
  62.             --this means the slime was paralyzed and killed (only relevant if Brey is equipped with the Venomous Dagger)
  63.             wins = wins + 1;
  64.             para = para + 1;
  65.         else
  66.             --Metal Slime was killed
  67.             wins = wins + 1;
  68.         end
  69.        
  70.         total = total + 1;
  71.        
  72.         --save the RNG values for the next loop
  73.         rng1 = memory.readbyte(0x0012)
  74.         rng2 = memory.readbyte(0x0013)
  75.         rng3 = memory.readbyte(0x050D)
  76.        
  77.         Wait(1);
  78.    
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement