--Function requires the same name as the file local sound_entity = 963 --entity assigned to this lua file local max_vol = 100 -- maximum sound volume local trigger_zone = 1072 -- action zone radius local zone_segments = 16 -- number of increments for a volume range of 84 to 100 local inzone = 0 local volume = 0 local dist = 0 local inc = 0 local volume_step = 0 function waterfall_volume_fade_init(sound_entity) end function waterfall_volume_fade_main(sound_entity) --calculate individual zone segment size based on the number of zone segments requested (16) inc = (math.floor(trigger_zone / zone_segments)) --will equal 65 using above variables dist = GetPlayerDistance(sound_entity) --find how far the player is from the center of zone volume_step = (math.floor(dist / inc)) --number of zone segments traveled becomes the steps in volume volume = max_vol - volume_step --volume level if dist < trigger_zone and inzone == 0 then --player is in the active zone PlaySoundIfSilent(sound_entity, 1) SetSoundVolume(volume)--this is where the volume changes based on the above calculation Prompt("volume = " .. volume .." Distance = " .. dist.." inc = " .. inc .." new_dist " .. volume_step) end if dist > trigger_zone and inzone == 0 then --player has left the active zone StopSound(sound_entity, 1) inzone = 1 end inzone = 0 end