D0nyAlcap0ney

Code for Reload Tutorial

Mar 7th, 2025 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Game Maker 6.22 KB | Source Code | 0 0
  1. ///Code for adding gun reloads to Hotline Miami 1 source. GMS1 (and posssibly GMS2???) compatible.
  2.  
  3.  
  4. ///DISCLAIMER: I FUCKED UP AND THUS SOME PARTS OF THIS PASTE WILL BE CHANGED FROM HOW THEY ARE PRESENTED IN THE VIDEO. CHECK PINNED COMMENT FOR MORE INFO.
  5.  
  6.  
  7.  
  8. //First, add these two global variables to the create event of objTitle.
  9.  
  10. //Global ammo variables.
  11. global.mags = 0
  12. global.shells = 0
  13.  
  14.  
  15.  
  16.  
  17. //Next add the following local and global variables to the create event of objPlayerMouse.
  18. mags = global.mags
  19. shells = global.shells
  20. global.reloadspeed = yourspeedhere
  21.  
  22.  
  23.  
  24. //Then, add a destroy event to objPlayerMouse and set these variables within the destroy event.
  25. global.mags = mags
  26. global.shells = shells
  27.  
  28.  
  29.  
  30.  
  31. //Next add these script calls to their respective places
  32. scrReload() - Step event of objPlayerMouse
  33. scrReloadManually() - Press R Key event of objPlayerMouse
  34. scrReloadManuallyShotguns() - Press R Key event of objPlayerMouse
  35. scrIsReloading(sprite_index) - scrPlayerPickup2 and scrPlayerPickup1
  36.  
  37.  
  38. //Now we can add tracking for shells and mags to the player's HUD. Keep in mind that this is not a tutorial covering UI.
  39.  
  40. //Add this code to around line 87 in scrScoreDrawStory. (Given that you haven't already edited it in any way)
  41.  
  42. if objPlayer.shells > 0 ammostring = string(objPlayer.ammo) + "/" + string(maxammo) + "rnds" + " |" + string(objPlayer.shells) + " reserve"
  43.         else if objPlayer.mags > 0 ammostring = string(objPlayer.ammo) + "/" + string(maxammo) + "rnds" + " |" + string(objPlayer.mags) + " reserve"
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50. //scrIsReloading
  51. if argument0 = sprPReloadDoubleBarrel
  52. or argument0 = sprPReloadSilencer
  53. or argument0 = sprPReloadShotgun
  54. or argmuent0 = sprPCockShotgun
  55. return true
  56.  
  57.  
  58.  
  59.  
  60. //scrReloadManually
  61. if sprite_index = sprPWalkSilencer {
  62.     if ammo < 13 and mags > 0 {
  63.     sprite_index = sprPReloadSilencer
  64.     image_index = 0
  65.     image_speed = 0
  66. }
  67. }else exit
  68.  
  69.  
  70.  
  71. //scrReloadManuallyShotguns
  72. if sprite_index = sprPWalkDoubleBarrel {
  73.         if ammo < 2 and shells > 0 {
  74.         sprite_index = sprPReloadDoubleBarrel
  75.         image_index = 0
  76.         image_speed = 0
  77.         }
  78.         }
  79.        
  80.   if sprite_index = sprPWalkShotgun {
  81.     if ammo < 6 and shells > 0 {
  82.     sprite_index = sprPReloadShotgun
  83.     image_index = 0
  84.     image_speed = 0
  85.     }
  86.     }
  87.    
  88.    
  89.    else exit
  90.    
  91.    
  92.    
  93.    
  94.    
  95.    
  96.    
  97. //scrReload
  98.  
  99. //Check if the player is currently reloading and whether or not they have the reserve ammo to reload.
  100. if scrIsReloading(sprite_index) and shells > 0 or scrIsReloading(sprite_index) and mags > 0 {
  101.  
  102.  //Double Barrel Reload
  103.      if ammo < 2 and shells > 0 {
  104.      if sprite_index = sprPReloadDoubleBarrel {
  105.         if image_index < sprite_get_number(sprite_index) - 1 {
  106.             image_index += global.reloadspeed * 1.5
  107.             if image_index >= 3 and image_index - global.reloadspeed < 3 {
  108.                 repeat (2) {
  109.                     my_id = instance_create(x + lengthdir_x(5, dir - 5 * left), y + lengthdir_y(5, dir - 5 * left), objShell)
  110.                     my_id.sprite_index = sprShotgunShell
  111.                     my_id.image_angle = dir
  112.                     my_id.direction = dir - 90 * left - 20 + random(30)
  113.                     my_id.speed = 1 + random(2)
  114.                    }
  115.                 }  
  116.            
  117.    
  118.             if image_index >= 11 and image_index - global.reloadspeed * 1.5 < 11 audio_play_sound(sndInsertShell, 0, false)
  119.             if image_index >= 16 and image_index - global.reloadspeed * 1.5 < 16 audio_play_sound(sndInsertShell, 0, false)
  120.  
  121.         } else {
  122.            
  123.          ammo = 2;  //Refill the ammo.
  124.                 shells -= 2;  //Decrement the number of shells.
  125.                 if shells <= 0 shells = 0;  //Ensure shells don't go below zero.
  126.                
  127.                 if sprite_index = sprPReloadDoubleBarrel sprite_index = sprPWalkDoubleBarrel;
  128.                 }
  129.             }
  130.          }
  131.          
  132.          
  133.          
  134.          
  135.          
  136.          
  137.          
  138.  //Silencer Reload
  139.          if ammo < 13 and mags > 0 {
  140.          if sprite_index = sprPReloadSilencer {
  141.         if image_index < sprite_get_number(sprite_index) - 1 {
  142.             image_index += global.reloadspeed
  143.             if image_index >= 5 and image_index - global.reloadspeed < 5 {
  144.                 audio_play_sound(sndEjectClipHandgun, 0, false)
  145.                 my_id = instance_create(x + lengthdir_x(5, dir - 5 * left), y + lengthdir_y(5, dir - 5 * left), objGunClip)
  146.                 my_id.image_index = 3
  147.                 my_id.image_angle = dir
  148.                 my_id.direction = dir - 90 * left - 20 + random(30)
  149.                 my_id.speed = 1 + random(2)
  150.             }
  151.            
  152.             if image_index >= 10 and image_index - global.reloadspeed < 10 audio_play_sound(sndInsertClipHandgun, 0, false)
  153.         } else {
  154.             ammo = 13
  155.             mags -= 1
  156.             if sprite_index = sprPReloadSilencer sprite_index = sprPWalkSilencer
  157.             audio_play_sound(sndSlideHandgun, 0, false)
  158.         }
  159.     }
  160. }      
  161.  
  162.  
  163.  
  164.  
  165.  
  166. //Shotgun Reload
  167.  if sprite_index = sprPReloadShotgun {
  168.         if ammo < 6 and shells > 0 {
  169.             if image_index * 10 = 47.5 audio_play_sound(sndInsertShell, 0, false)
  170.             if image_index < 9 image_index += global.reloadspeed else {
  171.                 ammo += 1
  172.                 shells -= 1
  173.                 image_index = 5
  174.                 audio_play_sound(sndInsertShell, 0, false)
  175.                 if shells = 0 { sprite_index = sprPCockShotgun image_speed = 0.25 audio_play_sound(sndCockShotgun, 0, false) exit }
  176.             }
  177.         } else {
  178.             if image_index < sprite_get_number(sprite_index) - 1 image_index += global.reloadspeed
  179.             else {
  180.                 audio_play_sound(sndCockShotgun, 0, false)
  181.                 sprite_index = sprPCockShotgun
  182.                 image_speed = 0.25
  183.             }
  184.         }
  185.     }  
  186.    
  187.     }
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195. ///objGunClip
  196.  
  197.  
  198. //Create
  199.  
  200. image_speed=0
  201. dir=0
  202. ammo=0
  203. friction=0.1
  204.  
  205.  
  206. //Step
  207.  
  208. if speed>0 image_angle+=sign(vspeed)*speed*3
  209.  
  210.  
  211.  
  212. //Collisions
  213.  
  214. move_bounce_all(0)
  215. speed*=0.2
  216.  
  217.  
  218.  
  219.  
  220. //Draw
  221.  
  222. draw_sprite_ext(sprite_index,image_index,x,y,image_xscale,image_yscale,image_angle,image_blend,image_alpha)
  223.  
Add Comment
Please, Sign In to add comment