Added DCSEx.world.getFirstPlayer function

This commit is contained in:
Ambroise Garel 2025-08-01 16:59:46 +02:00
parent 25ba1ccd2e
commit e840bc3b0d

View File

@ -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
-------------------------------------