Garry's Mod

Garry's Mod

Media Player
Alchemist 25. juli 2018 kl. 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> )
Sidst redigeret af Alchemist; 25. juli 2018 kl. 7:20
< >
Viser 1-3 af 3 kommentarer
sad cat meow in rain 30. juli 2018 kl. 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.
Alchemist 30. juli 2018 kl. 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 28. aug. 2018 kl. 0:37 
Where do I insert this code?:Binary_v2:
Sidst redigeret af Bbl4OK_OCEMEHNTEJI; 28. aug. 2018 kl. 0:38
< >
Viser 1-3 af 3 kommentarer
Per side: 1530 50