Dear forum users! In compliance with the new European GDPR regulations, we'd just like to inform you that if you have an account, your email address is stored in our database. We do not share your information with third parties, and your email address and password are encrypted for security reasons.

New to the forum? Say hello in this topic! Also make sure to read the rules.

How to check if IPlayer is gibbed in OnPlayerDeath event

Here you can find answered ScriptAPI topics.
Forum rules
By using the forum you agree to the following rules.
Post Reply
NearHuscarl
Superfighter
Superfighter
Posts: 97
Joined: Thu Feb 07, 2019 4:36 am

How to check if IPlayer is gibbed in OnPlayerDeath event

Post by NearHuscarl » 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;
            }
        }
0 x
Image

User avatar
Gurt
Lead Programmer
Lead Programmer
Posts: 1884
Joined: Sun Feb 28, 2016 3:22 pm
Title: Lead programmer
Started SFD: Made it!
Location: Sweden
Gender:
Age: 34

Post by Gurt » Sat Feb 23, 2019 3:44 pm

A gibbed player is also a removed player and a removed player doesn't carry any information what so ever because the player instance does no longer exist. Note that the OnPlayerDeath event is run when the player is killed (dies) and also when the player is removed (falling outside the map or being gibbed for example).
Note that there exist a IPlayer.IsRocketRiding property if you want to check rocket riding explicitly.
0 x
Gurt

NearHuscarl
Superfighter
Superfighter
Posts: 97
Joined: Thu Feb 07, 2019 4:36 am

Post by NearHuscarl » Sat Feb 23, 2019 4:39 pm

Gurt wrote:
Sat Feb 23, 2019 3:44 pm
A gibbed player is also a removed player and a removed player doesn't carry any information what so ever because the player instance does no longer exist. Note that the OnPlayerDeath event is run when the player is killed (dies) and also when the player is removed (falling outside the map or being gibbed for example).
Note that there exist a IPlayer.IsRocketRiding property if you want to check rocket riding explicitly.
I am aware of IPlayer.IsRocketRiding. But it's not working in the above code if called in OnPlayerDeath method as I have already commented the alternative method. But anyway, I also need to check if the player is gibbed by other objects too so IPlayer.IsRemoved would work better (but need to wait until next frame to confirm if the body still exist in the map). Thanks for your clarification.
0 x
Image

User avatar
Sree
Superfighter
Superfighter
Posts: 325
Joined: Sun May 08, 2016 8:19 pm
SFD Account: phasmic
SFD Alias: sree
Gender:
Age: 23

Post by Sree » Sat Feb 23, 2019 8:33 pm

NearHuscarl wrote:
Sat Feb 23, 2019 4:39 pm
I also need to check if the player is gibbed by other objects too so IPlayer.IsRemoved would work better
Gurt wrote:
Sat Feb 23, 2019 3:44 pm
A gibbed player is also a removed player and a removed player doesn't carry any information what so ever because the player instance does no longer exist.
you could just check for null to know whether a player is gibbed
0 x

Post Reply