Jump to content

trying to get lat/long of ownship in export.lua


steve2112

Recommended Posts

i wrote a simple Export.lua script

 

============================================

local log_file = nil

 

mist = mist or {}

mist.utils = mist.utils or {}

 

function LuaExportStart()

 

log_file = io.open("C:/Users/me/Saved Games/DCS/Scripts/Export.log", "w")

 

end

 

function LuaExportBeforeNextFrame()

end

function LuaExportAfterNextFrame()

end

 

function LuaExportStop()

if log_file then

log_file:write("Closing log file.")

log_file:close()

log_file = nil

end

end

 

function LuaExportActivityNextEvent(t)

 

local altBar = LoGetAltitudeAboveSeaLevel()

local altRad = LoGetAltitudeAboveGroundLevel()

local pitch, bank, yaw = LoGetADIPitchBankYaw()

local tas = LoGetTrueAirSpeed()

 

log_file:write(string.format(

"altBar=%.2f, pitch=%.2f, bank=%.2f tas=%.2f\n",

altBar, 57.3*pitch, 57.3*bank, tas))

 

local o = LoGetWorldObjects()

for k,v in pairs(o) do

log_file.write(string.format("t = %.2f, ID = %d, name = %s, country = %s(%s), LatLongAlt = (%f, %f, %f), heading = %f\n", t, k, v.Name, v.Country, v.Coalition, v.LatLongAlt.Lat, v.LatLongAlt.Long, v.LatLongAlt.Alt, v.Heading))

end

 

return t+0.5

end

============================================

 

pitch, bank, yaw and tas are all printing fine. but i'm trying to get the location of me, the player. best i could figure out was to use LoGetWorldObjects() which has lat longs in there ten figure out which is me. there is probably a better way, pls help.

 

but, when i run this script, i get a error in dcs.log

Export.lua - [string "C:\Users\me\Saved Games\DCS\Scripts\Export.lua"]:56: attempt to index global 'mist' (a nil value)

 

i assume that means i haven't set up mist yet but to be honest, i'm clueless.

 

any help please?

 

thx


Edited by steve2112

My kit: i7-4790K@4GHz / 8GB - GTX 980ti + rift CV1 - X52 pro - Multi Keyboard Remapper - 2DOF motion sim (in development)

Link to comment
Share on other sites

ok, i just got something working

 

function LuaExportActivityNextEvent(t)

 

local altBar = LoGetAltitudeAboveSeaLevel()

local altRad = LoGetAltitudeAboveGroundLevel()

local pitch, bank, yaw = LoGetADIPitchBankYaw()

local tas = LoGetTrueAirSpeed()

 

log_file:write(string.format(

"altBar=%.2f, pitch=%.2f, bank=%.2f tas=%.2f\n",

altBar, 57.3*pitch, 57.3*bank, tas))

 

local o = LoGetWorldObjects()

for k,v in pairs(o) do

log_file:write(string.format(

"ID=%d name=%s LatLong=(%f,%f)\n",

k, v.Name, v.LatLongAlt.Lat, v.LatLongAlt.Long))

end

 

return t+0.5

end

 

this works, but i'd still like to find a better way of getting only my lat long.

 

any ideas please?

My kit: i7-4790K@4GHz / 8GB - GTX 980ti + rift CV1 - X52 pro - Multi Keyboard Remapper - 2DOF motion sim (in development)

Link to comment
Share on other sites

i found what should be a better way LoGetSelfData(), but its not working

 

 

package.path  = package.path..";.\\LuaSocket\\?.lua"
package.cpath = package.cpath..";.\\LuaSocket\\?.dll"
 
socket = require("socket")
ipaddr = "239.255.50.10"
port = 5010

-- Lua Export Functions
function LuaExportStart()
conn = socket.udp()
conn:settimeout(0)
end

function LuaExportStop()
socket.try(conn:close())
end

function LuaExportBeforeNextFrame()
LoSetCommand(1032) -- iCommandThrottleIncrease	

end

function LuaExportAfterNextFrame()

socket.try(conn:sendto("hello from DCS", ipaddr , port))

local altBar = LoGetAltitudeAboveSeaLevel()
local pitch, bank, yaw = LoGetADIPitchBankYaw()
local tas = LoGetTrueAirSpeed()

local latPos = 99.9999
local longPos = 99.9999
local myPlane = LoGetSelfData()
if myPlane then
	latPos = MyPlane.LatLongAlt.Lat
	longPos = MyPlane.LatLongAlt.Lon
end

socket.try(conn:sendto(string.format(
		"altBar=%.2f, pitch=%.2f, bank=%.2f tas=%.2f LatLong=(%f,%f)\n", 
		altBar, 57.3*pitch, 57.3*bank, tas*1.6, latPos, longPos ),
		ipaddr , port))


end



 

when i run this, latPos and longPos come back as nil, i don't suppose anyone has an idea?

My kit: i7-4790K@4GHz / 8GB - GTX 980ti + rift CV1 - X52 pro - Multi Keyboard Remapper - 2DOF motion sim (in development)

Link to comment
Share on other sites

  • 9 months later...

Resurrecting an old thread...

 

Having the same problem in a script I wrote several years ago. Then it worked, but now when i try it again it for some reason does not.

I use the LoGetSelfData but it returns nil for me too.

 

Any progress steve2112?

Helicopters and Viggen

DCS 1.5.7 and OpenBeta

Win7 Pro 64bit

i7-3820 3.60GHz

P9X79 Pro

32GB

GTX 670 2GB

VG278H + a Dell

PFT Lynx

TrackIR 5

Link to comment
Share on other sites

local selfData = LoGetSelfData()
-- todo: handle case where LoGetSelfData() returns nil (happens in spectator mode, when crashed, etc)
-- todo: handle case where LoGetSelfData() does not return ownship position (MP server with allow_ownship_export ("Allow Player's Export") turned off)

local alt = selfData["LatLongAlt"]["Alt"]
local lat = selfData["LatLongAlt"]["Lat"]
local long = selfData["LatLongAlt"]["Long"]

  • Like 1
Link to comment
Share on other sites

Thank you both for quick answers!

I tried the syntax suggested by [FSF]Ian but it did not help (I use the . syntax)

 

But now to something strange.

After doing the test with [FSF]Ian's suggestion I returned my script back to my old original version, and now it suddenly worked! It did long ago, but not recently and certainly not earlier today...

 

What I believe happen here are a combination of a few things:

* My script contains UDP communications. I just read somewhere that the UDP connection needs to be established before anything else happens and I might have missed to start the receiving end early enough. Don't know how this can affect my LoGetSelfData call though

* I tested the script using a mission created by PeterP for testing his "Proper Neck for DCS World 1.2.6 - 1.2" mod. I believe it starts in spectator mode while selecting aircraft (i.e. you select aircraft when the mission has started). I did not know spectator mode would cause LoGetSelfData() to return nil, thanks for the hint [FSF]Ian!

 

So either one or both of these made it look like the script was broken. It wasn't.

Now I guess I need to add the todos ...

 

Thanks again!

Helicopters and Viggen

DCS 1.5.7 and OpenBeta

Win7 Pro 64bit

i7-3820 3.60GHz

P9X79 Pro

32GB

GTX 670 2GB

VG278H + a Dell

PFT Lynx

TrackIR 5

Link to comment
Share on other sites

  • Recently Browsing   0 members

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