GetVehiclesOfType: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
mNo edit summary
(7 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{Server function}}
__NOTOC__
__NOTOC__
This function scans through all the current vehicles and returns the ones matching the given model.
This function scans through all the current vehicles and returns the ones matching the given model.


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">table getVehiclesOfType ( model )</syntaxhighlight>
<syntaxhighlight lang="lua">table getVehiclesOfType ( int model )</syntaxhighlight>
 
{{OOP||[[vehicle]]:getAllOfType}}
===Required Arguments===
===Required Arguments===
*'''model''': The model of vehicles you want.
*'''model''': The model of vehicles you want.
Line 12: Line 13:


==Example==
==Example==
This example finds all landstalkers on the map and moves them 5 units to the left.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- Find all the vehicles with the model 400 (landstalker)
-- Find all the vehicles with the model 400 (landstalker)
vehicles = getVehiclesOfType ( 400 )
vehicles = getVehiclesOfType ( 400 )
-- Loop through the vehicle list
-- Loop through the vehicle list
for vehicleKey, vehicleValue in vehicles do
for vehicleKey, vehicleValue in ipairs ( vehicles ) do
-- Get the vehicle's position
-- Get the vehicle's position
         x, y, z = getEntityPosition ( vehicleValue )
         x, y, z = getElementPosition ( vehicleValue )
         -- Move the vehicle to the left
         -- Move the vehicle to the left
         setEntityPosition ( vehicle, x - 5, y, z )
         setElementPosition ( vehicleValue, x - 5, y, z )
end
end
</syntaxhighlight>
</syntaxhighlight>
Line 26: Line 28:
==See Also==
==See Also==
{{Vehicle functions}}
{{Vehicle functions}}
[[de:GetVehiclesOfType]]

Revision as of 23:42, 17 December 2014

This function scans through all the current vehicles and returns the ones matching the given model.

Syntax

table getVehiclesOfType ( int model )

OOP Syntax Help! I don't understand this!

Method: vehicle:getAllOfType(...)


Required Arguments

  • model: The model of vehicles you want.

Returns

Returns a table of existing vehicles matching the specified model.

Example

This example finds all landstalkers on the map and moves them 5 units to the left.

-- Find all the vehicles with the model 400 (landstalker)
vehicles = getVehiclesOfType ( 400 )
-- Loop through the vehicle list
for vehicleKey, vehicleValue in ipairs ( vehicles ) do
	-- Get the vehicle's position
        x, y, z = getElementPosition ( vehicleValue )
        -- Move the vehicle to the left
        setElementPosition ( vehicleValue, x - 5, y, z )
end

See Also