- Documentation
- Server functions
- setVehicleEngine
Function
setVehicleEngine
Fits a vehicle with an engine described by real-car parameters (power, torque, displacement, fuel, mass, gears) and calculates the handling fields from them: mass, top speed, acceleration, engine inertia, fuel type, number of gears and grip. An engine much stronger than the factory one reduces grip (wheelspin). Wear lowers power by up to 30%. nil restores the factory engine. Good for tuning and engine-swap systems on RP servers.
Syntax
bool setVehicleEngine(vehicle vehicle, table/nil spec [, float wear = 0])Arguments
vehiclevehicle- The vehicle.
spectable/nil- Engine table:
power(kW),torque(Nm),displacement(litres),cylinders,fuel("petrol","diesel","electric"),mass(engine kg),gears(1-5),name,code. Missing fields take the factory engine's value.nil= factory engine. wearfloat, optional = 0- Engine wear 0.0 (new) - 1.0 (worn out, -30% power).
Returns
true on success, false for a vehicle without handling data.
Example
addCommandHandler("swap", function(player)
local vehicle = getPedOccupiedVehicle(player)
if not vehicle then return end
setVehicleEngine(vehicle, { name = "V8 5.0", power = 300, torque = 540, displacement = 5.0,
cylinders = 8, fuel = "petrol", mass = 220, gears = 5 }, 0.1)
end)
See also
getVehicleEngineReturns the vehicle's engine: the one fitted withsetVehicleEngineor, when none was fitted, the factory engine calculated from game data (withfactory = true). The second value is wear 0..1. Works on both sides.getVehicleFactoryEngineReturns a model's factory engine. Power is calculated from the game's handling, and the other data (torque, displacement, cylinders, mass) are a realistic estimate, marked withestimated = true. It gives a reference point for tuning systems.getVehiclePerformanceReturns a vehicle's performance in a player-friendly form: power in kW and HP, torque, mass, 0-100 km/h time and top speed. You can pass a vehicle (its engine and wear are used) or a model number, optionally with an engine to compare.calculateEngineHandlingCalculates which handling fields an engine would give in a model, without fitting it. It returns whatsetVehicleEnginewould write into the vehicle, so it suits a preview in an engine shop.