From bfc34df581c622556aae9a4e0d48a95292198b21 Mon Sep 17 00:00:00 2001 From: Oliver Brakmann Date: Sat, 8 Feb 2014 16:04:29 +0100 Subject: [PATCH] Add Actor.OnDamaged Allows the AI to react to its units being attacked. --- OpenRA.Mods.RA/Scripting/LuaScriptEvents.cs | 8 +++++++- mods/common/lua/actor.lua | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.RA/Scripting/LuaScriptEvents.cs b/OpenRA.Mods.RA/Scripting/LuaScriptEvents.cs index f321920777..40b2778583 100644 --- a/OpenRA.Mods.RA/Scripting/LuaScriptEvents.cs +++ b/OpenRA.Mods.RA/Scripting/LuaScriptEvents.cs @@ -15,12 +15,13 @@ namespace OpenRA.Mods.RA.Scripting { public class LuaScriptEventsInfo : TraitInfo { } - public class LuaScriptEvents : INotifyKilled, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyCapture + public class LuaScriptEvents : INotifyKilled, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyCapture, INotifyDamage { public event Action OnKilled = (self, e) => { }; public event Action OnAddedToWorld = self => { }; public event Action OnRemovedFromWorld = self => { }; public event Action OnCaptured = (self, captor, oldOwner, newOwner) => { }; + public event Action OnDamaged = (self, e) => { }; public void Killed(Actor self, AttackInfo e) { @@ -41,5 +42,10 @@ namespace OpenRA.Mods.RA.Scripting { OnCaptured(self, captor, oldOwner, newOwner); } + + public void Damaged(Actor self, AttackInfo e) + { + OnDamaged(self, e); + } } } diff --git a/mods/common/lua/actor.lua b/mods/common/lua/actor.lua index 1eb1922ab1..613f9b927f 100644 --- a/mods/common/lua/actor.lua +++ b/mods/common/lua/actor.lua @@ -143,6 +143,10 @@ Actor.SetStance = function(actor, stance) Internal.SetUnitStance(actor, stance) end +Actor.OnDamaged = function(actor, eh) + Actor.Trait(actor, "LuaScriptEvents").OnDamaged:Add(eh) +end + Actor.OnKilled = function(actor, eh) Actor.Trait(actor, "LuaScriptEvents").OnKilled:Add(eh) end