Community Forum

Export data FS19

Forum Overview >> Scripting

Created01.02.2022 14:30

Mario Tilocca (Mario_Tilocca) 01.02.2022 14:30
Hey guys!
I am pretty much a newbie creating mods so maybe for you this is a very simple task.

For a project I would need to make a simple script where the position of the player and some parameters from the vehicle, such as velocities, steering angles and rpm are saved into an external .txt file.
I have read the LUADOC documentation extensively but I could not find anything that could help with this ...

Thank you so much for your help!! :)

Loki Laufeyson (loki_79) 03.02.2022 09:28
If it is just for reading later, then you can use print to write to the game log.txt file:
local px, py, pz = getWorldTranslation(g_currentMission.player.rootNode)
print(string.format("x,y,z = %s,%s,%s\n", tostring(px), tostring(py), tostring(pz)))

Or, it is not much more work to write your own file:
local px, py, pz = getWorldTranslation(g_currentMission.player.rootNode)
local myFile = getUserProfileAppPath() .. "myFileName.txt"
local file =, "w")
file:write(string.format("%s,%s,%s\n", tostring(px), tostring(py), tostring(pz)))

If you need data in real time, there are things like this:

Mario Tilocca (Mario_Tilocca) 04.02.2022 17:37
Thank you so much Loki! That helped really a lot. I
Now I am trying to export some parameters while driving a vehicle for each frame but it exports only the last data from the game. Also I was trying to get the vehicle wheels rpms and steering angles but did not manage to find anything or make anything work sadly.

Do you guys have any suggestion for how to solve this issue and how to get the vehicle wheels rpms and steering angles ?

Thank you so much again for helping me :)

Here's the code I have made.


dataExport ={
frame = 0,
count = 0

function dataExport:update(dt)
local myFile = getUserProfileAppPath() .. "data.txt"
local file =, "w")
if g_currentMission.player ~= nil and self.count ~=1 then

self.count = self.count + 1


if g_currentMission.controlledVehicle ~= nil then
local px, py, pz = getWorldTranslation(g_currentMission.controlledVehicle.rootNode)
local vx, vy, vz = getLinearVelocity(g_currentMission.controlledVehicle.rootNode)
local rpm, clutch_rpm, motorload = getMotorRotationSpeed(g_currentMission.controlledVehicle.rootNode)
local omegaX, omegaY, omegaZ = getAngularVelocity(g_currentMission.controlledVehicle.rootNode)

renderText(0.7, 0.3, 0.02, px .. ";"";"..pz)
file:write(string.format("%s; %s; %s; %s; %s; %s; %s; %s; %s; %s\n", tostring(px), tostring(py), tostring(pz), tostring(vx), tostring(vy), tostring(vz), tostring(rpm), tostring(omegaX), tostring(omegaY), tostring(omegaZ)))

if g_currentMission.missionInfo.savegameIndex ~= nil then
end end

self.frame = self.frame +1


Loki Laufeyson (loki_79) 04.02.2022 19:58
You have two main options, you can just use a flag to open the file (and write the header) once within onUpdate():

if self.fileCreated == nil then
local myFile = getUserProfileAppPath() .. "data.txt"
local file =, "w")
self.fileCreated = true

but ideally you still need to close it somewhere outside of the loop.

Otherwise, you could separate out the file creation/opening/closing events into other functions, like onEnterVehicle() / onActivate() / onDeactivate() / etc, maybe with different unique file names for each vehicle. Then close the file(s) when you exit the vehicle, or when you exit the game, depending if you have one file for everything, or different filenames for each vehicle.

Of course, either way, you should write only the information you need (once per line) during onUpdate().

**EDIT: I should also say, to keep track of the file you will need to store it within your vehicle spec or your mod class instead of locally, so something like: self.file =, "w")
but it depends how you are using it in other functions, and if you made your mod into a vehicle specialisation.

Mario Tilocca (Mario_Tilocca) 07.02.2022 12:00
Thanks a lot! :))

I did it following the first method you suggested and it worked perfectly! turns out that by simply quitting the game the file is closed automatically.

What I wanted to do was just very simple, in case a vehicle is motorized I wanted to start saving data about the vehicle kinematics like position of the vehicle, linear and angular velocities etc. Basically every variable shown when you call "gsVehicleDebugPhysics"
I was looking for the source code in the documentation but I wasn't very successful.

Do you know where I can find the source code of "gsVehicleDebugPhysics" ?

or if that is not available just getting the vehicle's wheels rpms and steering angles would do. Do you know how I can get these two parameters ?

Thank you so so much again for your help!! :)

@ Squity (Squity) 08.02.2022 09:55
Are you sure that there is no way to save some data to files?
I know that some scripts save mod configuration to XML files, i suggest to try to search for info in such mods.

Mario Tilocca (Mario_Tilocca) 08.02.2022 10:00
Hi Squity!

It is indeed possible to export data. With the tips of Loki I managed to create a .txt file where several parameters when you drive a vehicle are written. Now I am just looking for how to get the wheels rpms and steering angles :)

Loki Laufeyson (loki_79) 08.02.2022 12:34
Most of the vechile control variables have not changed from FS19, so you can still use the documentation here:

e.g.: steering angle == vehicle.spec_drivable.axisSide

Mario Tilocca (Mario_Tilocca) 11.02.2022 08:55
Thank you so much again for your help guys!
As maybe it might be useful for someone and I didn't find a lot of examples about it, here is how you retrieve the wheels steering angles and angular velocities.

vehicle = g_currentMission.controlledVehicle
wheels = vehicle:getWheels()

-- steering angles (we need only the front wheels)

alphaFL = wheels[1].steeringAngle
alphaFR = wheels[2].steeringAngle

-- angular velocity of the wheels

omegaFL = wheels[1].netInfo.xDriveSpeed
omegaFR = wheels[2].netInfo.xDriveSpeed
omegaRL = wheels[3].netInfo.xDriveSpeed
omegaRR = wheels[4].netInfo.xDriveSpeed

Note: Log in to post. Create a new account here.