Skip to content

Commit 1ef0f63

Browse files
authored
Add level setting, also play regardless of distance/location (#2183)
1 parent ec99005 commit 1ef0f63

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lua/entities/gmod_wire_soundemitter.lua

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ function ENT:Initialize()
2424
self:SetSolid( SOLID_VPHYSICS )
2525

2626
self.Inputs = WireLib.CreateInputs(self, { "A", "Toggle", "Volume", "Play", "Stop",
27-
"PitchRelative", "Sample", "SampleName [STRING]" })
27+
"PitchRelative", "Sample", "SampleName [STRING]", "Level" })
2828
self.Outputs = WireLib.CreateOutputs(self, { "Duration", "Property Sound", "Properties [ARRAY]", "Memory" })
2929

3030
self.Samples = table.Copy(DefaultSamples)
3131

3232
self.Active = false
3333
self.Volume = 100
34+
self.Level = 80
3435
self.Pitch = 100
3536
self.sound = self.Samples[1]
3637
-- self.sound is a string, self.SoundObj is a CSoundPatch
@@ -54,6 +55,7 @@ end
5455
1: volume
5556
2: pitchrelative
5657
3: duration
58+
6: level
5759
]]
5860
function ENT:ReadCell(address)
5961
address = math.floor(address)
@@ -65,6 +67,8 @@ function ENT:ReadCell(address)
6567
return self.Pitch / 100
6668
elseif address == 3 then
6769
return self.Outputs.Duration.Value
70+
elseif address == 6 then
71+
return self.Level
6872
end
6973
end
7074

@@ -77,6 +81,7 @@ local cellsOut = {
7781
[3] = "Sample",
7882
[4] = "Play",
7983
[5] = "Stop",
84+
[6] = "Level",
8085
}
8186

8287
function ENT:WriteCell(address, value)
@@ -114,6 +119,8 @@ function ENT:TriggerInput(iname, value)
114119
self:StopSounds()
115120
elseif iname == "Volume" then
116121
self.Volume = math.Clamp(math.floor(value*100), 0.0, 100.0)
122+
elseif iname == "Level" then
123+
self.Level = math.Clamp(value, 55.0, 165.0)
117124
elseif iname == "PitchRelative" then
118125
self.Pitch = math.Clamp(math.floor(value*100), 0, 255)
119126
elseif iname == "Sample" then
@@ -127,7 +134,9 @@ end
127134
function ENT:UpdateSound()
128135
if self.NeedsRefresh or self.sound ~= self.ActiveSample then
129136
self.NeedsRefresh = nil
130-
self.SoundObj = CreateSound(self, self.sound)
137+
local filter = RecipientFilter()
138+
filter:AddAllPlayers()
139+
self.SoundObj = CreateSound(self, self.sound, filter)
131140
self.ActiveSample = self.sound
132141

133142
self.SoundProperties = sound.GetProperties(self.sound)
@@ -144,6 +153,7 @@ function ENT:UpdateSound()
144153
end
145154
self.SoundObj:ChangePitch(self.Pitch, 0)
146155
self.SoundObj:ChangeVolume(self.Volume / 100.0, 0)
156+
self.SoundObj:SetSoundLevel(self.Level)
147157
end
148158

149159
function ENT:SetSound(soundName)

0 commit comments

Comments
 (0)