Skip to content

centroid

The centroid function calculates the centroid (geometric center) of a group of units within a specified distance. This function is useful for determining the central point of a group of units, which can be helpful for positioning and targeting purposes.

Parameters

  • units (table): A table containing the unit identifiers (such as "player", "target", "focus", etc.) for which to calculate the centroid.
  • dist (number): The maximum distance within which to consider the units for the centroid calculation.

Returns

  • x (number): The x-coordinate of the centroid.
  • y (number): The y-coordinate of the centroid.
  • z (number): The z-coordinate of the centroid.

Example Usage in Lua

Here is an example of how to use the centroid function in Lua:

local api = ...

-- Function to calculate and print the centroid of a group of units
function PrintCentroid(units, dist)
    local centroid = api.centroid(units, dist)
    print("The centroid of the units is located at: (" .. centroid.x .. ", " .. centroid.y .. ", " .. centroid.z .. ")")
end

-- Example usage: Calculate and print the centroid of a group of units within a distance of 10
local units = {"player", "party1", "party2"}
PrintCentroid(units, 10)