From c93dc1424cbbfe301b17b5a63dc8ad422dcae4a0 Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Sat, 13 Apr 2019 13:11:53 +0200 Subject: [PATCH] Throw a LuaException when placing a beacon without the player trait --- OpenRA.Mods.Common/Scripting/Global/BeaconGlobal.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/OpenRA.Mods.Common/Scripting/Global/BeaconGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/BeaconGlobal.cs index 7afcdfba1d..1274bfbef4 100644 --- a/OpenRA.Mods.Common/Scripting/Global/BeaconGlobal.cs +++ b/OpenRA.Mods.Common/Scripting/Global/BeaconGlobal.cs @@ -9,6 +9,7 @@ */ #endregion +using Eluant; using OpenRA.Mods.Common.Effects; using OpenRA.Mods.Common.Traits; using OpenRA.Scripting; @@ -20,16 +21,21 @@ namespace OpenRA.Mods.Common.Scripting { readonly RadarPings radarPings; - public BeaconGlobal(ScriptContext context) : base(context) + public BeaconGlobal(ScriptContext context) + : base(context) { radarPings = context.World.WorldActor.TraitOrDefault(); } [Desc("Creates a new beacon that stays for the specified time at the specified WPos. " + - "Does not remove player set beacons, nor gets removed by placing them.")] + "Does not remove player set beacons, nor gets removed by placing them. " + + "Requires the 'PlaceBeacon' trait on the player actor.")] public Beacon New(Player owner, WPos position, int duration = 30 * 25, bool showRadarPings = true) { - var beacon = owner.PlayerActor.Info.TraitInfo(); + var beacon = owner.PlayerActor.Info.TraitInfoOrDefault(); + if (beacon == null) + throw new LuaException("The player actor has no 'PlaceBeacon' trait."); + var playerBeacon = new Beacon(owner, position, duration, beacon.Palette, beacon.IsPlayerPalette, beacon.BeaconImage, beacon.BeaconSequence, beacon.ArrowSequence, beacon.CircleSequence);