buddem/car/carspawn.lua

45 lines
1.2 KiB
Lua
Raw Normal View History

2019-10-24 22:32:40 +03:00
RegisterCommand('car', function(source, args)
local vehicle = args[1] or "futo"
if not IsModelInCdimage(vehicle) or not IsModelAVehicle(vehicle) then
TriggerEvent("chat:addMessage", {
color = {255,0,0},
args = { vehicle .. ' ei ole ajoneuvo tai sitä ei löydy.' }
})
return
end
RequestModel(vehicle)
while not HasModelLoaded(vehicle) do
Wait(500)
end
local ped = PlayerPedId()
local pos = GetEntityCoords(ped)
local head, vect = GetClosestVehicleNodeWithHeading(pos.x, pos.y, pos.z, 1)
local x,y,z = table.unpack(vect)
-- local veh = CreateVehicle(vehicle, pos.x+5, pos.y+5, pos.z, GetEntityHeading(ped), true, false)
local veh = CreateVehicle(vehicle, x, y, z, GetEntityHeading(ped), true, false)
-- local veh = CreateVehicle(vehicle, x, y, z, head, true, false)
SetVehicleOnGroundProperly(veh)
SetVehicleNumberPlateText(veh, GetPlayerName())
TriggerEvent('chat:addMessage', {
color = {0,255,0},
args = { 'Tässä pyytämäsi upouusi ' .. vehicle }
})
local blip = AddBlipForEntity(veh)
SetBlipSprite(blip, 225)
SetBlipFlashes(blip, true)
SetBlipFlashTimer(blip, 10000)
SetModelAsNoLongerNeeded(vehicle)
SetEntityAsNoLongerNeeded(veh)
end, false)