Add OnAnyProduction and OnSold lua triggers

This commit is contained in:
abcdefg30
2019-03-11 19:07:54 +01:00
committed by reaperrr
parent c096fbde96
commit 2db2148310
2 changed files with 16 additions and 1 deletions

View File

@@ -147,6 +147,13 @@ namespace OpenRA.Mods.Common.Scripting
GetScriptTriggers(a).RegisterCallback(Trigger.OnProduction, func, Context);
}
[Desc("Call a function when any actor produces another actor. The callback " +
"function will be called as func(Actor producer, Actor produced, string productionType).")]
public void OnAnyProduction(LuaFunction func)
{
GetScriptTriggers(Context.World.WorldActor).RegisterCallback(Trigger.OnOtherProduction, func, Context);
}
[Desc("Call a function when this player completes all primary objectives. " +
"The callback function will be called as func(Player player).")]
public void OnPlayerWon(Player player, LuaFunction func)
@@ -456,6 +463,13 @@ namespace OpenRA.Mods.Common.Scripting
GetScriptTriggers(discovered.PlayerActor).RegisterCallback(Trigger.OnPlayerDiscovered, func, Context);
}
[Desc("Call a function when this actor is sold. The callback function " +
"will be called as func(Actor self).")]
public void OnSold(Actor a, LuaFunction func)
{
GetScriptTriggers(a).RegisterCallback(Trigger.OnSold, func, Context);
}
[Desc("Removes all triggers from this actor. " +
"Note that the removal will only take effect at the end of a tick, " +
"so you must not add new triggers at the same time that you are calling this function.")]

View File

@@ -421,7 +421,8 @@ namespace OpenRA.Mods.Common.Scripting
{
using (var a = producee.ToLuaValue(f.Context))
using (var b = produced.ToLuaValue(f.Context))
f.Function.Call(a, b).Dispose();
using (var c = productionType.ToLuaValue(f.Context))
f.Function.Call(a, b, c).Dispose();
}
catch (Exception ex)
{