Created
May 2, 2019 12:26
lua script x-plane visual helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require("graphics") | |
local window_x = 40 -- Display position from right edge of window | |
local window_y = 40 -- Display position from top edge of window | |
local show_wind = false | |
DataRef("WIND_DIR", "sim/cockpit2/gauges/indicators/wind_heading_deg_mag", "readonly") | |
DataRef("WIND_SPEED", "sim/cockpit2/gauges/indicators/wind_speed_kts", "readonly") | |
DataRef("HEADING", "sim/flightmodel/position/psi", "readonly") | |
local qs_heading = dataref_table("sim/cockpit/autopilot/heading_mag") | |
local qs_course = dataref_table("sim/cockpit/radios/nav1_obs_degm") | |
DataRef("QNH_PILOT", "sim/cockpit2/gauges/actuators/barometer_setting_in_hg_pilot", "readonly") | |
DataRef("QNH", "sim/weather/barometer_sealevel_inhg", "readonly") | |
function wind_main() | |
if show_wind then | |
XPLMSetGraphicsState(0,0,0,1,1,0,0) | |
local windTxt = "" | |
if WIND_SPEED > 10 then | |
windTxt = string.format("% d", WIND_SPEED) | |
else | |
windTxt = " " .. string.format("% d", WIND_SPEED) | |
end | |
graphics.set_color(0, 0, 0, 0.5) -- transparent grey | |
graphics.draw_filled_circle(SCREEN_WIDTH - window_x, SCREEN_HIGHT - window_y, 30) | |
if WIND_SPEED > 10 then | |
graphics.set_color(1, 0, 0, 0.8) -- red | |
else | |
graphics.set_color(0.0, 0.6, 0.0, 0.8) -- green | |
end | |
graphics.draw_circle(SCREEN_WIDTH - window_x, SCREEN_HIGHT - window_y, 30, 2) | |
if WIND_SPEED > 10 then | |
graphics.set_color(1, 0, 0, 0.8) -- red | |
else | |
graphics.set_color(0.0, 0.6, 0.0, 0.8) -- green | |
end | |
graphics.draw_angle_line(SCREEN_WIDTH - window_x, SCREEN_HIGHT - window_y, WIND_DIR - HEADING, 30) | |
graphics.draw_angle_arrow(SCREEN_WIDTH - window_x, SCREEN_HIGHT - window_y, WIND_DIR - HEADING + 180, 30, 15, 1) | |
graphics.set_color(1, 1, 1, 0.8) -- white | |
draw_string_Helvetica_12(SCREEN_WIDTH - window_x -12, SCREEN_HIGHT - window_y - 5, windTxt) | |
draw_string_Helvetica_12(SCREEN_WIDTH - window_x - 24, SCREEN_HIGHT - window_y - 45, "From " .. string.format("% d", WIND_DIR) .. "^") | |
if math.abs(QNH - QNH_PILOT) > 0.01 then | |
graphics.set_color(1, 0, 0, 0.8) -- red | |
else | |
graphics.set_color(0.0, 0.6, 0.0, 0.8) -- green | |
end | |
--draw_string_Helvetica_12(SCREEN_WIDTH - window_x - 32, SCREEN_HIGHT - window_y - 63, "QNH " .. string.format("% 2.2f", QNH)) | |
draw_string_Helvetica_12(SCREEN_WIDTH - window_x - 30, SCREEN_HIGHT - window_y - 65, "QNH " .. string.format("% d", math.floor(QNH * 33.8637526 + 0.5))) | |
graphics.set_color(1, 1, 1, 0.8) -- white | |
draw_string_Helvetica_12(SCREEN_WIDTH - window_x - 30, SCREEN_HIGHT - window_y - 75, "QNH " .. string.format("% d", math.floor(QNH_PILOT * 33.8637526 + 0.5))) | |
draw_string_Helvetica_12(SCREEN_WIDTH - window_x - 30, SCREEN_HIGHT - window_y - 85, "HDG " .. math.floor(qs_heading[0])) | |
draw_string_Helvetica_12(SCREEN_WIDTH - window_x - 30, SCREEN_HIGHT - window_y - 95, "CRS " .. math.floor(qs_course[0])) | |
end | |
end | |
function toggle_wind() | |
if show_wind then | |
show_wind = false | |
else | |
show_wind = true | |
end | |
end | |
create_command("lua/wind_toggle", "Wind direction toggle", "toggle_wind()", "", "") | |
do_every_draw("wind_main()") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment