From e840bc3b0d02d1b079d0579dc6cad9e810ac8816 Mon Sep 17 00:00:00 2001 From: Ambroise Garel <47314805+akaAgar@users.noreply.github.com> Date: Fri, 1 Aug 2025 16:59:46 +0200 Subject: [PATCH] Added DCSEx.world.getFirstPlayer function --- Script/DCS extensions/World.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 -------------------------------------