Thanks AmenMoses, I had tried that already but got the syntax wrong. It works nicely now! For anyone else who is interested, the script is attached.
-- LUA Script - precede every function and global member with lowercase name of script + '_main'
-- Sound emitter script
local soundrange = {}
function soundemitter_init(e)
soundrange[e] = g_Entity[e]['health']
end
function soundemitter_main(e)
PlayerDist = GetPlayerDistance(e)
if PlayerDist < soundrange[e] then
LoopSound(e,0)
Distvol = ((PlayerDist/soundrange[e])*100)
SetSoundVolume (100 - (Distvol/2)) -- for some reason dividing by 2 worked out better than leaving as is
--Prompt ( "volume=" .. (100 - Distvol))
end
end
I've been having a think about another hypothetical script, but my ambitions far outstrip my scripting and maths knowledge
Imagine a cave. From the depths, you hear an echoy sound. As you get closer, the sound gets clearer, you start to discern a tune. You finally come across a gramophone playing music and as you approach it, you can finally hear it clearly.
One method of doing this would be to have three separate audio files; one echoy, one mid, one near, and fade them in and out based on the distance of the player. Here's a graph of how the script would work (you can tell I'm better at visuals than scripting!)
I've got as far as thinking a triangle wave equation might be the solution (or possible sin if you wanted something smoother), but I have no idea where to go from here. I need to know if individual volume control on specific sound effects is possible.
Anyone got any idea on how to achieve this?
AE