Hi there. I know, there are few topics about this function but I have read it all and it isn’t help me. I want to get ground height for specific coordinates. I try do this by lua and C# uneffectually
LUA Code
AddEventHandler('getRandomPositionWithGroundHeight', function(x, y)
local ground, newZ
local z = 0
ground, newZ = GetGroundZFor_3dCoord(x, y, 99990.0, 1)
Citizen.Trace('trying to get groundZ at ' .. tostring(x) .. ', ' .. tostring(y) .. ', ' .. tostring(z))
TriggerEvent('onRandomPositionWithGroundHeightCalculated', x, y, newZ);
end)
C# code
var groundHeight = 0.0f;
var groundFound = API.GetGroundZFor_3dCoord(randomPosition.X, randomPosition.Y, 99999.0f, ref groundHeight, false);
more С# code
var groundHeight = 0.0f;
for (var i = 0; i < 800; i++)
{
var groundFound = API.GetGroundZFor_3dCoord(randomPosition.X, randomPosition.Y, i, ref groundHeight, false);
Debug.WriteLine($"Ground find result for {i}: groundFound: {groundFound}, groundHeight: {groundHeight}");
if (groundFound)
Debug.WriteLine("GROUND FOUND");
}
But it always return groundHeight = 0. What am I doing wrong?