Fallback to normal difficulty when none is set.

This commit is contained in:
Matthias Mailänder
2022-09-10 21:36:05 +02:00
committed by Gustas
parent b30285e38d
commit 0fb5853b7a
4 changed files with 15 additions and 3 deletions

View File

@@ -120,6 +120,18 @@ namespace OpenRA.Mods.Common.Scripting
return option.Value; return option.Value;
} }
[Desc("Returns the value of a `ScriptLobbyDropdown` selected in the game lobby or fallback to a default value.")]
public LuaValue LobbyOptionOrDefault(string id, string fallback)
{
var option = Context.World.WorldActor.TraitsImplementing<ScriptLobbyDropdown>()
.FirstOrDefault(sld => sld.Info.ID == id);
if (option == null)
return fallback;
return option.Value;
}
[Desc("Returns a table of all the actors that were specified in the map file.")] [Desc("Returns a table of all the actors that were specified in the map file.")]
public Actor[] NamedActors => sma.Actors.Values.ToArray(); public Actor[] NamedActors => sma.Actors.Values.ToArray();

View File

@@ -7,7 +7,7 @@
information, see COPYING. information, see COPYING.
]] ]]
Difficulty = Map.LobbyOption("difficulty") Difficulty = Map.LobbyOptionOrDefault("difficulty", "normal")
InitObjectives = function(player) InitObjectives = function(player)
Trigger.OnObjectiveCompleted(player, function(p, id) Trigger.OnObjectiveCompleted(player, function(p, id)

View File

@@ -7,7 +7,7 @@
information, see COPYING. information, see COPYING.
]] ]]
Difficulty = Map.LobbyOption("difficulty") Difficulty = Map.LobbyOptionOrDefault("difficulty", "normal")
InitObjectives = function(player) InitObjectives = function(player)
Trigger.OnObjectiveCompleted(player, function(p, id) Trigger.OnObjectiveCompleted(player, function(p, id)

View File

@@ -7,7 +7,7 @@
information, see COPYING. information, see COPYING.
]] ]]
Difficulty = Map.LobbyOption("difficulty") Difficulty = Map.LobbyOptionOrDefault("difficulty", "normal")
InitObjectives = function(player) InitObjectives = function(player)
Trigger.OnObjectiveCompleted(player, function(p, id) Trigger.OnObjectiveCompleted(player, function(p, id)