Fix OnAllRemovedFromWorld only triggering once
This commit is contained in:
@@ -211,8 +211,27 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (!group.Any())
|
if (!group.Any())
|
||||||
using (f)
|
{
|
||||||
f.Call().Dispose();
|
// Functions can only be .Call()ed once, so operate on a copy so we can reuse it later
|
||||||
|
var temp = (LuaFunction)f.CopyReference();
|
||||||
|
using (temp)
|
||||||
|
temp.Call().Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Context.FatalError(e.Message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Action<Actor> onMemberAdded = m =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!actors.Contains(m) || group.Contains(m))
|
||||||
|
return;
|
||||||
|
|
||||||
|
group.Add(m);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -221,7 +240,10 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
};
|
};
|
||||||
|
|
||||||
foreach (var a in group)
|
foreach (var a in group)
|
||||||
|
{
|
||||||
GetScriptTriggers(a).OnRemovedInternal += onMemberRemoved;
|
GetScriptTriggers(a).OnRemovedInternal += onMemberRemoved;
|
||||||
|
GetScriptTriggers(a).OnAddedInternal += onMemberAdded;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Desc("Call a function when this actor is captured. The callback function " +
|
[Desc("Call a function when this actor is captured. The callback function " +
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
public event Action<Actor> OnKilledInternal = _ => { };
|
public event Action<Actor> OnKilledInternal = _ => { };
|
||||||
public event Action<Actor> OnCapturedInternal = _ => { };
|
public event Action<Actor> OnCapturedInternal = _ => { };
|
||||||
public event Action<Actor> OnRemovedInternal = _ => { };
|
public event Action<Actor> OnRemovedInternal = _ => { };
|
||||||
|
public event Action<Actor> OnAddedInternal = _ => { };
|
||||||
public event Action<Actor, Actor> OnProducedInternal = (a, b) => { };
|
public event Action<Actor, Actor> OnProducedInternal = (a, b) => { };
|
||||||
public event Action<Actor, Actor> OnOtherProducedInternal = (a, b) => { };
|
public event Action<Actor, Actor> OnOtherProducedInternal = (a, b) => { };
|
||||||
|
|
||||||
@@ -340,6 +341,9 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run any internally bound callbacks
|
||||||
|
OnAddedInternal(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyRemovedFromWorld.RemovedFromWorld(Actor self)
|
void INotifyRemovedFromWorld.RemovedFromWorld(Actor self)
|
||||||
|
|||||||
Reference in New Issue
Block a user