I’ll just drop off a lua example, in case you you need it.
local radius = 100.0
local coords = vector3(1653.15, 2517.33, 45.56) -- Replace with the desired coordinates
local x = coords.x + math.random(-radius, radius)
local y = coords.y + math.random(-radius, radius)
local spawnOnPavement = false -- Change this if you want to spawn the ped on the nearest pavement
local foundSafeCoords, safeCoords = GetSafeCoordForPed(x, y, coords.z, spawnOnPavement , 16)
if not foundSafeCoords then -- The native couldn't find a safe spawn point, in which case we'll calculate the coordinates ourselves. It would probably be better to just not spawn the ped at this coordinates, and recalculate it.
local z = 0
repeat
local onGround, safeZ = GetGroundZFor_3dCoord(coords)
if not onGround then
z = z + 0.1
end
until onGround
safeCoords = vector3(x, y, safeZ)
end
local ped = CreateRandomPed(safeCoords.x, safeCoords.y, safeCoords.z)