Garry's Mod

Garry's Mod

Media Player
Alchemist 25 Jul, 2018 @ 7:17am
Lua Help - Distance & Volume
Hi guys we are modding this addon a little bit so you don't have to Press E for it to work, which we have done, now we're working on getting the volume to fade as you get further away, here is the code, it all works except for the fading volume, if anyone can take a look and try get it working we would really appreciate it.

function ENT:Think() local mp = self:GetMediaPlayer() for k, v in pairs( player.GetAll() ) do local dis = self:GetPos():Distance( v:GetPos() ) if dis >= 300 then mp:RemoveListener(v) else if mp:HasListener(v) then MediaPlayer.Volume( 0.1 / dis ) else mp:AddListener(v) end end end end

We have tried
MediaPlayer.Volume ( <value> )

mp.Volume( <value> )

and
local media = mp:CurrentMedia() media:Volume( <value> )
Last edited by Alchemist; 25 Jul, 2018 @ 7:20am
< >
Showing 1-3 of 3 comments
Make sure MediaPlayer.Volume is changed client-side.

function ENT:Think() if SERVER then local mp = self:GetMediaPlayer() for k, v in pairs( player.GetAll() ) do local dis = self:GetPos():Distance( v:GetPos() ) if dis >= 300 then mp:RemoveListener(v) elseif not mp:HasListener(v) then mp:AddListener(v) end end else --CLIENT local dis = self:GetPos():Distance( LocalPlayer():GetPos() ) MediaPlayer.Volume( 0.1 / dis ) end end

Note however that MediaPlayer.Volume is global for all Media Players, so this will only work properly with one Media Player entity. If you're planning on having multiple Media Players on the map you might just be better off waiting for the built-in 3D audio to get fixed.

Alternatively you could dive deeper into the files and try to edit the Media Player itself to incorporate this.
Alchemist 30 Jul, 2018 @ 6:53am 
no worries we're using another addon that isn't globally client sided to all entities. thanks for the help though.
Bbl4OK_OCEMEHNTEJI 28 Aug, 2018 @ 12:37am 
Where do I insert this code?:Binary_v2:
Last edited by Bbl4OK_OCEMEHNTEJI; 28 Aug, 2018 @ 12:38am
< >
Showing 1-3 of 3 comments
Per page: 1530 50