Add Export.lua
This commit is contained in:
parent
6e428de432
commit
693dfd1f15
64
Export.lua
Normal file
64
Export.lua
Normal file
@ -0,0 +1,64 @@
|
||||
--[[
|
||||
dcsw server map: Export.lua
|
||||
by Sacha Ligthert on 2024-01-14
|
||||
----
|
||||
|
||||
Add the following lines to your Export.lua in your ...\Saved Games\DCS.openbeta\Scripts folder.
|
||||
If they functions already exist, you will need to do some editing yourselves.
|
||||
]]--
|
||||
|
||||
function LuaExportStart()
|
||||
package.path = package.path..";"..lfs.currentdir().."/LuaSocket/?.lua"
|
||||
package.cpath = package.cpath..";"..lfs.currentdir().."/LuaSocket/?.dll"
|
||||
|
||||
socket = require("socket")
|
||||
IPAddress = "192.168.1.2"
|
||||
Port = 12345
|
||||
|
||||
MySocket = socket.try(socket.connect(IPAddress, Port))
|
||||
MySocket:setoption("tcp-nodelay",true)
|
||||
end
|
||||
|
||||
function LuaExportBeforeNextFrame()
|
||||
end
|
||||
|
||||
function LuaExportAfterNextFrame()
|
||||
end
|
||||
|
||||
function LuaExportStop()
|
||||
-- Terminate TCP connection
|
||||
if MySocket then
|
||||
socket.try(MySocket:send("exit\n"))
|
||||
MySocket:close()
|
||||
end
|
||||
end
|
||||
|
||||
function LuaExportActivityNextEvent(t)
|
||||
|
||||
-- Required to function normal
|
||||
local tNext = t
|
||||
|
||||
-- Grab objects. Create JSON. Send off to server
|
||||
local o = LoGetWorldObjects()
|
||||
local json = '{"units":['
|
||||
for k,v in pairs(o) do
|
||||
print(v.Type) -- add this line for debugging purposes
|
||||
local objectType = "unknown"
|
||||
objectType = type(v.Type)
|
||||
json = json .. string.format('{"age_in_seconds":"%.1f", "unit_name":"%s", "group_name":"%s", "name":"%s", "latitude":%f, "longitude":%f, "altitude_in_feet":%f, "heading_in_rads":%f, "pitch_in_rads":%f, "bank_in_rads":%f, "coalition":"%s", "type":"%s"},', t, v.UnitName, v.GroupName, v.Name, v.LatLongAlt.Lat, v.LatLongAlt.Long, v.LatLongAlt.Alt, v.Heading, v.Pitch, v.Bank, v.Coalition, objectType )
|
||||
end
|
||||
|
||||
-- Remove trialing comma
|
||||
json = json:sub(1, -2)
|
||||
|
||||
-- Wrap up JSON
|
||||
json = json .. "]}"
|
||||
|
||||
-- Send it awaaaaay!
|
||||
socket.try(MySocket:send(json))
|
||||
|
||||
-- Come back in 10 seconds
|
||||
tNext = tNext + 10.0
|
||||
return tNext
|
||||
|
||||
end
|
10
README.md
10
README.md
@ -1,3 +1,11 @@
|
||||
# exports_lua
|
||||
|
||||
The _exports.lua_ script running on DCS World Servers
|
||||
The _Export.lua_ script running on DCS World Servers for the Server Map
|
||||
|
||||
## Installation
|
||||
|
||||
Open `...\Saved Games\DCS.openbeta\Scripts\Export.lua` and add the contents of _Export.lua_ to this file.
|
||||
|
||||
**Note:** It could be that these functions already exist, then you will need to copy the contents of the functions yourself.
|
||||
|
||||
Modify the fields `IPAddress` and `Port` to point to the collector.
|
Loading…
x
Reference in New Issue
Block a user