Advertisement
offyerrocker

AutoFireSoundFix.lua

Jun 24th, 2017
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.28 KB | None | 0 0
  1. -- Header comment that will likely be deleted. This was made by 90e.
  2. --Auto-Fire SoundFix, unofficial patch
  3. --Changes from official version:
  4. --No longer crashes, supports underbarrel attachments
  5. --7/2/17 Made code look less hideous, thanks to Llamageddon! (https://modworkshop.net/member.php?action=profile&uid=42988)
  6.  
  7. -- <3 Offy
  8.  
  9.  
  10. -- Unless this weapon should follow standard logic...
  11. function RaycastWeaponBase:_soundfix_should_play_normal()
  12.     local name_id = self:get_name_id()
  13.     if tweak_data.weapon[name_id].sounds.fire_single == nil or self:gadget_overrides_weapon_functions() then
  14.         return true
  15.     end
  16.     return false
  17. end
  18.  
  19. -- ...don't play a sound conventionally...
  20. local original_fire_sound = RaycastWeaponBase._fire_sound
  21. function RaycastWeaponBase:_fire_sound()
  22.     if self:_soundfix_should_play_normal() then
  23.         original_fire_sound(self)
  24.     end
  25. end
  26.  
  27. -- ...and instead play the single fire noise here
  28. local original_fire = RaycastWeaponBase.fire
  29. function RaycastWeaponBase:fire(...)
  30.     local result = original_fire(self, ...)
  31.    
  32.     -- TODO?: Why should this have to check for result?
  33.     if not self:_soundfix_should_play_normal() and result then
  34.         self:play_tweak_data_sound("fire_single", "fire")
  35.     end
  36.  
  37.     return result
  38. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement