Thanks to everyone.
I have what I want now and it works fine. (see the attachment) I still have a problem with the volume though.
I will take a look at the code from roandoom and see if his volume code works for me.
Again thanks to all, you have all been very helpful.
Edit: I have the sound volume now working. The problem is that the volume range is about 85 to 100. Anything below 85 is almost silent. 100 appears to be the higher limit. Not a great command but will suffice. One more time "Thanks to everyone"
--Function requires the same name as the file
local soundPlaying = 0
local vol = 82 -- water volume
local trigger = 3000 -- activate distance
local sound_entity = 125 --entity assigned to this lua file
function river_sound_init(e)
end
function river_sound_main(e)
if GetPlayerDistance(sound_entity) < trigger then
ActivateIfUsed(sound_entity)
if soundPlaying == 0 then
SetSoundVolume(vol)
PlaySoundIfSilent(sound_entity, 0)
end
else
if GetPlayerDistance(sound_entity) > trigger then
StopSound(sound_entity, 0)
end
end
end
Windows 10,64 bit|AMD FX-6200 Six-core-3.80 Ghz |CPU PASSMARK 6,142 |Memory 10GB |NVIDIA GEFORCE GTX 660 SC |GPU PASSMARK 4,114