buddem/car/carspawn.lua

47 lines
1.3 KiB
Lua
Raw Normal View History

2019-10-24 22:32:40 +03:00
RegisterCommand('car', function(source, args)
2019-10-26 06:16:48 +03:00
-- Random vehicle if nothing asked
local vehicle = args[1] or vehicles[math.random(#vehicles)]
2019-10-24 22:32:40 +03:00
2019-10-24 23:49:22 +03:00
-- Check existance and if a vehicle
2019-10-24 22:32:40 +03:00
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
2019-10-24 23:49:22 +03:00
-- Load model
2019-10-24 22:32:40 +03:00
RequestModel(vehicle)
while not HasModelLoaded(vehicle) do
Wait(500)
end
2019-10-24 23:49:22 +03:00
-- Position vehicle niceishly
2019-10-24 22:32:40 +03:00
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, x, y, z, GetEntityHeading(ped), true, false)
SetVehicleOnGroundProperly(veh)
2019-10-24 23:49:22 +03:00
-- Set register plate and a blip
2019-10-24 22:32:40 +03:00
SetVehicleNumberPlateText(veh, GetPlayerName())
local blip = AddBlipForEntity(veh)
SetBlipSprite(blip, 225)
SetBlipFlashes(blip, true)
SetBlipFlashTimer(blip, 10000)
2019-10-24 23:49:22 +03:00
-- Inform vehicle spawned
TriggerEvent('chat:addMessage', {
color = {0,255,0},
2019-10-24 23:56:49 +03:00
args = { 'Tässä pyytämäsi upouusi ' .. vehicle }
})
2019-10-24 23:49:22 +03:00
-- Cleaning up. Let R* handle despawning
2019-10-24 22:32:40 +03:00
SetModelAsNoLongerNeeded(vehicle)
SetEntityAsNoLongerNeeded(veh)
end, false)