PT-BR/CreateVehicle: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Sbx320 moved page CreateVehicle/PT-BR to PT-BR/CreateVehicle)
m (Undo revision 71358 by EOFIK (talk) Reason: No real change.)
Tag: Undo
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{BR/Funcao compartilhada}}{{BR/Nota|Os veículos (e outros elementos) criados em client-side são vistos somente pelo cliente que os criaram, não são sincronizados e os jogadores não podem entrar neles. Eles são essencialmente apenas para exibição.}}
{{BR/Funcao compartilhada}}
{{BR/Nota|Os veículos (e outros elementos) criados em client-side são vistos somente pelo cliente que os criaram, não são sincronizados e os jogadores não podem entrar neles. Eles são essencialmente apenas para exibição.}}
Esta função cria um veículo em uma localização especificada.
Esta função cria um veículo em uma localização especificada.


Line 7: Line 8:
==Sintaxe==
==Sintaxe==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
vehicle createVehicle ( int modelo, float x, float y, float z [, float rx, float ry, float rz, string numberplate, bool bDirection, int variant1, int variant2 ] )
vehicle createVehicle ( int model, float x, float y, float z [, float rx, float ry, float rz, string numberplate, bool bDirection, int variant1, int variant2 ] )
</syntaxhighlight>
</syntaxhighlight>
{{PT-BR/POO||[[Vehicle]]||}}
{{PT-BR/POO||[[Vehicle]]||}}


===Argumentos necessários===
===Argumentos necessários===
* '''modelo''': O [[IDs_de_veiculos|ID]] do veículo que está sendo criado
* '''model''': O [[IDs_de_veiculos|ID]] do veículo que está sendo criado
* '''x''': Um número [[float]] representando a coordenada X do mapa
* '''x''': Um número [[float]] representando a coordenada X do mapa
* '''y''': Um número [[float]] representando a coordenada Y do mapa
* '''y''': Um número [[float]] representando a coordenada Y do mapa
Line 185: Line 186:


==Veja também==
==Veja também==
 
[[de:createVehicle]]
 
[[pl:createVehicle]]
[[ru:CreateVehicle]]
[[en:CreateVehicle]]
{{Vehicle functions}}
{{Vehicle functions}}

Latest revision as of 20:46, 20 June 2021

Post-it.png Nota: Os veículos (e outros elementos) criados em client-side são vistos somente pelo cliente que os criaram, não são sincronizados e os jogadores não podem entrar neles. Eles são essencialmente apenas para exibição.

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.

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

Click to collapse [-]
Example 1: Server

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)
Click to collapse [-]
Example 2: Server

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 )
Click to expand [+]
Example 3: Server
Click to expand [+]
Example 4: Server
Click to collapse [-]
Example 5: Client

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 )


ADDED/UPDATED IN VERSION 1.4 :

Este é um exemplo de como essa função é usada em OOP(POO - Programação Orientada a Objeto)

Click to collapse [-]
OOP server

This script will create an Infernus at the center (0, 0, 3) of San Andreas upon execution.

addEventHandler( "onResourceStart", resourceRoot,
    function()
        infernus = Vehicle(411, Vector3(0, 0, 3)); -- Create an Infernus and spawn it at the middle of SA.
        infernus:setColor(0, 0, 0); -- Set its color to black.
        infernus.damageProof = true; -- Make it damage proof
    end
)
	
addCommandHandler( "blowinfernus",
    function(p)
        if not infernus.blown then -- Check if the Infernus is blown up or not.
            infernus:blow();
        else -- Ouch, it's blown up, let's output an error to the player.
            outputChatBox( "The Infernus has already been blown up by you.", p, 255, 0, 0, false );
        end
    end)

Veja também