Code: Select all
//Throws script exception and corpse gets removed on first try only
public void OnStartup() {
Events.PlayerDeathCallback.Start((deadPlayer) => {
if (deadPlayer != null ) deadPlayer.Gib();
});
}
Code: Select all
--- Exception ---
Object reference not set to an instance of an object.
at ScriptEngine.Sandbox.ExecuteInstanceMethodInScript.Run(Boolean debuggingScript, Action callback, MethodInfo methodInfo, Object classInstanceObject, Object[] parameters)
at SFD.GameWorld.RunScriptCallbacks[T](Func`2 handleCallback)
Also, I made some extra tests to check a few things, hope it helps
Code: Select all
//Gives script exception on first try but corpses are getting removed correctly
public void OnStartup() {
Events.PlayerDeathCallback.Start((deadPlayer) =>
Events.UpdateCallback.Start((t) => {
if (deadPlayer != null) deadPlayer.Gib(); }, 100, 1)
);
}
//This approach works
public void OnStartup() {
Events.PlayerDeathCallback.Start((deadPlayer) => {
if (deadPlayer != null)
deadPlayer.SetWorldPosition(new Vector2(0, Game.GetWorldBottom()));
});
}