From d062523700b9faf25ad37e941b2e78859d27f921 Mon Sep 17 00:00:00 2001 From: Mustafa Alperen Seki Date: Thu, 2 Aug 2018 17:40:00 +0300 Subject: [PATCH] Add GetActorsByTypes. --- .../Scripting/Properties/PlayerProperties.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/OpenRA.Mods.Common/Scripting/Properties/PlayerProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/PlayerProperties.cs index 62751e816c..04b8a62d6a 100644 --- a/OpenRA.Mods.Common/Scripting/Properties/PlayerProperties.cs +++ b/OpenRA.Mods.Common/Scripting/Properties/PlayerProperties.cs @@ -87,6 +87,21 @@ namespace OpenRA.Mods.Common.Scripting return result.ToArray(); } + [Desc("Returns all living actors of the specified types of this player.")] + public Actor[] GetActorsByTypes(string[] types) + { + var result = new List(); + + foreach (var type in types) + if (!Context.World.Map.Rules.Actors.ContainsKey(type)) + throw new LuaException("Unknown actor type '{0}'".F(type)); + + result.AddRange(Player.World.Actors + .Where(actor => actor.Owner == Player && !actor.IsDead && actor.IsInWorld && types.Contains(actor.Info.Name))); + + return result.ToArray(); + } + [Desc("Check if the player has these prerequisites available.")] public bool HasPrerequisites(string[] type) {