I am trying to make a function so when i press “Y” after the ShowAdvNotification a tractor2 spawns, but it does not seem to work.
Can someone help me? All help is appreciated
ShowAdvNotification("CHAR_MP_ARMY_CONTACT", "Jonas", "Hö leverans", "Kan du hjälpa mig att leverera en vagn med hö? ~y~ Y/~r~N")
Citizen.Wait(5000)
if IsControlJustReleased(1, 246) then
function SpawnVehicle(request)
local myPed = GetPlayerPed(-1)
local player = PlayerId()
local vehicle = GetHashKey(request)
RequestModel(vehicle)
while not HasModelLoaded(vehicle) do
Wait(1)
end
local coords = GetOffsetFromEntityInWorldCoords(GetPlayerPed(-1), 0, 5.0, 0)
local spawned_car = CreateVehicle(vehicle, coords, 64.55118,116.613,78.69622, true, false)
SetVehicleOnGroundProperly(spawned_car)
SetPedIntoVehicle(myPed, spawned_car, - 1)
SetModelAsNoLongerNeeded(vehicle)
if IsVehicleModel(spawned_car, GetHashKey("tractor2")) then
end
end
end
end
ShowAdvNotification("CHAR_MP_ARMY_CONTACT", "Jonas", "Hö leverans", "Kan du hjälpa mig att leverera en vagn med hö? ~y~ Y/~r~N")
Citizen.Wait(5000)
if IsControlJustReleased(1, 246) then
SpawnVehicle('adder')
function SpawnVehicle(request)
local myPed = GetPlayerPed(-1)
local player = PlayerId()
local vehicle = GetHashKey(request)
RequestModel(vehicle)
while not HasModelLoaded(vehicle) do
Wait(1)
end
local coords = GetOffsetFromEntityInWorldCoords(GetPlayerPed(-1), 0, 5.0, 0)
local spawned_car = CreateVehicle(vehicle, coords, 64.55118,116.613,78.69622, true, false)
SetVehicleOnGroundProperly(spawned_car)
SetPedIntoVehicle(myPed, spawned_car, - 1)
SetModelAsNoLongerNeeded(vehicle)
if IsVehicleModel(spawned_car, GetHashKey("tractor2")) then
end
end
end
end
i solved it: i wrote the function before Citizen.Createthread function:
function spawnCar()
RequestModel(Config.car.hash)
while not HasModelLoaded(Config.car.hash) do
RequestModel(Config.car.hash)
Citizen.Wait(0)
end
local x, y, z = table.unpack(GetEntityCoords(GetPlayerPed(-1), false))
local vehicle = CreateVehicle(Config.car.hash, -127.98, 1927.0, 197.09, 0.0, true, false)
SetEntityAsMissionEntity(vehicle, true, true)