Jump to content

How to list your flight-times via LUA-script (flight logbook)


Atari800XL

Recommended Posts

2nd try:

some weeks ago I asked the support, how to list my flight-times. They said, look into logbook.lua. So I wrote a little script to list my flight-times descending and formatted. Maybe usefull for others, must be executed in your saved-games directory.

 

-- personal logbook for flights DCS
-- execute this file in do C:\Users\{{YOUR_USERNAME}}\Saved Games\DCS.openbeta\MissionEditor
-- to get the exact flight times of variant models.
dofile("logbook.lua")

function secToHMS(sec_o)
  local sec = math.floor(sec_o)
  local h = 0
  local m = 0

  while sec >= 3600 do
    h = h + 1
    sec = sec - 3600
  end
  while sec >= 60 do
    m = m + 1
    sec = sec - 60
  end
  sec = math.floor(sec)
  local ret = str_pad_left(h, 4, "0") .. ":" .. str_pad_left(m, 2, "0") .. ":" .. str_pad_left(sec, 2, "0")
  return ret
end

function str_pad_left(s, l, char)
  while string.len(s) < l do
    s = char .. s
  end
  return s
end

function compare(a, b)
  return a[2] > b[2]
end

function roundNumber(i, d)
  local mult = 10 ^ (d or 0)
  return math.floor(i * mult + 0.5) / mult
end

branch = logbook["players"][1]["statistics"]

print()
print("my flight log:")
print()
flights = {}
total = 0
for k, v in pairs(branch) do
  if type(v) == 'table' then
    time = math.floor(v["flightHours"])
    total = total + time
    table.insert(flights, {k, time})
  end
end
table.sort(flights, compare)
for i, e in pairs(flights) do
  perc = roundNumber(e[2] / (total / 100), 2)
  print(str_pad_left(e[1], 15, " ") .. " : " .. secToHMS(e[2]) .. " ~" .. perc .. "%")
end
print("")
d = roundNumber(total / (24 * 60 * 60), 2)
print((str_pad_left("total", 15, " ") .. " : " .. secToHMS(total)) .. " (~" .. d .. " days non-stop)")

 

 

image.png


Edited by Atari800XL

DCS MT😍, all maps except channel, FC3, F-16C Viper, F-15E, F/A-18C, AH-64D, F-5E, F-4E, P-51D, Spitfire, Fw-190D, MiG-21bis, L-39, AJS-37
Supercarrier, WWII-AP, CA, TrackIR5, F/A-18-Stick + Thrustmaster 16000, Stream Deck 8x4, 2x MFD Cougar
Ryzen9 5950X SMT off, 64GB RAM, RTX 4070 SUPER TI, UWQHD 3440x1440, Win11+DCS from separate M.2

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...