SetModelHandling: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(8 intermediate revisions by 6 users not shown)
Line 5: Line 5:
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool setModelHandling ( int modelId, [ string property, var value ] )  
bool setModelHandling ( int modelId, string property, var value )  
</syntaxhighlight>  
</syntaxhighlight>  


Line 27: Line 27:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function handlingChange()
function handlingChange()
setModelHandling(541, "mass", 1890)
local modelId = 541
setModelHandling(541, "turnMass", 3780)
setModelHandling(modelId, "mass", 1890)
setModelHandling(541, "dragCoeff", 0.7)
setModelHandling(modelId, "turnMass", 3780)
setModelHandling(541, "centerOfMass", {0.0, 0.1, -0.2} )
setModelHandling(modelId, "dragCoeff", 0.7)
setModelHandling(541, "percentSubmerged", 75)
setModelHandling(modelId, "centerOfMass", {0.0, 0.1, -0.2} )
setModelHandling(541, "tractionMultiplier", 0.70)
setModelHandling(modelId, "percentSubmerged", 75)
setModelHandling(541, "tractionLoss", 0.90)
setModelHandling(modelId, "tractionMultiplier", 0.70)
setModelHandling(541, "tractionBias", 0.50)
setModelHandling(modelId, "tractionLoss", 0.90)
setModelHandling(541, "numberOfGears", 5)
setModelHandling(modelId, "tractionBias", 0.50)
setModelHandling(541, "maxVelocity", 407)
setModelHandling(modelId, "numberOfGears", 5)
setModelHandling(541, "engineAcceleration", 50)
setModelHandling(modelId, "maxVelocity", 407)
setModelHandling(541, "engineInertia", 10)
setModelHandling(modelId, "engineAcceleration", 50)
setModelHandling(541, "driveType", "awd")
setModelHandling(modelId, "engineInertia", 10)
setModelHandling(541, "engineType", "petrol")
setModelHandling(modelId, "driveType", "awd")
setModelHandling(541, "brakeDeceleration", 11)
setModelHandling(modelId, "engineType", "petrol")
setModelHandling(541, "brakeBias", 0.45)
setModelHandling(modelId, "brakeDeceleration", 11)
setModelHandling(541, "ABS", false)
setModelHandling(modelId, "brakeBias", 0.45)
setModelHandling(541, "steeringLock", 30)
setModelHandling(modelId, "ABS", false)
setModelHandling(541, "suspensionForceLevel", 0.80)
setModelHandling(modelId, "steeringLock", 30)
setModelHandling(541, "suspensionDamping", 0.20)
setModelHandling(modelId, "suspensionForceLevel", 0.80)
setModelHandling(541, "suspensionHighSpeedDamping", 0.0)
setModelHandling(modelId, "suspensionDamping", 0.20)
setModelHandling(541, "suspensionUpperLimit", 0.10)
setModelHandling(modelId, "suspensionHighSpeedDamping", 0.0)
setModelHandling(541, "suspensionLowerLimit", -0.09)
setModelHandling(modelId, "suspensionUpperLimit", 0.10)
setModelHandling(541, "suspensionFrontRearBias", 0.5)
setModelHandling(modelId, "suspensionLowerLimit", -0.09)
setModelHandling(541, "suspensionAntiDiveMultiplier", 0.6)
setModelHandling(modelId, "suspensionFrontRearBias", 0.5)
setModelHandling(541, "seatOffsetDistance", 0.3)
setModelHandling(modelId, "suspensionAntiDiveMultiplier", 0.6)
setModelHandling(541, "collisionDamageMultiplier", 0.50)
setModelHandling(modelId, "seatOffsetDistance", 0.3)
setModelHandling(541, "monetary", 1460000)
setModelHandling(modelId, "collisionDamageMultiplier", 0.50)
setModelHandling(541, "modelFlags", 0xC0222004)
setModelHandling(modelId, "monetary", 1460000)
setModelHandling(541, "handlingFlags", 0x1400000)
setModelHandling(modelId, "modelFlags", 0xC0222004)
setModelHandling(541, "headLight", 1)
setModelHandling(modelId, "handlingFlags", 0x1400000)
setModelHandling(541, "tailLight", 1)
setModelHandling(modelId, "headLight", 1)
setModelHandling(541, "animGroup", 0)
setModelHandling(modelId, "tailLight", 1)
setModelHandling(modelId, "animGroup", 0)
end
end
addEventHandler("onResourceStart", resourceRoot, handlingChange)
addEventHandler("onResourceStart", resourceRoot, handlingChange)
Line 68: Line 69:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function resetHandling()
function resetHandling()
for k,_ in pairs(getModelHandling(541)) do
local modelId = 541
setModelHandling(541, k, nil)
for k,_ in pairs(getModelHandling(modelId)) do
setModelHandling(modelId, k, nil)
end
end
end
end
Line 76: Line 78:
</section>
</section>


== Issues ==
{{Issues|
{{Issue|553|setModelHandling doesn't work with already created vehicles}}
{{Issue|1198|"setModelHandling" function doesn't affect vehicles that have been changed using "setElementModel"}}
}}


==See other vehicle functions==
==See other vehicle functions==
{{Vehicle functions}}
{{Vehicle_functions|server}}

Latest revision as of 23:04, 6 September 2024

This function is used to change the handling data of all vehicles of a specified model.

Syntax

bool setModelHandling ( int modelId, string property, var value ) 

Required Arguments

  • modelId: The vehicle model you wish to set the handling of.
  • property: The property you wish to set the handling of the vehicle to, or nil if you want to reset the all the handling properties.
  • value: The value of the models's handling property you wish to set, or nil if you want to reset the handling property to its default value.

Returns

Returns true if the handling was set successfully, false otherwise.


Handling Properties

See below a list of valid properties and their required values:

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.


Example

Click to collapse [-]
Server

This example script changes the handling of all Bullet.

function handlingChange()
	local modelId = 541
	setModelHandling(modelId, "mass", 1890)
	setModelHandling(modelId, "turnMass", 3780)
	setModelHandling(modelId, "dragCoeff", 0.7)
	setModelHandling(modelId, "centerOfMass", {0.0, 0.1, -0.2} )
	setModelHandling(modelId, "percentSubmerged", 75)
	setModelHandling(modelId, "tractionMultiplier", 0.70)
	setModelHandling(modelId, "tractionLoss", 0.90)
	setModelHandling(modelId, "tractionBias", 0.50)
	setModelHandling(modelId, "numberOfGears", 5)
	setModelHandling(modelId, "maxVelocity", 407)
	setModelHandling(modelId, "engineAcceleration", 50)
	setModelHandling(modelId, "engineInertia", 10)
	setModelHandling(modelId, "driveType", "awd")
	setModelHandling(modelId, "engineType", "petrol")
	setModelHandling(modelId, "brakeDeceleration", 11)
	setModelHandling(modelId, "brakeBias", 0.45)
	setModelHandling(modelId, "ABS", false)
	setModelHandling(modelId, "steeringLock", 30)
	setModelHandling(modelId, "suspensionForceLevel", 0.80)
	setModelHandling(modelId, "suspensionDamping", 0.20)
	setModelHandling(modelId, "suspensionHighSpeedDamping", 0.0)
	setModelHandling(modelId, "suspensionUpperLimit", 0.10)
	setModelHandling(modelId, "suspensionLowerLimit", -0.09)
	setModelHandling(modelId, "suspensionFrontRearBias", 0.5)
	setModelHandling(modelId, "suspensionAntiDiveMultiplier", 0.6)
	setModelHandling(modelId, "seatOffsetDistance", 0.3)
	setModelHandling(modelId, "collisionDamageMultiplier", 0.50)
	setModelHandling(modelId, "monetary", 1460000)
	setModelHandling(modelId, "modelFlags", 0xC0222004)
	setModelHandling(modelId, "handlingFlags", 0x1400000)
	setModelHandling(modelId, "headLight", 1)
	setModelHandling(modelId, "tailLight", 1)
	setModelHandling(modelId, "animGroup", 0)
end
addEventHandler("onResourceStart", resourceRoot, handlingChange)


This function will reset the handling of Bullet vehicles to its default state.

function resetHandling()
	local modelId = 541
	for k,_ in pairs(getModelHandling(modelId)) do
		setModelHandling(modelId, k, nil)
	end
end
addEventHandler("onResourceStop", resourceRoot, resetHandling)

Issues

Issue ID Description
#553 setModelHandling doesn't work with already created vehicles
#1198 "setModelHandling" function doesn't affect vehicles that have been changed using "setElementModel"

See other vehicle functions