Set up a if statement to an garage function()

hey i want to add an if statement that if a other vehicle is near 5.0 the spawning coords, you can not park another car out till you drove the other one away. As the result you get to print a notification. I tryed it many times but i wount get to work, pls help.

function(data, menu)

    insideMarker = false

    local plate = exports['esx_vehicleshop']:GeneratePlate()

    VehicleLoadTimer(data.current.model)

    local veh = CreateVehicle(data.current.model,463.77,-1019.48,28.1,89.05)

    SetPedIntoVehicle(GetPlayerPed(-1),veh,-1)

    SetVehicleNumberPlateText(veh,plate)

   

    TaskWarpPedIntoVehicle(PlayerPedId(), veh, -1)

    SetEntityAsMissionEntity(veh)

    local gps = AddBlipForEntity(veh)

    SetBlipSprite(gps, 227)

    SetBlipColour(gps, 3)

    BeginTextCommandSetBlipName("STRING")

    AddTextComponentString('Einsatzfahrzeug')

    EndTextCommandSetBlipName(gps)

    SetEntityAsMissionEntity(veh, true, true)

   

    if type == 'car' then

        ESX.ShowNotification(Config.CarOutFromPolGar)

    elseif type == 'helicopter' then

       

    end

   

    TriggerEvent("fuel:setFuel",veh,100.0)

    SetVehicleDirtLevel(veh, 0.1)      

end, function(data, menu)

    menu.close()

    insideMarker = false

end, function(data, menu)

end)

end

Hello, this is a friendly reminder because this is your first time creating a topic (or it has been a while since your last topic) in this category.

Please note that most of the support is provided by the Cfx.re community on a voluntary basis. We ask you to be patient; there is no guarantee we have a solution to your problem(s). To avoid unnecessary/duplicate topics, please browse the forums before creating a topic.

To improve your chances of your issue(s) being solved, please provide as much information as possible about the issue(s) you are having. Also —whenever possible— please use the template given to you when creating a topic.

Thanks for keeping these forums tidy!
:mascot:

Hello @Hakku1,

Maybe the following code will help?

function park_vehicle_attempt()
    local player_position = GetEntityCoords(PlayerPedId())
    local closest_vehicle = GetClosestVehicle(player_position, 5.0, 0, 70)
    local vehicle_position

    if closest_vehicle then
        vehicle_position = GetEntityCoords(closest_vehicle)
    else
        park_vehicle()
    end

    local distance = #(player_position - vehicle_position)
    if distance <= 5 then
        -- Closest vehicle is 5.0 or closer, throw error
    else
        park_vehicle()
    end
end

function park_vehicle()
    -- Your function for vehicle parking goes here
end

The above code is essentially a watered down version of what you’re looking for (if I understood your request correctly). All you have to do is replace the comments with your own logic/functionality.

If the code doesn’t work, please let me know and I will take a proper look as it’s currently untested.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.