PT-BR/CreateVehicle
Esta função cria um veículo em uma localização especificada.
Vale notar que a posição do veículo é relativa ao ponto central do veículo, não sua base. Sendo assim, você precisa garantir que o valor z (eixo vertical) esteja a alguma altura acima do solo. Você pode achar a altura exata com a seguinte função client-side getElementDistanceFromCentreOfMassToBaseOfModel, ou você mesmo pode fazer uma estimativa e gerar o veículo para que ele caia no chão.
Sintaxe
vehicle createVehicle ( int model, float x, float y, float z [, float rx, float ry, float rz, string numberplate, bool bDirection, int variant1, int variant2 ] )
Sintaxe POO(OOP) Não entendeu o que significa isso?
- Método: Vehicle(...)
Argumentos necessários
- model: O ID do veículo que está sendo criado
- x: Um número float representando a coordenada X do mapa
- y: Um número float representando a coordenada Y do mapa
- z: Um número float representando a coordenada Z do mapa
Argumentos Opcionais
NOTA: Ao usar argumentos opcionais, pode ser necessário fornecer todos os argumentos anteriores ao que você deseja usar. Para obter mais informações sobre argumentos opcionais, consulte Argumentos Opcionais.
- rx: Um número float representando a rotação em torno do eixo X em graus.
- ry: Um número float representando a rotação em torno do eixo Y em graus.
- rz: Um número float representando a rotação em torno do eixo Z em graus.
- numberplate: Uma string que aparecerá na placa do veículo (máximo de 8 caracteres).
- bDirection (serverside only): Placeholder boolean que fornece compatibilidade com alguns scripts. Isso nunca teve nenhum efeito, mas é lido pelo código. Recomenda-se ignorar esse argumento, passando o argumento false ou variant1 em seu lugar.
- variant1: Um int para o primeiro variante do veículo. Veja vehicle variants.
- variant2: Um int para o segundo variante do veículo. Veja vehicle variants.
Retorna
Retorna o elemento Elemento/Vehicle que foi criado. Retorna false se os argumentos estão incorretos, ou se o limite de 65535 veículos spawnados no mundo for excedido
Usando trens
Trens são criados usando a função desta página. Eles são colocados no ponto mais próximo do percurso do trem do GTA:SA (geralmente são trilhos de trem) a partir do ponto em que ele foi spawnado.
Exemplo
Este exemplo cria um marker 'vehicle spawner' que dá ao jogador um veículo assim que ele atinge o marker.
local vehMark = createMarker(-2426.34106, -639.12714, 132.93631,"cylinder")
function vehicleSpawner(hitElement,matchingDimension)
if getElementType(hitElement) == "player" then
if getPedOccupiedVehicle(hitElement) == false then
local x,y,z = getElementPosition(hitElement)
local veh = createVehicle(551, x,y,z)
warpPedIntoVehicle(hitElement,veh)
end
end
end
addEventHandler("onMarkerHit",vehMark,vehicleSpawner)
Este exemplo cria um veículo a 5 unidades de distância do jogador quando ele digita createvehicle e seu nome no 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 = getElementRotation ( 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 )
Este script spawna um tanque em cima do jogador local.
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 )
Veja também
- addVehicleUpgrade
- addVehicleSirens
- attachTrailerToVehicle
- blowVehicle
- createVehicle
- detachTrailerFromVehicle
- fixVehicle
- getOriginalHandling
- getTrainDirection
- getTrainPosition
- getTrainSpeed
- getVehicleColor
- getVehicleCompatibleUpgrades
- getVehicleController
- getVehicleDoorOpenRatio
- getVehicleDoorState
- getVehicleEngineState
- getVehicleHandling
- getVehicleHeadLightColor
- getVehicleLandingGearDown
- getVehicleLightState
- getVehicleMaxPassengers
- getVehicleModelFromName
- getVehicleName
- getVehicleNameFromModel
- setVehicleNitroActivated
- 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
- removeVehicleSirens
- setTrainDerailable
- setTrainDerailed
- setTrainDirection
- setTrainPosition
- setTrainSpeed
- setVehicleColor
- setVehicleDamageProof
- setVehicleDoorOpenRatio
- setVehicleDoorState
- setVehicleDoorsUndamageable
- setVehicleEngineState
- setVehicleFuelTankExplodable
- setVehicleHandling
- setVehicleHeadLightColor
- setVehicleLandingGearDown
- setVehicleLightState
- setVehicleLocked
- setVehicleOverrideLights
- setVehiclePaintjob
- setVehiclePanelState
- setVehiclePlateText
- setVehicleSirens
- setVehicleSirensOn
- setVehicleTaxiLightOn
- setVehicleTurretPosition
- setVehicleVariant
- setVehicleWheelStates