DCS func getNearestCargos

From DCS World Wiki - Hoggitworld.com
Revision as of 00:07, 21 March 2022 by Grimes (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Scripting Root

Envrioment: Mission Scripting
Function: getNearestCargos Added with: 2.5.5
Member Of: Unit
Syntax: table Unit.getNearestCargos(Class Self )
Description: Returns a table of friendly cargo objects indexed numerically and sorted by distance from the helicopter.

Returns nil if used on any object other than a helicopter.

Return Value: table
Return Example: A table of unit objects.
       [1] = {
           ["id_"] = 16777728,
   [2] = {
           ["id_"] = 16777984,
Examples: This could be used in a function to find the nearest ammo crate to a given helicopter:
   local cargo = Unit.getByName('whoopwhoop'):getNearestCargos
   for i = 1, cargo do
       if Object.getDesc(cargo[i]).typeName == 'ammo_cargo' then
           return cargo[i]
Related Functions: Unit Functions: isActive, getPlayerName, getID, getNumber, getController, getGroup, getCallsign, getLife, getLife0, getFuel, getAmmo, getSensors, hasSensors, getRadar, getDrawArgumentValue, getNearestCargos, enableEmission, getDescentCapacity

Object Functions: isExist, destroy, getCategory, getTypeName, getDesc, hasAttribute, getName, getPoint, getPosition, getVelocity, inAir

Coalition Object Functions: getCoalition, getCountry