SetVehicleHandling: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(25 intermediate revisions by 13 users not shown)
Line 1: Line 1:
{{Server function}}  
{{Server client function}}
__NOTOC__  
__NOTOC__  
This function is used to change the handling data of a vehicle.
This function is used to change the handling data of a vehicle.
{{New feature/item|3.0156|1.5.5|12009|Implemented also for client-sided vehicles.}}


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool setVehicleHandling ( element theVehicle, string property, var value )  
bool setVehicleHandling(element theVehicle, string property, var value)  
</syntaxhighlight>  
</syntaxhighlight>
 
Syntaxes for reset configurations:
<syntaxhighlight lang="lua">
bool setVehicleHandling(element theVehicle, string property, nil, false)  -- Reset one property to model handling value
bool setVehicleHandling(element theVehicle, string property, nil, true)  -- Reset one property to GTA default value
bool setVehicleHandling(element theVehicle, false)                        -- Reset all properties to model handling value
bool setVehicleHandling(element theVehicle, true)                        -- Reset all properties to GTA default value
</syntaxhighlight>


===Required Arguments===  
===Required Arguments===  
*'''theVehicle:''' The vehicle you wish to set the handling of.
*'''theVehicle:''' The vehicle you wish to set the handling of.
*'''property:''' The property you wish to set the handling of the vehicle to.
*'''property:''' The property you wish to set the handling of the vehicle to.
{{Note|For functionality reasons, suspension modification is disabled on monster trucks, trains, boats and trailers.
Additionally, helicopters are not affected by custom handling. The vehicle-on-wheels handling does not affect planes when they are on the ground either. For more information on this, see [https://github.com/multitheftauto/mtasa-blue/issues/2426 issue 2426]}}
{{Warning|To change handling values of aircraft like ''maxVelocity'', you must first set [[SetAircraftMaxVelocity|setAircraftMaxVelocity]].}}
{{Handling Properties}}
{{Handling Properties}}
*'''value:''' The value of the property you wish to set the handling of the vehicle to.
*'''value:''' The value of the property you wish to set the handling of the vehicle to.


===Returns===
===Returns===
Returns ''true'' if the handling was set successfully, ''false'' otherwise. See below a list of valid propertys and their required values:
Returns ''true'' if the handling was set successfully, ''false'' otherwise. See below a list of valid properties and their required values:
 
==Example==
This example will make Infernus handling very fast and also make it damage proof from collision (handling by Mr.unpredictable).
this example will help you in creating your own vehicle handling.
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
function vhandling ( theVehicle )
    if getElementModel(theVehicle) == 411 then -------------- vehicle Id
        setVehicleHandling(theVehicle, "mass", 300.0)
        setVehicleHandling(theVehicle, "turnMass", 200)
        setVehicleHandling(theVehicle, "dragCoeff", 4.0 )
        setVehicleHandling(theVehicle, "centerOfMass", { 0.0,0.08,-0.09 } )
        setVehicleHandling(theVehicle, "percentSubmerged", 103)
        setVehicleHandling(theVehicle, "tractionMultiplier", 1.8)
        setVehicleHandling(theVehicle, "tractionLoss", 1.0)
        setVehicleHandling(theVehicle, "tractionBias", 0.48)
        setVehicleHandling(theVehicle, "numberOfGears", 5)
        setVehicleHandling(theVehicle, "maxVelocity", 300.0)
        setVehicleHandling(theVehicle, "engineAcceleration", 90.0 )
        setVehicleHandling(theVehicle, "engineInertia", 5.0)
        setVehicleHandling(theVehicle, "driveType", "rwd")
        setVehicleHandling(theVehicle, "engineType", "petrol")
        setVehicleHandling(theVehicle, "brakeDeceleration", 20.0)
        setVehicleHandling(theVehicle, "brakeBias", 0.60)
        -----abs----
        setVehicleHandling(theVehicle, "steeringLock",  35.0 )
        setVehicleHandling(theVehicle, "suspensionForceLevel", 0.85)
        setVehicleHandling(theVehicle, "suspensionDamping", 0.15 )
        setVehicleHandling(theVehicle, "suspensionHighSpeedDamping", 0.0)
        setVehicleHandling(theVehicle, "suspensionUpperLimit", 0.15 )
        setVehicleHandling(theVehicle, "suspensionLowerLimit", -0.16)
        setVehicleHandling(theVehicle, "suspensionFrontRearBias", 0.5 )
        setVehicleHandling(theVehicle, "suspensionAntiDiveMultiplier", 0.0)
        setVehicleHandling(theVehicle, "seatOffsetDistance", 0.0)
        setVehicleHandling(theVehicle, "collisionDamageMultiplier", 0.00)
        --setVehicleHandling(theVehicle, "monetary",  10000) This one is disabled for now
        setVehicleHandling(theVehicle, "modelFlags", 1002000)
        setVehicleHandling(theVehicle, "handlingFlags", 1000002)
        --setVehicleHandling(theVehicle, "headLight", 3) This one is disabled for now
        --setVehicleHandling(theVehicle, "tailLight", 2) This one is disabled for now
        --setVehicleHandling(theVehicle, "animGroup", 4) This one is disabled for now
    end
end
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), vhandling )
</syntaxhighlight></section>


==Notes==
This example will add a command for players with which they can change the mass of the vehicle.
for functionality reasons suspension modification is disabled on monster trucks, trains and boats.
<section name="Server" class="server" show="true">
==Example==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function massChange ( me, command, mass )
function massChange ( me, command, mass )
     mass = tonumber ( mass ) -- Convert mass to a number
     local mass = tonumber ( mass ) -- Convert mass to a number
     local veh = getPedOccupiedVehicle ( me ) -- Get the player's vehicle
     local veh = getPedOccupiedVehicle ( me ) -- Get the player's vehicle
      
      
     if mass and veh then  -- If valid mass and in a vehicle
     if mass and veh then  -- If valid mass and in a vehicle
         local success = setVehicleHandling ( veh, "mass", mass ) -- Set the vehicle's mass, and check if successful
         local success = setVehicleHandling ( veh, "mass", mass) -- Set the vehicle's mass, and check if successful
          
          
         if success then -- If successful
         if success then -- If successful
Line 40: Line 99:
end
end
addCommandHandler ( "changemass", massChange )
addCommandHandler ( "changemass", massChange )
</syntaxhighlight>
</syntaxhighlight></section>


<section name="Server" class="server" show="true">
This example will apply custom handling as defined for each specific vehicle (ID) in below table
This example script changes the handling of all Bullet.
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function handlingChange ()
local predefinedHandling = {
for i,v in ipairs(getElementsByType("vehicle")) do
[411] = {
    if getElementModel(v) == 541 then
["engineAcceleration"] = 14,
          setVehicleHandling(v, "mass", 1890)
["dragCoeff"] = 0,
  setVehicleHandling(v, "turnMass", 3780)
["maxVelocity"] = 100000,
  setVehicleHandling(v, "dragCoeff", 0.7)
["tractionMultiplier"] = 0.9,
  setVehicleHandling(v, "centerOfMass", {0.0, 0.1, -0.2} )
["tractionLoss"] = 1.1,
  setVehicleHandling(v, "percentSubmerged", 75)
},
  setVehicleHandling(v, "tractionMultiplier", 0.70)
[415] = {
  setVehicleHandling(v, "tractionLoss", 0.90)
["engineAcceleration"] = 14,
  setVehicleHandling(v, "tractionBias", 0.50)
["dragCoeff"] = 0,
  setVehicleHandling(v, "numberOfGears", 5)
["maxVelocity"] = 100000,
  setVehicleHandling(v, "maxVelocity", 407)
["tractionMultiplier"] = 0.9,
  setVehicleHandling(v, "engineAcceleration", 50)
["tractionLoss"] = 1.1,
  setVehicleHandling(v, "engineInertia", 10)
},
  setVehicleHandling(v, "driveType", "awd")
[562] = { -- Universal drift handling
  setVehicleHandling(v, "engineType", "petrol")
["driveType"] = "rwd",
  setVehicleHandling(v, "brakeDeceleration", 11)
["engineAcceleration"] = 200,
  setVehicleHandling(v, "brakeBias", 0.45)
["dragCoeff"] = 1.5,
  setVehicleHandling(v, "ABS", false)
["maxVelocity"] = 300,
  setVehicleHandling(v, "steeringLock", 30)
["tractionMultiplier"] = 0.7,
  setVehicleHandling(v, "suspensionForceLevel", 0.80)
["tractionLoss"] = 0.8,
  setVehicleHandling(v, "suspensionDamping", 0.20)
["collisionDamageMultiplier"] = 0.4,
  setVehicleHandling(v, "suspensionHighSpeedDamping", 0.0)
["engineInertia"] = -175,
  setVehicleHandling(v, "suspensionUpperLimit", 0.10)
["steeringLock"] = 75,
  setVehicleHandling(v, "suspensionLowerLimit", -0.09)
["numberOfGears"] = 4,
  setVehicleHandling(v, "suspensionFrontRearBias", 0.5)
["suspensionForceLevel"] = 0.8,
  setVehicleHandling(v, "suspensionAntiDiveMultiplier", 0.6)
["suspensionDamping"] = 0.8,
  setVehicleHandling(v, "seatOffsetDistance", 0.3)
["suspensionUpperLimit"] = 0.33,
  setVehicleHandling(v, "collisionDamageMultiplier", 0.50)
["suspensionFrontRearBias"] = 0.3,
  setVehicleHandling(v, "monetary", 1460000)
["mass"] = 1800,
  setVehicleHandling(v, "modelFlags", 0xC0222004)
["turnMass"] = 3000,
  setVehicleHandling(v, "handlingFlags", 0x1400000)
["centerOfMass"] = { [1]=0, [2]=-0.2, [3]=-0.5 }, -- Good example to understand centerOfMass parameter usage
  setVehicleHandling(v, "headLight", 1)
},
  setVehicleHandling(v, "tailLight", 1)
 
  setVehicleHandling(v, "animGroup", 0)
--next model below etc (copy rows)
      end
}
      end
 
for i,v in pairs (predefinedHandling) do
if i then
for handling, value in pairs (v) do
if not setModelHandling (i, handling, value) then
outputDebugString ("* Predefined handling '"..tostring(handling).."' for vehicle model '"..tostring(i).."' could not be set to '"..tostring(value).."'")
end
end
end
end
end
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), handlingChange )
 
</syntaxhighlight>
for _,v in ipairs (getElementsByType("vehicle")) do
</section>
if v and predefinedHandling[getElementModel(v)] then
for k,vl in pairs (predefinedHandling[getElementModel(v)]) do
setVehicleHandling (v, k, vl)
end
end
end
 
function resetHandling()
for model in pairs (predefinedHandling) do
if model then
for k in pairs(getOriginalHandling(model)) do
setModelHandling(model, k, nil)
end
end
end
 
for _,v in ipairs (getElementsByType("vehicle")) do
if v then
local model = getElementModel(v)
if predefinedHandling[model] then
for k,h in pairs(getOriginalHandling(model)) do
setVehicleHandling(v, k, h)
end
end
end
end
end
addEventHandler("onResourceStop", resourceRoot, resetHandling)
</syntaxhighlight></section>
 
==Changelog==
{{ChangelogHeader}}
{{ChangelogItem|1.5.5-3.12009|Added for vehicles created on client-side.}}


==See other vehicle functions==
==See other vehicle functions==
{{Vehicle functions}}
{{Vehicle functions}}

Latest revision as of 19:55, 5 January 2022

This function is used to change the handling data of a vehicle.

Implemented also for client-sided vehicles.

Syntax

bool setVehicleHandling(element theVehicle, string property, var value) 

Syntaxes for reset configurations:

bool setVehicleHandling(element theVehicle, string property, nil, false)  -- Reset one property to model handling value
bool setVehicleHandling(element theVehicle, string property, nil, true)   -- Reset one property to GTA default value
bool setVehicleHandling(element theVehicle, false)                        -- Reset all properties to model handling value
bool setVehicleHandling(element theVehicle, true)                         -- Reset all properties to GTA default value

Required Arguments

  • theVehicle: The vehicle you wish to set the handling of.
  • property: The property you wish to set the handling of the vehicle to.
[[{{{image}}}|link=|]] Note: For functionality reasons, suspension modification is disabled on monster trucks, trains, boats and trailers.

Additionally, helicopters are not affected by custom handling. The vehicle-on-wheels handling does not affect planes when they are on the ground either. For more information on this, see issue 2426

[[|link=|]] Warning: To change handling values of aircraft like maxVelocity, you must first set setAircraftMaxVelocity.


http://web.archive.org/web/20140223160252/http://projectcerbera.com/gta/sa/tutorials/handling

Property Value Minimum value Maximum value Notes
mass Float 1.0 100000.0
turnMass Float 0.0 1000000.0
dragCoeff Float -200.0 200.0
centerOfMass Table = { [1]=posX, [2]=posY, [3]=posZ } (floats) -10.0 10.0 Get returns a table, set needs a table.
percentSubmerged Integer 1 99999
tractionMultiplier Float -100000.0 100000.0
tractionLoss Float 0.0 100.0
tractionBias Float 0.0 1.0
numberOfGears Integer 1 5
maxVelocity Float 0.1 200000.0
engineAcceleration Float 0.0 100000.0
engineInertia Float -1000.0 1000.0 Inertia of 0 can cause a LSOD. (Unable to divide by zero)
driveType String N/A N/A Use 'rwd', 'fwd' or 'awd'.
engineType String N/A N/A Use 'petrol', 'diesel' or 'electric'.
brakeDeceleration Float 0.1 100000.0
brakeBias Float 0.0 1.0
ABS Boolean true false Has no effect.
steeringLock Float 0.0 360.0
suspensionForceLevel Float 0.0 100.0
suspensionDamping Float 0.0 100.0
suspensionHighSpeedDamping Float 0.0 600.0
suspensionUpperLimit Float -50.0 50.0 Can't be equal to suspensionLowerLimit.
suspensionLowerLimit Float -50.0 50.0 Can't be equal to suspensionUpperLimit.
suspensionFrontRearBias Float 0.0 1.0 Hardcoded maximum is 3.0, but values above 1.0 have no effect.
suspensionAntiDiveMultiplier Float 0.0 30.0
seatOffsetDistance Float -20.0 20.0
collisionDamageMultiplier Float 0.0 10.0
monetary Integer 0 230195200 Get works, set is disabled.
modelFlags Hexadecimal/Decimal N/A N/A Property uses a decimal value, generated by a hexadecimal value. Either use 0x12345678 or tonumber ( "0x12345678" ). See projectcerbera for possible values.
handlingFlags Hexadecimal/Decimal N/A N/A Property uses a decimal value, generated by a hexadecimal value. Either use 0x12345678 or tonumber ( "0x12345678" ). See projectcerbera for possible values.
headLight String N/A N/A Get works, set is disabled. Available values: 'long', 'small', 'big', 'tall'.
tailLight String N/A N/A Get works, set is disabled. Available values: 'long', 'small', 'big', 'tall'.
animGroup Integer ?? ?? Get works, set is disabled due to people not knowing this property was vehicle-based and caused crashes.
  • value: The value of the property you wish to set the handling of the vehicle to.

Returns

Returns true if the handling was set successfully, false otherwise. See below a list of valid properties and their required values:

Example

This example will make Infernus handling very fast and also make it damage proof from collision (handling by Mr.unpredictable). this example will help you in creating your own vehicle handling.

Click to collapse [-]
Server
function vhandling ( theVehicle )
    if getElementModel(theVehicle) == 411 then -------------- vehicle Id
        setVehicleHandling(theVehicle, "mass", 300.0)
        setVehicleHandling(theVehicle, "turnMass", 200)
        setVehicleHandling(theVehicle, "dragCoeff", 4.0 )
        setVehicleHandling(theVehicle, "centerOfMass", { 0.0,0.08,-0.09 } )
        setVehicleHandling(theVehicle, "percentSubmerged", 103)
        setVehicleHandling(theVehicle, "tractionMultiplier", 1.8)
        setVehicleHandling(theVehicle, "tractionLoss", 1.0)
        setVehicleHandling(theVehicle, "tractionBias", 0.48)
        setVehicleHandling(theVehicle, "numberOfGears", 5)
        setVehicleHandling(theVehicle, "maxVelocity", 300.0)
        setVehicleHandling(theVehicle, "engineAcceleration", 90.0 )
        setVehicleHandling(theVehicle, "engineInertia", 5.0)
        setVehicleHandling(theVehicle, "driveType", "rwd")
        setVehicleHandling(theVehicle, "engineType", "petrol")
        setVehicleHandling(theVehicle, "brakeDeceleration", 20.0)
        setVehicleHandling(theVehicle, "brakeBias", 0.60)
        -----abs----
        setVehicleHandling(theVehicle, "steeringLock",  35.0 )
        setVehicleHandling(theVehicle, "suspensionForceLevel", 0.85)
        setVehicleHandling(theVehicle, "suspensionDamping", 0.15 )
        setVehicleHandling(theVehicle, "suspensionHighSpeedDamping", 0.0)
        setVehicleHandling(theVehicle, "suspensionUpperLimit", 0.15 )
        setVehicleHandling(theVehicle, "suspensionLowerLimit", -0.16)
        setVehicleHandling(theVehicle, "suspensionFrontRearBias", 0.5 )
        setVehicleHandling(theVehicle, "suspensionAntiDiveMultiplier", 0.0)
        setVehicleHandling(theVehicle, "seatOffsetDistance", 0.0)
        setVehicleHandling(theVehicle, "collisionDamageMultiplier", 0.00)
        --setVehicleHandling(theVehicle, "monetary",  10000) This one is disabled for now
        setVehicleHandling(theVehicle, "modelFlags", 1002000)
        setVehicleHandling(theVehicle, "handlingFlags", 1000002)
        --setVehicleHandling(theVehicle, "headLight", 3) This one is disabled for now
        --setVehicleHandling(theVehicle, "tailLight", 2) This one is disabled for now
        --setVehicleHandling(theVehicle, "animGroup", 4) This one is disabled for now
    end
end
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), vhandling )

This example will add a command for players with which they can change the mass of the vehicle.

Click to collapse [-]
Server
function massChange ( me, command, mass )
    local mass = tonumber ( mass ) -- Convert mass to a number
    local veh = getPedOccupiedVehicle ( me ) -- Get the player's vehicle
    
    if mass and veh then  -- If valid mass and in a vehicle
        local success = setVehicleHandling ( veh, "mass", mass) -- Set the vehicle's mass, and check if successful
        
        if success then -- If successful
            outputChatBox ( "Your vehicle's mass has been changed to: "..mass.." kg", me, 0, 255, 0 ) -- Notify the player of success
        else -- Too bad failure is still an option
            outputChatBox ( "Setting mass failed. It's probably above or below allowed limits", me, 255, 0, 0 ) -- Notify the player of failure, and give a possible reason
        end
    elseif not veh then -- If not in a vehicle
        outputChatBox ( "You're not in a vehicle", me, 255, 0, 0 ) -- Tell the player; He / she obviously doesn't know
    elseif not mass then -- If not a valid mass
        outputChatBox ( "Syntax: /changemass [mass]", me, 255, 0, 0 ) -- Tell the player the proper syntax
    end
end
addCommandHandler ( "changemass", massChange )

This example will apply custom handling as defined for each specific vehicle (ID) in below table

Click to collapse [-]
Server
local predefinedHandling = {
	[411] = {
		["engineAcceleration"] = 14,
		["dragCoeff"] = 0,
		["maxVelocity"] = 100000,
		["tractionMultiplier"] = 0.9,
		["tractionLoss"] = 1.1,
	},
	[415] = {
		["engineAcceleration"] = 14,
		["dragCoeff"] = 0,
		["maxVelocity"] = 100000,
		["tractionMultiplier"] = 0.9,
		["tractionLoss"] = 1.1,
	},
		[562] = { -- Universal drift handling
		["driveType"] = "rwd",
		["engineAcceleration"] = 200,
		["dragCoeff"] = 1.5,
		["maxVelocity"] = 300,
		["tractionMultiplier"] = 0.7,
		["tractionLoss"] = 0.8,
		["collisionDamageMultiplier"] = 0.4,
		["engineInertia"] = -175,
		["steeringLock"] = 75,
		["numberOfGears"] = 4,
		["suspensionForceLevel"] = 0.8,
		["suspensionDamping"] = 0.8,
		["suspensionUpperLimit"] = 0.33,
		["suspensionFrontRearBias"] = 0.3,
		["mass"] = 1800,
		["turnMass"] = 3000,
		["centerOfMass"] = { [1]=0, [2]=-0.2, [3]=-0.5 }, -- Good example to understand centerOfMass parameter usage
	},

	--next model below etc (copy rows)
}

for i,v in pairs (predefinedHandling) do
	if i then
		for handling, value in pairs (v) do
			if not setModelHandling (i, handling, value) then
				outputDebugString ("* Predefined handling '"..tostring(handling).."' for vehicle model '"..tostring(i).."' could not be set to '"..tostring(value).."'")
			end
		end
	end
end

for _,v in ipairs (getElementsByType("vehicle")) do
	if v and predefinedHandling[getElementModel(v)] then
		for k,vl in pairs (predefinedHandling[getElementModel(v)]) do
			setVehicleHandling (v, k, vl)
		end
	end
end

function resetHandling()
	for model in pairs (predefinedHandling) do
		if model then
			for k in pairs(getOriginalHandling(model)) do
				setModelHandling(model, k, nil)
			end
		end
	end

	for _,v in ipairs (getElementsByType("vehicle")) do
		if v then
			local model = getElementModel(v)
			if predefinedHandling[model] then
				for k,h in pairs(getOriginalHandling(model)) do
					setVehicleHandling(v, k, h)
				end
			end
		end
	end
end
addEventHandler("onResourceStop", resourceRoot, resetHandling)

Changelog

Version Description
1.5.5-3.12009 Added for vehicles created on client-side.

See other vehicle functions