# Problema ao nascer dentro do veiculo

## Recommended Posts

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

Edited by SciptNovato
• Other Languages Moderators

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

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

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
• 2 weeks later...
local vehicleIds = {400401402403404405406407408409410411412413414415,
416417418419420421422423424425426427428429430431432433,
434435436437438439440441442443444445446447448449450451,
452453454455456457458459460461462463464465466467468469,
470471472473474475476477478479480481482483484485486487,
488489490491492493494495496497498499500501502503504505,
506507508509510511512513514515516517518519520521522523,
524525526527528529530531532533534535536537538539540541,
542543544545546547548549550551552553554555556557558559,
560561562563564565566567568569570571572573574575576577,
578579580581582583584585586587588589590591592593594595,
596597598599600601602603604605606607608609610611
}

function carPlayerInPlayer(player_idPlayeridVehicle)
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

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
• 1

## Create an account

Register a new account