Skip to content

A3D_FindRandomPoint

imshooter edited this page Oct 17, 2026 · 1 revision

Find a random spot on the ground around a point where something fits, such as a spawn or a dropped item.

The spot lies on ground that faces up within 45 degrees, out of the water, with room for a sphere of clearance resting on it, free of the map and of every kind of body.

native bool:A3D_FindRandomPoint(
    Float:x,
    Float:y,
    Float:z,
    Float:radius,
    &Float:spotX,
    &Float:spotY,
    &Float:spotZ,
    Float:height = 5.0,
    Float:clearance = 0.5,
    worldid = -1
);

Parameters

Parameter Description Default
Float:x Centre on the X axis.
Float:y Centre on the Y axis.
Float:z Centre on the Z axis.
Float:radius Distance from the centre to look within.
&Float:spotX Spot found on the X axis.
&Float:spotY Spot found on the Y axis.
&Float:spotZ Height of the ground at the spot.
Float:height How far above and below z the ground is looked for. Inside a building it must stay under the ceiling. 5.0
Float:clearance Radius of the room needed. 0.5
worldid Virtual world to look in, or -1 for every world. -1

Returns

  • true when a spot was found.
  • false when none of 16 tries found one.

How it works

The native makes up to 16 tries. Each picks a column at random inside the circle, spread evenly over its area, and looks down it from z + height to z - height for the map and static objects. The column is kept when:

  1. the ground faces up within 45 degrees of the vertical,
  2. the ground lies out of the water,
  3. a sphere of clearance resting on the ground touches nothing, neither the map nor any kind of body.

The point written lies on the ground. Add the height of what is placed there, about a metre for a player.

Inside a building, keep z + height under the ceiling, or the columns find the roof. The spots differ from call to call. When all 16 tries fail, such as in a crowded room or on a steep hill, the native returns false.

Example

Scatters the loot of a box around it.

stock ScatterLoot(Float:x, Float:y, Float:z, count) {
    new
        Float:spotX,
        Float:spotY,
        Float:spotZ
    ;

    for (new i; i != count; ++i) {
        if (!A3D_FindRandomPoint(x, y, z, 4.0, spotX, spotY, spotZ, 3.0, 0.3)) {
            continue;
        }

        CreatePickup(1212, 1, spotX, spotY, spotZ + 0.5);
    }
}

Related

Home

Guides

Reference

Functions

Creating objects
Motion
Placement
Behaviour
Display and data
Rays
Shapes
Players, vehicles and actors
Map probes
Screen
Map objects
Water
Models and surfaces
Rotations and offsets
Vehicles
Routes
Route display
Walking
Callbacks

Clone this wiki locally