diff --git a/Script/DCS extensions/World.lua b/Script/DCS extensions/World.lua index 2fe63d2..982e716 100644 --- a/Script/DCS extensions/World.lua +++ b/Script/DCS extensions/World.lua @@ -10,6 +10,7 @@ -- DCSEx.world.getClosestPointOnRoadsVec2(vec2) -- DCSEx.world.getCoordinatesAsString(point, hideElevation) -- DCSEx.world.getCurrentMarkerID() +-- DCSEx.world.getFirstPlayer(side) -- DCSEx.world.getGroupByID(groupID) -- DCSEx.world.getGroupCenter(group) -- DCSEx.world.getMarkerByText(text, coalition) @@ -232,6 +233,24 @@ do return nextMarkerId - 1 end + ------------------------------------- + -- Returns the first player found + ------------------------------------- + -- @param side The coalition the player must belong to, or nil to search for any player + -- @return A player unit object, or nil if no player was found + ------------------------------------- + function DCSEx.world.getFirstPlayer(side) + local players = {} + if side then + players = coalition.getPlayers(side) + else + players = DCSEx.world.getAllPlayers() + end + + if not players or #players == 0 then return nil end + return players[1] + end + ------------------------------------- -- Searches and return a group by its ID -------------------------------------