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 do i recover from DeathKneelInfinite?

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 do i recover from DeathKneelInfinite?

Post by NearHuscarl » Mon Aug 12, 2019 10:38 am

StopDeathKneel, StopAll command or ClearCommandQueue doesn't work at all

EDIT: I think the reason the mecha boss in the campaign map can stop kneeling is because you call IPlayer.Kill() which
is undesirable in my situation, I want to keep the player alive

Code: Select all

        private IPlayer player;
        public void OnStartup()
        {
            player = Game.GetPlayers()[0];

            player.SetInputEnabled(false);
            player.AddCommand(new PlayerCommand(PlayerCommandType.DeathKneelInfinite));

            Events.UpdateCallback.Start(OnUpdate);
        }

        private float m_kneelTimer = 0;
        private void OnUpdate(float dt)
        {
            if (m_kneelTimer != -1)
                m_kneelTimer += dt;

            if (m_kneelTimer >= 3000)
            {
                Game.ShowChatMessage("Stop kneeling");

                player.AddCommand(new PlayerCommand(PlayerCommandType.StopDeathKneel));
                //player.AddCommand(new PlayerCommand(PlayerCommandType.StopAll));
                //player.ClearCommandQueue();
                player.SetInputEnabled(true);
                m_kneelTimer = -1;
            }
        }
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 » Mon Aug 12, 2019 12:47 pm

Any commands added are actually processed the next update cycle (or if it was at the end of the current update cycle). So when you're calling
player.AddCommand(new PlayerCommand(PlayerCommandType.StopDeathKneel));
it won't be processed straight away. But as you also call
player.SetInputEnabled(true);
the commands will be ignored once they do get processed ;)

This might not be super intuitive when writing code so I'm tweaking the processing of commands to also process one additional update cycle after the player gets back control to simplify coding. Which will make the last command added work as expected when writing code like this:
player.AddCommand(new PlayerCommand(PlayerCommandType.StopDeathKneel));
player.SetInputEnabled(true);


If you don't want to wait around for the next update simply delay your player.SetInputEnalbed(true) to the next update cycle which you can do in an update event.
Events.UpdateCallback.Start((t) => {
player.SetInputEnabled(true);
}, 1, 1);

so the working code will look like this:

Code: Select all

	    private IPlayer player;
        public void OnStartup()
        {
            player = Game.GetPlayers()[0];

            player.SetInputEnabled(false);
            player.AddCommand(new PlayerCommand(PlayerCommandType.DeathKneelInfinite));

            Events.UpdateCallback.Start(OnUpdate);
        }

        private float m_kneelTimer = 0;
        private void OnUpdate(float dt)
        {
            if (m_kneelTimer != -1)
                m_kneelTimer += dt;

            if (m_kneelTimer >= 3000)
            {
                Game.ShowChatMessage("Stop kneeling");

                player.AddCommand(new PlayerCommand(PlayerCommandType.StopDeathKneel));
                //player.AddCommand(new PlayerCommand(PlayerCommandType.StopAll));
                //player.ClearCommandQueue();
				
                // Enable player input the next update to allow the StopDeathKneel command to run.
                Events.UpdateCallback.Start((t) => {
                       player.SetInputEnabled(true);
                }, 1, 1);
                m_kneelTimer = -1;
            }
        }
1 x
Gurt

Post Reply