CreateVehicle: Difference between revisions
Uc.Setlings (talk | contribs) |
Uc.Setlings (talk | contribs) |
||
Line 60: | Line 60: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- Cars with this ID is not allowed | -- Cars with this ID is not allowed | ||
LockID = { | |||
[435] = true ; | [435] = true ; | ||
[441] = true ; | [441] = true ; | ||
Line 88: | Line 88: | ||
if ( tonumber(idmodel) ) and ( tonumber(sx) ) and ( tonumber(sy) ) and ( tonumber(sz) ) then | if ( tonumber(idmodel) ) and ( tonumber(sx) ) and ( tonumber(sy) ) and ( tonumber(sz) ) then | ||
if (not | if (not LockID[tonumber(idmodel)] ) then | ||
data = ( numberplate or "PRIVATE" ) | data = ( numberplate or "PRIVATE" ) | ||
local spawn = createVehicle(tonumber(idmodel), tonumber(sx), tonumber(sy), tonumber(sz), 0, 0, 0, data) | local spawn = createVehicle(tonumber(idmodel), tonumber(sx), tonumber(sy), tonumber(sz), 0, 0, 0, data) |
Revision as of 05:36, 20 March 2016
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 ] )
OOP Syntax Help! I don't understand this!
- Method: Vehicle(...)
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.
- bDirection: 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 example spawns a car. To spawn a car need to enter the number of the desired car and also specify the coordinates for the spawn point of this car.
-- Cars with this ID is not allowed LockID = { [435] = true ; [441] = true ; [449] = true ; [450] = true ; [464] = true ; [465] = true ; [501] = true ; [537] = true ; [538] = true ; [564] = true ; [569] = true ; [570] = true ; [584] = true ; [590] = true ; [591] = true ; [594] = true ; [606] = true ; [607] = true ; [608] = true ; [610] = true ; [611] = true ; } addCommandHandler("spveh", function(p, command, idmodel, sx, sy, sz, numberplate) if getElementType(p) == "player" then if ( tonumber(idmodel) ) and ( tonumber(sx) ) and ( tonumber(sy) ) and ( tonumber(sz) ) then if (not LockID[tonumber(idmodel)] ) then data = ( numberplate or "PRIVATE" ) local spawn = createVehicle(tonumber(idmodel), tonumber(sx), tonumber(sy), tonumber(sz), 0, 0, 0, data) if isElement(spawn) then -- If the vehicle has been created then: outputChatBox("Your vehicle has been created! INFO:", p, 255, 255, 0) outputChatBox("ID Vehicle: "..getElementModel(spawn), p, 255, 255, 0) outputChatBox("Name Vehicle: "..getVehicleName(spawn), p, 255, 255, 0) local x, y, z = getElementPosition(spawn) -- Check the vehicle position outputChatBox("Vehicle Coordinates: X: "..tostring(x) .. ", Y: " .. tostring(y) .. ", Z: " .. tostring(z), p, 255, 255, 0) outputChatBox("Vehicle Number plate: "..getVehiclePlateText(spawn), p, 255, 255, 0) else outputChatBox("Unknown ERROR!", p, 255, 100, 100) end else outputChatBox("Sorry! This car model number is not allowed!", p, 255, 100, 100) end else outputChatBox("Error! Correct syntax Use: /spveh [model] [x] [y] [z] or more [Number Plate]", p, 255, 100, 100) end end end)
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 )
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