diff --git a/OpenRA.Mods.RA/Guard.cs b/OpenRA.Mods.RA/Guard.cs index 9014c2baf2..7fc5e7e9ee 100644 --- a/OpenRA.Mods.RA/Guard.cs +++ b/OpenRA.Mods.RA/Guard.cs @@ -27,13 +27,19 @@ namespace OpenRA.Mods.RA if (order.OrderString == "Guard") { var target = Target.FromActor(order.TargetActor); - self.SetTargetLine(target, Color.Yellow); - var range = WRange.FromCells(target.Actor.Info.Traits.Get().Range); - self.QueueActivity(false, new AttackMove.AttackMoveActivity(self, self.Trait().MoveFollow(self, target, range))); + GuardTarget(self, target); } } + public void GuardTarget(Actor self, Target target) + { + self.SetTargetLine(target, Color.Yellow); + + var range = WRange.FromCells(target.Actor.Info.Traits.Get().Range); + self.QueueActivity(false, new AttackMove.AttackMoveActivity(self, self.Trait().MoveFollow(self, target, range))); + } + public string VoicePhraseForOrder(Actor self, Order order) { return order.OrderString == "Guard" ? "Move" : null; @@ -100,4 +106,4 @@ namespace OpenRA.Mods.RA } class Guardable { } -} \ No newline at end of file +} diff --git a/OpenRA.Mods.RA/Scripting/LuaScriptInterface.cs b/OpenRA.Mods.RA/Scripting/LuaScriptInterface.cs index 1861c770cb..10fab7b688 100644 --- a/OpenRA.Mods.RA/Scripting/LuaScriptInterface.cs +++ b/OpenRA.Mods.RA/Scripting/LuaScriptInterface.cs @@ -372,5 +372,17 @@ namespace OpenRA.Mods.RA.Scripting factory.Trait().ResolveOrder(factory, Order.StartProduction(factory, unit, (int)amount)); } + + [LuaGlobal] + public void Guard(Actor guard, Actor target) + { + if (target.HasTrait()) + { + var gt = guard.TraitOrDefault(); + + if (gt != null) + gt.GuardTarget(guard, Target.FromActor(target)); + } + } } } diff --git a/mods/common/lua/actor.lua b/mods/common/lua/actor.lua index 613f9b927f..a0aca22213 100644 --- a/mods/common/lua/actor.lua +++ b/mods/common/lua/actor.lua @@ -187,6 +187,10 @@ Actor.ReturnToBase = function(actor, airfield) actor:QueueActivity(OpenRA.New("ReturnToBase", { actor, airfield })) end +Actor.Guard = function(actor, target) + Internal.Guard(actor, target) +end + Actor.Patrol = function(actor, waypoints, wait, loop) Utils.Do(waypoints, function(wpt) Actor.AttackMove(actor, wpt.Location, 3)