M MY Multiplayer: Wiki
Side
Kind

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

NameTypeDescription
x, yfloatThe point to search around.
minDistancefloatThe least distance from the point, in metres, for a spot that is visible on screen.
maxDistancefloatThe most distance from the point for a spot that is visible on screen.
minOffScreenfloatThe least distance for a spot off screen.default minDistance
maxOffScreenfloatThe 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)
end
NoteIt 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.

See also