View difference between Paste ID: 6PcVgQAj and tH3rr9ie
SHOW: | | - or go back to the newest paste.
1
-- Header comment that will likely be deleted. This was made by 90e.
2-
--Auto-Fire SoundFix, unofficial patch
2+
--24 June 2017, fixed Little Friend 7.62/contrabandm203 using single fire bullet shot when using underbarrel grenade launcher mode
3-
--Changes from official version:
3+
4-
--No longer crashes, supports underbarrel attachments
4+
5-
--7/2/17 Made code look less hideous, thanks to Llamageddon! (https://modworkshop.net/member.php?action=profile&uid=42988)
5+
-- Don't play a sound conventionally (unless using the saw which lacks a single fire sound)
6
7
local base_fire_sound = RaycastWeaponBase._fire_sound
8
9
function RaycastWeaponBase:_fire_sound()
10-
-- Unless this weapon should follow standard logic...
10+
	if self:get_name_id() == "saw" or self:get_name_id() == "saw_secondary" or self:get_name_id() == "m134" or self:get_name_id() == "flamethrower_mk2" or self:get_name_id() == "mg42" then
11-
function RaycastWeaponBase:_soundfix_should_play_normal()
11+
		base_fire_sound(self)
12-
    local name_id = self:get_name_id()
12+
	end --to delete?
13-
    if tweak_data.weapon[name_id].sounds.fire_single == nil or self:gadget_overrides_weapon_functions() then 
13+
14-
        return true
14+
15
-- Instead play the single fire noise here
16-
    return false
16+
17
local old_fire = RaycastWeaponBase.fire
18
function RaycastWeaponBase:fire(...)
19-
-- ...don't play a sound conventionally...
19+
    local result = old_fire(self, ...)
20-
local original_fire_sound = RaycastWeaponBase._fire_sound
20+
21
    -- Don't try playing the single fire sound with the saw; minigun = m134
22-
    if self:_soundfix_should_play_normal() then
22+
    if self:get_name_id() == "saw" or self:get_name_id() == "saw_secondary" or self:get_name_id() == "m134" or self:get_name_id() == "flamethrower_mk2" or self:get_name_id() == "mg42" then
23-
        original_fire_sound(self)
23+
        return result
24
    end
25
26-
 
26+
    if result and not self:gadget_overrides_weapon_functions() then
27-
-- ...and instead play the single fire noise here
27+
28-
local original_fire = RaycastWeaponBase.fire
28+
	elseif self:gadget_overrides_weapon_functions() then
29
		self:play_tweak_data_sound(self:fire_mode() == "auto" and "fire_auto" or "fire_single", "fire")
30-
    local result = original_fire(self, ...)
30+
	end
31-
    
31+
32-
    -- TODO?: Why should this have to check for result?
32+
33-
    if not self:_soundfix_should_play_normal() and result then
33+
34
function RaycastWeaponBase:play_tweak_data_sound(event, alternative_event)
35
	local sounds = tweak_data.weapon[self._name_id].sounds
36-
 
36+
	
37
	--overrides and uses vanilla method to determine "event" if using the little friend underbarrel mode
38
	--clumsy method of determining which way to get event and play_sound, will fix that later probably 
39
	if self:gadget_overrides_weapon_functions() then
40
	local event = self:_get_sound_event(event, alternative_event)
41
		self:play_sound(event)
42
	elseif event then
43
		local event = (sounds and (sounds[event] or sounds[alternative_event])) --otherwise uses AFSF's singlefire override
44
		self:play_sound(event)
45
	end
46
end