Sound Distance ?

I need help with the distance of some sound.

I want to limit the printing noise to a certain size like 500.
[lua]
if self.MakePrintingSound then
self.Sound = CreateSound(self, Sound(“ambient/levels/labs/equipment_printer_loop1.wav”))
self.Sound:SetSoundLevel(self.SoundLevel)
end
[/lua]

and i also want to limit the bank robbery noise to approx 500 aswell. Currently the robbery plays globally.
[lua]
function BankRS.duringRobberySiren()
BroadcastLua(‘surface.PlaySound(“siren.wav”)’)

if BankConfig.loop then
    timer.Create("sirenLoop", SoundDuration("sound/siren.wav"), 0, function()
	    if !timer.Exists("robberyTimer") then
			timer.Destroy("sirenLoop")
		else
		    BroadcastLua('surface.PlaySound("siren.wav")')
		end
	end)
end

end
[/lua]

Broadcasting surface.PlaySound will ALWAYS be at full volume for anyone who receives said broadcast. Use sound.Play() instead. Also, you can use distance checking and replace BroadcastLua() with a net message.


--SERVER
util.AddNetworkString("RobberySiren")
local function doSiren(pos)
	local tab = {}
	for k,v in pairs(player.GetAll()) do
		if v:GetPos():Distance(pos) <= 500 then
			table.insert(tab, v)
		end
	end
	net.Start("RobberySiren")
		net.WriteVector(pos)
	net.Send(tab)
end

function BankRS.duringRobberySiren()
    doSiren(WhereEverTheAlarmIsComingFrom())
	
	if BankConfig.loop then
	    timer.Create("sirenLoop", SoundDuration("siren.wav"), 0, function()
		    if !timer.Exists("robberyTimer") then
				timer.Destroy("sirenLoop")
			else
			    doSiren(WhereEverTheAlarmIsComingFrom())
			end
		end)
    end
end

--CLIENT
local decibel = 75 --default
local function Siren(_)
	local pos = net.ReadVector()
	if !pos then return end --sanity check
	sound.Play("siren.wav", pos, decibel)
end
net.Receive("RobberySiren", Siren)

Im okay with the sounds playing at full volume, its the range im trying to affect. The printer seems to have a massive range (across map) and the Bank Is global. I want to limit them both to like 500

Added code for the bank thing. Also avoids the full volume issue I mentioned prior to editing.

Edit: The printer is going to be a little harder, I suspect. What are you using for the sound level?

The sound level is different per printer. The most basic printer is 90

That’s probably why it’s so loud. 75 is the default sound level.

While I wouldn’t recommend a specific enum, you can use this to get an idea of how loud your printers are according to the engine. The only way to make the volume independent of distance is to replace the entity’s CreateSound() with something resembling the above, but that has its own problems.

Edit: Try using a quieter decibel setting, then using CSoundPatch:ChangeVolume(num Volume, num DeltaTime = 0) (http://wiki.garrysmod.com/page/CSoundPatch/ChangeVolume) to handle the actual ‘volume’ of the printer.