<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/wiki/Modules/FileSystem/file/readFloat?action=history&amp;feed=atom</id>
	<title>Modules/FileSystem/file/readFloat - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/wiki/Modules/FileSystem/file/readFloat?action=history&amp;feed=atom"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=Modules/FileSystem/file/readFloat&amp;action=history"/>
	<updated>2026-04-06T11:46:40Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=Modules/FileSystem/file/readFloat&amp;diff=73740&amp;oldid=prev</id>
		<title>Danilo at 03:03, 23 January 2022</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=Modules/FileSystem/file/readFloat&amp;diff=73740&amp;oldid=prev"/>
		<updated>2022-01-23T03:03:34Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 03:03, 23 January 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;pageclass class=&quot;#3cc882&quot; subcaption=&quot;File function&quot;&gt;&amp;lt;/pageclass&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;__NOTOC__&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;__NOTOC__&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This function attempts to read a float (native type) from a file and return it. The amount of bytes read should be four.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This function attempts to read a float (native type) from a file and return it. The amount of bytes read should be four.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wiki-wiki_dev_:diff::1.12:old-73656:rev-73740 --&gt;
&lt;/table&gt;</summary>
		<author><name>Danilo</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=Modules/FileSystem/file/readFloat&amp;diff=73656&amp;oldid=prev</id>
		<title>Danilo: Created page with &quot;__NOTOC__ This function attempts to read a float (native type) from a file and return it. The amount of bytes read should be four.  ==Syntax== &lt;syntaxhighlight lang=&quot;lua&quot;&gt; float file:readFloat () &lt;/syntaxhighlight&gt;  ==Returns== Returns a float if it was successfully read from the file, '''false''' otherwise.  ==Example== &lt;section name=&quot;Server&quot; class=&quot;server&quot; show=&quot;true&quot;&gt; This snippet demonstrates a binary vehicle handling format. This saves space in comparison to a .XML...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=Modules/FileSystem/file/readFloat&amp;diff=73656&amp;oldid=prev"/>
		<updated>2022-01-19T03:35:37Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;__NOTOC__ This function attempts to read a float (native type) from a file and return it. The amount of bytes read should be four.  ==Syntax== &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt; float file:readFloat () &amp;lt;/syntaxhighlight&amp;gt;  ==Returns== Returns a float if it was successfully read from the file, &amp;#039;&amp;#039;&amp;#039;false&amp;#039;&amp;#039;&amp;#039; otherwise.  ==Example== &amp;lt;section name=&amp;quot;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt; This snippet demonstrates a binary vehicle handling format. This saves space in comparison to a .XML...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__NOTOC__&lt;br /&gt;
This function attempts to read a float (native type) from a file and return it. The amount of bytes read should be four.&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
float file:readFloat ()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Returns==&lt;br /&gt;
Returns a float if it was successfully read from the file, '''false''' otherwise.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
&amp;lt;section name=&amp;quot;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
This snippet demonstrates a binary vehicle handling format. This saves space in comparison to a .XML based format.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local function writeFileString( theFile, string )&lt;br /&gt;
    theFile:writeShort( #string );&lt;br /&gt;
    theFile:write( string );&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function readFileString( theFile )&lt;br /&gt;
    local stringLen = theFile:readShort();&lt;br /&gt;
&lt;br /&gt;
    if not ( stringLen ) then&lt;br /&gt;
        return false;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    return theFile:read( stringLen );&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function saveVehicleHandling( theFile, handlingDict )&lt;br /&gt;
    -- Write down the details.&lt;br /&gt;
    theFile:writeDouble( handlingDict.mass );&lt;br /&gt;
    theFile:writeDouble( handlingDict.turnMass );&lt;br /&gt;
    theFile:writeFloat( handlingDict.dragCoeff );&lt;br /&gt;
&lt;br /&gt;
    theFile:writeFloat( handlingDict.centerOfMass[1] );&lt;br /&gt;
    theFile:writeFloat( handlingDict.centerOfMass[2] );&lt;br /&gt;
    theFile:writeFloat( handlingDict.centerOfMass[3] );&lt;br /&gt;
&lt;br /&gt;
    theFile:writeInt( handlingDict.percentSubmerged );&lt;br /&gt;
    theFile:writeDouble( handlingDict.tractionMultiplier );&lt;br /&gt;
    theFile:writeFloat( handlingDict.tractionLoss );&lt;br /&gt;
    theFile:writeFloat( handlingDict.tractionBias );&lt;br /&gt;
    theFile:writeShort( handlingDict.numberOfGears );&lt;br /&gt;
    theFile:writeDouble( handlingDict.maxVelocity );&lt;br /&gt;
    theFile:writeDouble( handlingDict.engineAcceleration );&lt;br /&gt;
    theFile:writeFloat( handlingDict.engineInertia );&lt;br /&gt;
    &lt;br /&gt;
    writeFileString( theFile, tostring( handlingDict.driveType ) );&lt;br /&gt;
    writeFileString( theFile, tostring( handlingDict.engineType ) );&lt;br /&gt;
&lt;br /&gt;
    theFile:writeDouble( handlingDict.brakeDeceleration );&lt;br /&gt;
    theFile:writeBoolean( handlingDict.ABS );&lt;br /&gt;
    theFile:writeFloat( handlingDict.steeringLock );&lt;br /&gt;
    theFile:writeFloat( handlingDict.suspensionForceLevel );&lt;br /&gt;
    theFile:writeFloat( handlingDict.suspensionDamping );&lt;br /&gt;
    theFile:writeFloat( handlingDict.suspensionHighSpeedDamping );&lt;br /&gt;
    theFile:writeFloat( handlingDict.suspensionUpperLimit );&lt;br /&gt;
    theFile:writeFloat( handlingDict.suspensionLowerLimit );&lt;br /&gt;
    theFile:writeFloat( handlingDict.suspensionFrontRearBias );&lt;br /&gt;
    theFile:writeFloat( handlingDict.suspensionAntiDiveMultiplier );&lt;br /&gt;
    theFile:writeFloat( handlingDict.seatOffsetDistance );&lt;br /&gt;
    theFile:writeFloat( handlingDict.collisionDamageMultiplier );&lt;br /&gt;
    theFile:writeInt( handlingDict.monetary );&lt;br /&gt;
    theFile:writeInt( handlingDict.modelFlags );&lt;br /&gt;
    theFile:writeInt( handlingDict.handlingFlags );&lt;br /&gt;
    &lt;br /&gt;
    writeFileString( theFile, handlingDict.headLight );&lt;br /&gt;
    writeFileString( theFile, handlingDict.tailLight );&lt;br /&gt;
    &lt;br /&gt;
    theFile:writeShort( handlingDict.animGroup );&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function attemptFileRead( theFile, theOperation, defaultOut )&lt;br /&gt;
    local output = theOperation( theFile );&lt;br /&gt;
&lt;br /&gt;
    if not ( output ) then&lt;br /&gt;
        return defaultOut;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    return output;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function loadVehicleHandling( theFile )&lt;br /&gt;
    local handlingEntry = {&lt;br /&gt;
        mass = attemptFileRead( theFile, theFile.readDouble, 1000 ),&lt;br /&gt;
        turnMass = attemptFileRead( theFile, theFile.readDouble, 1000 ),&lt;br /&gt;
        dragCoeff = attemptFileRead( theFile, theFile.readFloat, 0 ),&lt;br /&gt;
&lt;br /&gt;
        {&lt;br /&gt;
            [1] = attemptFileRead( theFile, theFile.readFloat, 0 ),&lt;br /&gt;
            [2] = attemptFileRead( theFile, theFile.readFloat, 0 ),&lt;br /&gt;
            [3] = attemptFileRead( theFile, theFile.readFloat, 0 )&lt;br /&gt;
        },&lt;br /&gt;
&lt;br /&gt;
        percentSubmerged = attemptFileRead( theFile, theFile.readInt, 100 ),&lt;br /&gt;
        tractionMultiplier = attemptFileRead( theFile, theFile.readDouble, 1.0 ),&lt;br /&gt;
        tractionLoss = attemptFileRead( theFile, theFile.readFloat, 1.0 ),&lt;br /&gt;
        tractionBias = attemptFileRead( theFile, theFile.readFloat, 1.0 ),&lt;br /&gt;
        numberOfGears = attemptFileRead( theFile, theFile.readShort, 4 ),&lt;br /&gt;
        maxVelocity = attemptFileRead( theFile, theFile.readDouble, 240 ),&lt;br /&gt;
        engineAcceleration = attemptFileRead( theFile, theFile.readDouble, 9 ),&lt;br /&gt;
        engineInertia = attemptFileRead( theFile, theFile.readFloat, 3 ),&lt;br /&gt;
        &lt;br /&gt;
        driveType = attemptFileRead( theFile, function(theFile) return readFileString( theFile ) end, &amp;quot;fwd&amp;quot; ),&lt;br /&gt;
        engineType = attemptFileRead( theFile, function(theFile) return readFileString( theFile ) end, &amp;quot;diesel&amp;quot; ),&lt;br /&gt;
&lt;br /&gt;
        brakeDeceleration = attemptFileRead( theFile, theFile.readDouble, 5 ),&lt;br /&gt;
        brakeBias = attemptFileRead( theFile, theFile.readFloat, 1.0 ),&lt;br /&gt;
        ABS = attemptFileRead( theFile, theFile.readBoolean, false ),&lt;br /&gt;
        steeringLock = attemptFileRead( theFile, theFile.readFloat, 180 ),&lt;br /&gt;
        suspensionForceLevel = attemptFileRead( theFile, theFile.readFloat, 10 ),&lt;br /&gt;
        suspensionDamping = attemptFileRead( theFile, theFile.readFloat, 10 ),&lt;br /&gt;
        suspensionHighSpeedDamping = attemptFileRead( theFile, theFile.readFloat, 50 ),&lt;br /&gt;
        suspensionUpperLimit = attemptFileRead( theFile, theFile.readFloat, 0 ),&lt;br /&gt;
        suspensionLowerLimit = attemptFileRead( theFile, theFile.readFloat, 0 ),&lt;br /&gt;
        suspensionFrontRearBias = attemptFileRead( theFile, theFile.readFloat, 0.4 ),&lt;br /&gt;
        suspensionAntiDiveMultiplier = attemptFileRead( theFile, theFile.readFloat, 10 ),&lt;br /&gt;
        seatOffsetDistance = attemptFileRead( theFile, theFile.readFloat, 4 ),&lt;br /&gt;
        collisionDamageMultiplier = attemptFileRead( theFile, theFile.readFloat, 0.5 ),&lt;br /&gt;
        monetary = attemptFileRead( theFile, theFile.readInt, 10000 ),&lt;br /&gt;
        modelFlags = attemptFileRead( theFile, theFile.readInt, 0 ),&lt;br /&gt;
        handlingFlags = attemptFileRead( theFile, theFile.readInt, 0 ),&lt;br /&gt;
        &lt;br /&gt;
        headLight = attemptFileRead( theFile, function(theFile) return readFileString( theFile ) end, &amp;quot;big&amp;quot; ),&lt;br /&gt;
        tailLight = attemptFileRead( theFile, function(theFile) return readFileString( theFile ) end, &amp;quot;big&amp;quot; ),&lt;br /&gt;
&lt;br /&gt;
        animGroup = attemptFileRead( theFile, theFile.readShort, 1 )&lt;br /&gt;
    };&lt;br /&gt;
&lt;br /&gt;
    return handlingEntry;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Save the handling of your vehicle, so you can reuse it later.&lt;br /&gt;
addCommandHandler( &amp;quot;savehandling&amp;quot;,&lt;br /&gt;
    function(player)&lt;br /&gt;
        local myVehicle = getPedOccupiedVehicle( player );&lt;br /&gt;
&lt;br /&gt;
        if ( myVehicle ) then&lt;br /&gt;
            local handling = getVehicleHandling( myVehicle );&lt;br /&gt;
&lt;br /&gt;
            local handlingFile = fileCreate( getPlayerName( player ) .. &amp;quot;_saved_handling.dat&amp;quot; );&lt;br /&gt;
&lt;br /&gt;
            if ( handlingFile ) then&lt;br /&gt;
                saveVehicleHandling( handlingFile, handling );&lt;br /&gt;
&lt;br /&gt;
                handlingFile:destroy();&lt;br /&gt;
&lt;br /&gt;
                outputChatBox( &amp;quot;successfully saved handling&amp;quot; );&lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
-- Load the handling of the vehicle for reusage.&lt;br /&gt;
addCommandHandler( &amp;quot;loadhandling&amp;quot;,&lt;br /&gt;
    function(player)&lt;br /&gt;
        local handlingName = getPlayerName( player ) .. &amp;quot;_saved_handling.dat&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        if ( fileExists( handlingName ) ) then&lt;br /&gt;
            local myVehicle = getPedOccupiedVehicle( player );&lt;br /&gt;
&lt;br /&gt;
            if ( myVehicle ) then&lt;br /&gt;
                local handlingFile = fileOpen( handlingName );&lt;br /&gt;
&lt;br /&gt;
                if ( handlingFile ) then&lt;br /&gt;
                    local handling = loadVehicleHandling( handlingFile );&lt;br /&gt;
&lt;br /&gt;
                    handlingFile:destroy();&lt;br /&gt;
&lt;br /&gt;
                    -- Apply the saved handling.&lt;br /&gt;
                    for m,n in pairs( handling ) do&lt;br /&gt;
                        setVehicleHandling( myVehicle, m, n );&lt;br /&gt;
                    end&lt;br /&gt;
&lt;br /&gt;
                    outputChatBox( &amp;quot;successfully restored handling&amp;quot; );&lt;br /&gt;
                end&lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
{{:Modules/FileSystem/file/functions}}&lt;/div&gt;</summary>
		<author><name>Danilo</name></author>
	</entry>
</feed>