Something like this is what I wrote years ago.
local vehicles = {}
function makeMyCar(player,command,modelid)
if vehicles[player] then
if vehicles[player][2] then
destroyElement(vehicles[player][2])
end
vehicles[player][2] = vehicles[player][1]
local x,y,z = getElementPosition(player)
vehicles[player][1] = createVehicle(modelid,x,y,z)
warpPedIntoVehicle(player,vehicles[player][1])
else
vehicles[player] = {}
vehicles[player][1] = createVehicle(modelid,x,y,z)
warpPedIntoVehicle(player,vehicles[player][1])
end
end
addCommandHandler("vi",makeMyCar)