--Function requires the same name as the file local sound_entity = 963 --entity assigned to this lua file local start_vol = 100 -- maximum sound volume local trigger_zone = 1000-- action zone radius local zone_segments = 20 -- create zone segments for each new location in the zone local inzone=0 function m3waterfall_init(sound_entity) end function m3waterfall_main(sound_entity) --this code segment calculates the volume changes required as the player passes by the waterfall inc = (math.floor(trigger_zone / zone_segments)) dist = GetPlayerDistance(sound_entity) new_dist = (math.floor(dist / inc)) vol = start_vol - new_dist if vol < 1 then vol = 1 end if GetPlayerDistance(sound_entity) < trigger_zone and inzone == 0 then --player is in the active zone SetSoundVolume(vol)--this is where the volume changes based on the above calculation PlaySoundIfSilent(sound_entity, 0) --Prompt("new dist = " .. new_dist .. " inc = " .. inc .." vol = " .. vol .." travel = " .. (math.floor(dist))) end if GetPlayerDistance(sound_entity) > trigger_zone then --player has left the active zone StopSound(sound_entity, 0) inzone = 1 end inzone = 0 end --when the player has completed his walk past the waterfall i lose the background sound wav. that is --attached to to start marker which is playing up until the time the player enters the area of the waterfall --but is lost when the player has passed the area of the waterfall lua file.