Garry's Mod

Garry's Mod

Media Player
Architect 2018 年 7 月 25 日 上午 7:17
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> )
最后由 Architect 编辑于; 2018 年 7 月 25 日 上午 7:20
< >
正在显示第 1 - 3 条,共 3 条留言
angry cat meow at dusk 2018 年 7 月 30 日 上午 5:38 
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.
Architect 2018 年 7 月 30 日 上午 6:53 
no worries we're using another addon that isn't globally client sided to all entities. thanks for the help though.
Bbl4OK_OCEMEHNTEJI 2018 年 8 月 28 日 上午 12:37 
Where do I insert this code?:Binary_v2:
最后由 Bbl4OK_OCEMEHNTEJI 编辑于; 2018 年 8 月 28 日 上午 12:38
< >
正在显示第 1 - 3 条,共 3 条留言
每页显示数: 1530 50