- Documentation
- Server functions
- spawnVehicleFlyingComponent
Function
spawnVehicleFlyingComponent
Creates an object element at the vehicle's position and gives it the vehicle's speed with a slight random spread, as if a part had fallen off. The object disappears after the given time. The part number is stored in the element data flyingComponent.
Syntax
object spawnVehicleFlyingComponent(vehicle vehicle, int nodeIndex [, int collisionType = nil, int lifetime = 30000])Arguments
vehiclevehicle- The vehicle.
nodeIndexint- Part number.
collisionTypeint, optional = nil- Accepted for compatibility with existing scripts and ignored.
lifetimeint, optional = 30000- Lifetime of the piece in ms; 0 = stays permanently.
Returns
The created object, or false.
Example
addEventHandler("onVehicleDamage", root, function(loss)
if loss > 200 then
local piece = spawnVehicleFlyingComponent(source, 1, nil, 10000)
if piece then setElementModel(piece, 1327) end
end
end)
Notes
Limitation. The object gets the vehicle's model number, and the game has no such object, so the detached part is not visible; the function suits script logic (e.g. your own model set with setElementModel).