Jump to content

Problema ao nascer dentro do veiculo


Recommended Posts

Posted (edited)

ola sou novo no mta e gostaria que esse script fizesse com que eu ja spawnasse o carro, com o player que deu o comando dentro do carro, e se possivel, colocar pra spawnar carro em outras pessoas pelo id da pessoa, ex: /createvehicle (id da pessoa que quero que spawne o carro) (id do carro que vai spawnar)

 

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 )

Edited by SciptNovato
  • Moderators
Posted

Olá, utilize o botão <> do fórum para postar scripts. Não cole direto no texto.

OfSmewi.png

Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanks! spacer.png

Minhas contribuições para a comunidade: LordHenry - MTA Wiki Profile
Inscreva-se no meu canal do YouTube: Lord Henry - Entertainment
Discord Oficial do MTA: https://mtasa.com/discord
Blacklist e Whitelist de Scripters: Planilha

Por favor, não me envie mensagens privadas solicitando suporte. Crie um tópico no fórum em vez disso.

Posted (edited)
On 25/08/2021 at 21:57, SciptNovato said:

ola sou novo no mta e gostaria que esse script fizesse com que eu ja spawnasse o carro, com o player que deu o comando dentro do carro, e se possivel, colocar pra spawnar carro em outras pessoas pelo id da pessoa, ex: /createvehicle (id da pessoa que quero que spawne o carro) (id do carro que vai spawnar)

 

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 )

Cara, fiquei com preguiça de ler esse código dessa forma, da próxima vez faça como o @Lord Henry instruiu acima...

Mas basicamente você cria o veículo com o createVehicle e depois use a função warpPedIntoVehicle para colocar o player dentro do veículo.

Edited by Boechat

Te ajudei? Me ajude também deixando seu Thanks! :Dspacer.png

 

Discord: _muelzera_

  • 2 weeks later...
Posted
local vehicleIds = {400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415,
    416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433,
    434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451,
    452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469,
    470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487,
    488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, 505,
    506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523,
    524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541,
    542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559,
    560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 576, 577,
    578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595,
    596, 597, 598, 599, 600, 601, 602, 603, 604, 605, 606, 607, 608, 609, 610, 611
}
 
function carPlayerInPlayer(player, _, idPlayer, idVehicle)
    local target = tonumber(idPlayer) local crt = tonumber(idVehicle) 
    local id = getPlayerID(target) local Vehicle = getVehicleByID(crt)
    if id then 
        if veh[id] and isElement(veh[id]) then 
            destroyElement(veh[id])
            veh[id] = nil 
        end
        iprint(id) 
        iprint(Vehicle)
        if Vehicle then 
            local x,y,z = getElementPosition(id) 
            veh[id] = createVehicle(crt, x,y,z) 
            warpPedIntoVehicle(id, veh[id])
        end
    end
end
addCommandHandler('c', carPlayerInPlayer)
 
addEventHandler('onPlayerQuit', getRootElement(), function()
    if veh[source] and isElement(veh[source]) then 
        destroyElement(veh[source])
        veh[source] = nil 
    end
end)
 
function getVehicleByID(vehID)
    vehID = tonumber(vehID)
    if (vehID) then
        for _, veh in ipairs(vehicleIds) do
            if (vehID == veh) then
                return veh
            end
        end
    end
    return false
end
 
function getPlayerID(id) 
    v = false 
    for i, player in ipairs(getElementsByType("player")) do 
        if getElementData(player, "ID") == id then 
            v = player 
            break 
        end
    end 
    return v 
end

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...