Revision Difference
Vehicle:SetVehicleParams#512261
<function name="SetVehicleParams" parent="Vehicle" type="classfunc">⤶
<description>⤶
Sets the vehicle parameters for given vehicle.⤶
⤶
<note>Not all variables from the <page>VehicleParams</page> can be set.</note>⤶
⤶
<bug issue="2625">Because this method uses miles per hour but <page>Vehicle:GetVehicleParams</page> returns Hammer units per second, this method incorrectly modifies the vehicle engine's "boostMaxSpeed", "maxRevSpeed" and "maxSpeed" even when not explicitly set in a call to this method.⤶
⤶
**Workaround**: In order to retain the original values for these fields, call <page>Vehicle:GetVehicleParams</page> yourself, convert the mentioned fields from Hammer units per second to miles per hour (1 MPH &asymp; 17.6 HU/s in this case) and add them to the table passed into the call to this setter. Avoid doing this repeatedly to avoid floating point inaccuracies over time (store the ready-calculated value for next time if possible).</bug>⤶
</description>⤶
<realm>Server</realm>⤶
<args>⤶
<arg name="params" type="table">The new new vehicle parameters. See <page>VehicleParams</page></arg>⤶
</args>⤶
</function>⤶
⤶
<example>⤶
<description>Adds 25 horsepower to every vehicle spawned.</description>⤶
<code>⤶
hook.Add("PlayerSpawnedVehicle", "VehicleParamsExample", function(ply, ent)⤶
⤶
local params = ent:GetVehicleParams()⤶
⤶
⤶
params.engine.horsepower = params.engine.horsepower + 25⤶
⤶
⤶
ent:SetVehicleParams(params)⤶
⤶
end)⤶
</code>⤶
⤶
</example>