Best Way to Identify Prop (Fire Hydrant) Based on Proximity?

Hey all, I’m currently developing a water management script for FD’s to use to have a little bit of a more realistic experience, by managing the water levels on their trucks. At the moment I’m trying to work out the best way to identify a fire hydrant in front of or around the player. Currently I’m having little success using a ray trace, which is this code:

Current Non-Functioning Ray Tracing Code
Citizen.CreateThread(function()
    while true do
        if findHydrant == true then
            local pos = GetEntityCoords(GetPlayerPed(-1))
            local entityWorld = GetOffsetFromEntityInWorldCoords(GetPlayerPed(-1), 0.0, 3.0, -1.0)
			DrawLine(pos.x, pos.y, pos.z, entityWorld.x, entityWorld.y, entityWorld.z, 255, 0, 0, 255) --only for debugging purposes
            local rayHandle = CastRayPointToPoint(pos.x, pos.y, pos.z, entityWorld.x, entityWorld.y, entityWorld.z, 10, GetPlayerPed(-1), 0)
            local _, _, _, _, hydrantHandle = GetRaycastResult(rayHandle)
            print(hydrantHandle) -- only for debug, at the moment is only printing 0
            for i,v in ipairs(hydrants) do
                if hydrantHandle == hydrants[i] then
                    activeHydrant = hydrantHandle
                    hydrantLocation = GetEntityCoords(hydrantHandle)
                end
            end
        end
    Citizen.Wait(0)
    end
end)

The Ray tracing works to find a fire engine, but I’m struggling to get it to work for the hydrants.

The only other method of finding these hydrants that I can think of is just using a set of coordinates in a table, where the coordinates mark hydrants around the map…the only problem is there’s probably (easily) 200+ hydrants around. Which is a lot of data and finding to do. So I’d like to avoid that if possible.

I would appreciate any assistance or suggestions at all! :slight_smile:

I would suggest using the following native

GetClosestObjectOfType

This native does all the work for you and returns the closest object that you want to find.

So in your case, the object you want to be searching for is prop_fire_hydrant_2. I believe the same fire hydrant is used across the entire map, if not, you can simply search for multiple objects instead of just the model mentioned above.

For a full list of objects (and their corresponding hashes): click here
For more information about this native: click here

1 Like

Wow! I can’t believe I missed something as simple as just a native. :man_facepalming:

Thank you so much for your help, and I’m happy to report it’s now functioning correctly!!!