CreateVehicle: Difference between revisions
(Added a "Needs_Checking" for the numberplates which have to contain at least 1 letter) |
m (Combined needs checking templates) |
||
Line 1: | Line 1: | ||
{{Needs_Checking|Numberplates only seem to work for some vehicles, and then only for the front or rear plate only | {{Needs_Checking| | ||
* Numberplates only seem to work for some vehicles, and then only for the front or rear plate only | |||
* Explain the direction parameter which should always be false and what is the point of having a parameter whose value need to be the same all the time. --[[User:MTA SE|MTA SE]] 20:05, 5 July 2012 (UTC) | |||
* The numberplates have to contain at least 1 letter. For example "132" will not work and the function will fail but, "13A" or "132A" will work | |||
}} | |||
__NOTOC__ | __NOTOC__ | ||
{{Server client function}} | {{Server client function}} |
Revision as of 07:56, 28 July 2012
This article needs checking. | |
Reason(s):
|
This template is no longer in use as it results in poor readability. This function creates a vehicle at the specified location.
Its worth noting that the position of the vehicle is the center point of the vehicle, not its base. As such, you need to ensure that the z value (vertical axis) is some height above the ground. You can find the exact height using the client side function getElementDistanceFromCentreOfMassToBaseOfModel, or you can estimate it yourself and just spawn the vehicle so it drops to the ground.
Syntax
vehicle createVehicle ( int model, float x, float y, float z [, float rx, float ry, float rz, string numberplate, bool bDirection, int variant1, int variant2 ] )
Required Arguments
- model: The vehicle ID of the vehicle being created.
- x: A floating point number representing the X coordinate on the map.
- y: A floating point number representing the Y coordinate on the map.
- z: A floating point number representing the Z coordinate on the map.
Optional Arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.
- rx: A floating point number representing the rotation about the X axis in degrees.
- ry: A floating point number representing the rotation about the Y axis in degrees.
- rz: A floating point number representing the rotation about the Z axis in degrees.
- numberplate: A string that will go on the number plate of the car (max 8 characters). This is only applicable to cars.
- direction: A boolean which should be set to false. *SERVER ONLY*
- variant1: An integer for the first vehicle variant see Vehicle variants
- variant2: An integer for the second vehicle variant see Vehicle variants
Returns
Returns the vehicle element that was created. Returns false if the arguments are incorrect, or if the vehicle limit of 65535 is exceeded.
Using trains
Trains are created using the createVehicle function. They are placed at the nearest point of the GTASA train pathing (railroad tracks) from their spawning point.
Example
This script spawns a Rhino on top of one lucky individual.
function scriptCreateTank ( player, command ) local luckyBugger = getRandomPlayer() -- get a random player local x, y, z = getElementPosition ( luckyBugger ) -- retrive the player's position createVehicle ( 432, x, y, z + 10 ) -- create the tank 10 units above them outputChatBox ( "You got Tank'd!", luckyBugger ) end --Attach the 'scriptCreateTank' function to the "tank" command addCommandHandler ( "tank", scriptCreateTank )
This script spawns a Rhino on top of the local player.
function scriptCreateTank ( commandName ) local luckyBugger = getLocalPlayer() -- get the local player local x, y, z = getElementPosition ( luckyBugger ) -- retrive the player's position createVehicle ( 432, x, y, z + 10 ) -- create the tank 10 units above them outputChatBox ( "You got Tank'd!", 255, 0, 0) end --Attach the 'scriptCreateTank' function to the "tank" command addCommandHandler ( "tank", scriptCreateTank )
This example creates a vehicle five units to the right of a player when they type createvehicle and its name in the console:
local distance = 5 --units -- define our handler (we'll take a variable number of parameters where the name goes, because there are vehicle names with more than one word) function consoleCreateVehicle ( sourcePlayer, commandName, ... ) -- if a player triggered it, not the admin, if ( sourcePlayer ) then -- calculate the position of the vehicle based on the player's position and rotation: local x, y, z = getElementPosition ( sourcePlayer ) -- get the player's position local rotZ = getPedRotation ( sourcePlayer ) -- get the player's rotation around the Z axis in degrees x = x + ( ( math.cos ( math.rad ( rotZ ) ) ) * distance ) -- calculate the X position of the vehicle y = y + ( ( math.sin ( math.rad ( rotZ ) ) ) * distance ) -- calculate the Y position of the vehicle -- get the complete vehicle name by joining all passed parameters using Lua function table.concat local vehicleName = table.concat({...}, " ") -- get the vehicle's model ID from the name local vehicleID = getVehicleModelFromName ( vehicleName ) -- if vehicle ID is valid, if vehicleID then -- create the vehicle using the information gathered above: local newVehicle = createVehicle ( vehicleID, x, y, z, 0, 0, rotZ ) -- if vehicle creation failed, give the player a message if not newVehicle then outputConsole ( "Failed to create vehicle.", sourcePlayer ) end end end end -- Attach the 'consoleCreateVehicle' function to the "createvehicle" command addCommandHandler ( "createvehicle", consoleCreateVehicle )
See Also
- addVehicleUpgrade
- attachTrailerToVehicle
- blowVehicle
- createVehicle
- detachTrailerFromVehicle
- fixVehicle
- getOriginalHandling
- getTrainDirection
- getTrainPosition
- getTrainSpeed
- getTrainTrack
- getVehicleColor
- getVehicleCompatibleUpgrades
- getVehicleController
- getVehicleDoorOpenRatio
- getVehicleDoorState
- getVehicleEngineState
- getVehicleHandling
- getVehicleHeadLightColor
- getVehicleLandingGearDown
- getVehicleLightState
- getVehicleMaxPassengers
- getVehicleModelFromName
- getVehicleName
- getVehicleNameFromModel
- getVehicleOccupant
- getVehicleOccupants
- getVehicleOverrideLights
- getVehiclePaintjob
- getVehiclePanelState
- getVehiclePlateText
- getVehicleSirenParams
- getVehicleSirens
- getVehicleSirensOn
- getVehicleTowedByVehicle
- getVehicleTowingVehicle
- getVehicleTurretPosition
- getVehicleType
- getVehicleUpgradeOnSlot
- getVehicleUpgradeSlotName
- getVehicleUpgrades
- getVehicleVariant
- getVehicleWheelStates
- isTrainDerailable
- isTrainDerailed
- isVehicleBlown
- isVehicleDamageProof
- isVehicleFuelTankExplodable
- isVehicleLocked
- isVehicleOnGround
- isVehicleTaxiLightOn
- removeVehicleUpgrade
- setTrainDerailable
- setTrainDerailed
- setTrainDirection
- setTrainPosition
- setTrainSpeed
- setTrainTrack
- setVehicleColor
- setVehicleDamageProof
- setVehicleDoorOpenRatio
- setVehicleDoorState
- setVehicleDoorsUndamageable
- setVehicleEngineState
- setVehicleFuelTankExplodable
- setVehicleHandling
- setVehicleHeadLightColor
- setVehicleLandingGearDown
- setVehicleLightState
- setVehicleLocked
- setVehicleOverrideLights
- setVehiclePaintjob
- setVehiclePanelState
- setVehiclePlateText
- setVehicleSirens
- setVehicleSirensOn
- setVehicleTaxiLightOn
- setVehicleTurretPosition
- setVehicleVariant
- setVehicleWheelStates