RU/CreateVehicle

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

[[{{{image}}}|link=|]] Note: Машины (и другие элементы) созданные на клиентской стороне доступны только ему же, не синхронизируются, и другие не могут в них войти. По существу они нужно только для показа.

Эта функция создает машину в определенной позиции.

Стоит помнить, что указывается позиция центра машины, а не базы. Вам нужно проверять положение в оси z, с тем что-бы машина была выше земли. Вы можете использовать клиентскую getElementDistanceFromCentreOfMassToBaseOfModel, или же просто устанавливать её заметно выше земли, рассчитывая на её падение.

Синтаксис

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!

Note: Это статическая функция класса Vehicle.
Method: Vehicle(...)


Обязательные параметры

  • model: ИД машины которую вы создаете.
  • x: Число(float) соответствующее позиции в X координате карты.
  • y: Число(float) соответствующее позиции в Y координате карты.
  • z: Число(float) соответствующее позиции в Z координате карты.

Необязательные параметры

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: Число(float) соответствующее углу в X в координате карты (в градусах).
  • ry: Число(float) соответствующее углу в Y в координате карты (в градусах).
  • rz: Число(float) соответствующее углу в Z в координате карты (в градусах).
  • numberplate: A string that will go on the number plate of the car (max 8 characters). This is only applicable to cars.
  • direction: Логическое значение, которое должено быть установлено в false. *SERVER ONLY*


  • variant1: Число соответствующее первому варианту машины.Vehicle variants
  • variant2: Число соответствующее второму варианту машины. Vehicle variants

Возвращает

Возвращает элемент созданной машины.Возвращает false если параметры заданы неверно, или машины достигли лимита в 65535. Returns the vehicle element that was created. Returns false if the arguments are incorrect, or if the vehicle limit of 65535 is exceeded.

Использование поездов

Поезда создаются с помощью функции createVehicle. Они устанавливаются на ближайшей точке ж/д пути.

Примеры

Click to collapse [-]
Example 1: Server

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

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


ADDED/UPDATED IN VERSION 1.4 :

This is an example of how this function is executed in an OOP environment.

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)

Смотрите также