getSafePedSpawnPosition
Client
Picks a random spot on a footpath near a point where a ped can appear, the way SA chooses where to create peds. The spot is on the ground.
vec3|false getSafePedSpawnPosition(float x, y, float minDistance, float maxDistance [, float minOffScreen = minDistance, float maxOffScreen = maxDistance])
Parameters
| Name | Type | Description |
|---|---|---|
| x, y | float | The point to search around. |
| minDistance | float | The least distance from the point, in metres, for a spot that is visible on screen. |
| maxDistance | float | The most distance from the point for a spot that is visible on screen. |
| minOffScreen | float | The least distance for a spot off screen.default minDistance |
| maxOffScreen | float | The most distance for a spot off screen.default maxDistance |
Returns
The spot's position, or false if no spot worked.
Example
local position = getElementPosition(localPlayer)
local spot = getSafePedSpawnPosition(position.x, position.y, 40, 60, 20, 60)
if spot then
createPed("male01", spot.x, spot.y, spot.z)
endNoteIt only searches the path area (750 m wide) that holds the point, and that area must be loaded. The result is random: the same call gives different spots, and one may fail where another succeeds.