-- Parafield to Renmark Mission for X-Plane 12 - Baron 58 -- Requires FlyWithLua NG -- Run only if correct aircraft and location if PLANE_ICAO ~= "BE58" then return end -- Basic vars local mission_started = false local timer = 0 local turbulence_active = false local severe_turbulence = false local arrival_announced = false -- Altitude and safety local cruise_alt = 7500 local altitude_deviation = 200 local turbulence_alt = 9500 local VNO = 165 -- Max structural cruise speed in KIAS -- DataRefs dataref("ias", "sim/cockpit2/gauges/indicators/airspeed_kts_pilot") dataref("altitude", "sim/cockpit2/gauges/indicators/altitude_ft_pilot") dataref("latitude", "sim/flightmodel/position/latitude") dataref("longitude", "sim/flightmodel/position/longitude") dataref("gps_dest_id", "sim/cockpit/radios/gps_nav_id", "string") -- Functions function say(msg) if SUPPORTS_SOUND then speak(msg) end end function set_weather(vis, clouds, turb) set("sim/weather/visibility_reported_m", vis * 1609.34) set("sim/weather/cloud_base_msl_m[0]", clouds * 0.3048) set("sim/weather/turbulence[0]", turb) end function distance_to(lat1, lon1, lat2, lon2) local R = 3440.065 -- NM local dlat = math.rad(lat2 - lat1) local dlon = math.rad(lon2 - lon1) local a = math.sin(dlat/2)^2 + math.cos(math.rad(lat1)) * math.cos(math.rad(lat2)) * math.sin(dlon/2)^2 local c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a)) return R * c end -- Renmark Airport Coordinates local yren_lat = -34.1969 local yren_lon = 140.674 -- Mission Initialization function start_mission() mission_started = true timer = 0 say("Mission started. Cruise at 7500 feet. Weather will deteriorate.") set_weather(10, 4000, 0.1) end -- Main logic loop function mission_tick() if not mission_started then -- Auto-start if near YPPF (Parafield) local dist = distance_to(latitude, longitude, -34.7933, 138.628) if dist < 3 then start_mission() end return end timer = timer + get("sim/operation/misc/frame_rate_period") -- After 5 minutes if timer > 300 and timer < 600 then set_weather(6, 3000, 0.2) end -- After 10 minutes if timer > 600 and timer < 900 then set_weather(3, 2500, 0.5) say("Weather worsening. Turbulence moderate.") end -- After 15 minutes if timer > 900 and not severe_turbulence then set_weather(3, 2000, 0.8) say("Severe turbulence. Climb above 9500 feet to reduce effects.") severe_turbulence = true end -- Turbulence safety warning if severe_turbulence and altitude < turbulence_alt and ias > VNO then say("Reduce speed below VNO to prevent structural damage.") end -- Arrival Detection local d = distance_to(latitude, longitude, yren_lat, yren_lon) if d < 3 and string.match(gps_dest_id, "YREN") and not arrival_announced then say("Arrival at Renmark detected. Mission complete.") arrival_announced = true end end do_every_frame("mission_tick()")