Good question. Yes it will get all vehicles by default.
There is one thing that I do not know and that is: "Will vehicles in a different dimension be considered as streamed in?"
Because getElementsByType does have a setting that allows the user to only collect streamed in vehicles. Which is incredible useful to improve the performance of the script. But if you need all streamed out vehicles as well, it might not be a good solution.
https://wiki.multitheftauto.com/wiki/GetElementsByType
Syntax (clientside)
table getElementsByType ( string theType, [ element startat=getRootElement(), bool streamedIn=false ] )
Capturing only streamed in vehicles.
local vehicles = getElementsByType ("vehicle", root, true )
A different method, but has to be partly implemented on the resource that creates vehicles. (not recommended unless you know how to to work with the element tree)
local vehicleParent = createElement("vehicleParent")
local newVehicle
newVehicle = createVehicle ( 551, 0,0,0 )
setElementParent(newVehicle, vehicleParent)
newVehicle = createVehicle ( 551, 0,0,0 )
setElementParent(newVehicle, vehicleParent)
newVehicle = createVehicle ( 551, 0,0,0 )
setElementParent(newVehicle, vehicleParent)
setElementDimension(vehicleParent, 100) -- move all current vehicles to a different dimension (fun fact)
Getting only these 3 vehicles.
local vehicles
--
vehicles = getElementsByType ("vehicle", vehicleParent)
-- or
vehicles = getElementChildren ( vehicleParent, "vehicle" ) -- the difference: This function only captures the direct children of the parent 'vehicleParent'. But in this set-up it doesn't matter.
Else you might need an utility function, like this:
function filterElementsByDimension (elementList, dimension)
local newElementList = {}
for 1, #elementList do
local element = elementList[i]
if getElementDimension(element) == dimension then
newElementList[#newElementList + 1] = element
end
end
return newElementList
end