PAYDAY-2-BeardLib icon indicating copy to clipboard operation
PAYDAY-2-BeardLib copied to clipboard

Weapons with custom underbarrels can crash other players

Open Lolnoobwut1 opened this issue 4 years ago • 2 comments

Switching to and firing a custom underbarrel will crash other players in the lobby.

lib/units/weapons/newnpcraycastweaponbase calls a function named _sound_singleshot to get the sound to play for the gun, leading to the crash. Normally this would work fine as the game usually looks for the _crew variant of the gun to get the sounds, but underbarrels look for an _npc variant instead.

I'm not sure how to implement this in BeardLib, but this is how we fixed it in Restoration Mod:

  • Add the following to WeaponTweakData:_create_table_structure()
self.[custom_underbarrel_name]_npc = {
	usage = "is_rifle",
	sounds = {},
	use_data = {},
	auto = {}
}
  • Add the rest of the necessary definitions to WeaponTweakData:init:
	self.[custom_underbarrel_name]_npc.sounds.prefix = "contrabandm203_npc"
	self.[custom_underbarrel_name]_npc.use_data.selection_index = 2
	self.[custom_underbarrel_name]_npc.DAMAGE = 2
	self.[custom_underbarrel_name]_npc.muzzleflash = "effects/payday2/particles/weapons/9mm_auto"
	self.[custom_underbarrel_name]_npc.shell_ejection = "effects/payday2/particles/weapons/shells/shell_9mm"
	self.[custom_underbarrel_name]_npc.no_trail = true
	self.[custom_underbarrel_name]_npc.CLIP_AMMO_MAX = 3
	self.[custom_underbarrel_name]_npc.NR_CLIPS_MAX = 1
	self.[custom_underbarrel_name]_npc.auto.fire_rate = 0.1
	self.[custom_underbarrel_name]_npc.hold = "rifle"
	self.[custom_underbarrel_name]_npc.alert_size = 2800
	self.[custom_underbarrel_name]_npc.suppression = 1
	self.[custom_underbarrel_name]_npc.FIRE_MODE = "auto"

Only the first line with the sound prefix should be necessary, though the rest were included to be safe.

To fix it for clients that don't have the underbarrel, you would likely have to spoof it as contraband_m203_npc.

Lolnoobwut1 avatar Sep 03 '20 04:09 Lolnoobwut1

GitHub, when I say I attempt to fix, I mean I ATTEMPT to fix not I fixed.

Luffyyy avatar Sep 30 '20 18:09 Luffyyy

Can you confirm if this happens as of the last commit?

Luffyyy avatar Mar 12 '21 21:03 Luffyyy

Closing this die to old age and presumably being fixed

segabl avatar Oct 16 '22 23:10 segabl