How to check if IPlayer is gibbed in OnPlayerDeath event
Posted: Sat Feb 23, 2019 3:19 pm
Here is the relevant section of my code. Currently this is how I check if the player is gibbed by checking IPlayer.IsRemoved at the next frame. Is there a more convenient way to do this. Something like IPlayer.IsGibbed that I can check right in OnPlayerDeath event?
Code: Select all
public static class BotHelper
{
private static Events.PlayerDeathCallback m_playerDeathEvent = null;
private static Events.UpdateCallback m_updateEvent = null;
public static void Initialize()
{
m_playerDeathEvent = Events.PlayerDeathCallback.Start(OnPlayerDeath);
m_updateEvent = Events.UpdateCallback.Start(OnUpdate);
if (Game.IsEditorTest)
{
var player = Game.GetPlayers()[0];
player.Gib();
}
}
public static void OnUpdate(float elapsed)
{
OnPlayerDeathNextFrame();
}
private static bool m_updateNextFrame = false;
private static IPlayer m_deadPlayer = null;
private static void OnPlayerDeathNextFrame()
{
if (!m_updateNextFrame) return;
var isRemoved = m_deadPlayer.IsRemoved; // --> This will return true if player is rocket riding or gibbed by object
m_updateNextFrame = false;
System.Diagnostics.Debugger.Break();
}
private static void OnPlayerDeath(IPlayer player)
{
// IPlayer.IsRocketRiding doesnt work in here for some reasons.
var IsRocketRiding = new Func<IPlayer, bool>(ply => (ply.IsInMidAir && !ply.IsFalling && ply.IsDisabled));
// player.IsRemoved return false here even if being gibbed to death, have to check it at the next frame
if (player == null) return;
m_deadPlayer = player;
m_updateNextFrame = true;
}
}