1. Hello,

    At the moment in my mod I intercept players' commands "respawn" and "spectate" using the OnServerCommand() hook.

    It all works fine and with my code the player can spectate and respawn under certain conditions.

    The problem is that when a player who is spectating another player, if the second player disconnects while he is BEING spectated, the spectator is left spectating the air, unable to do anything besides reconnect to fix the issue (spectate and respawn commands throw an exception as they get intercepted - read on...). Apparently, this causes the player, who I retrieve from arg.connection.player, to have a null value as a result of which leads to the message status in the title, namely [Debug] Player is actually a BasePlayer (leads to an exception in my code as well, but that is just a symptom).

    Is this an issue that exists and has anyone else received it? Any possible reasons why this might be caused?

    Here are snippets of relevant code:
    Code:
            object OnServerCommand(ConsoleSystem.Arg arg)
            {
                if (arg.connection == null)
                {
                    return null;
                }            if (arg?.cmd?.namefull == "global.spectate") {
                    CmdSpectate(player, "", target);
                    return true;
                }            return null;
            }
    Code:
    if (!player.IsSpectating())
    {
            var target = (args.Length > 0 ? BasePlayer.Find(args[0]) : null);        //*        // Put player in spectate mode
            player.SetPlayerFlag(BasePlayer.PlayerFlags.Spectating, true);
            player.gameObject.SetLayerRecursive(10);
            player.CancelInvoke("MetabolismUpdate");
            player.CancelInvoke("InventoryUpdate");
            player.ClearEntityQueue();
            entitySnapshot.Invoke(player, new object[] { target });
            player.gameObject.Identity();
            player.SetParent(target, 0);
            player.Die();
    } else {
            Respawn(player);
    }
    //* I omitted the code which sets the target to spectate. It's essentially a custom list of players which is managed by the plugin and one of the players is picked everytime someone writes '/spectate'.

    Also note Respawn() is a custom function which again checks a certain amount of conditions and at one point calls RespawnAt(), which is built-in into the BasePlayer class. Issue is essentially somewhere else and not involved with the actual respawning.
     
  2. Wulf

    Wulf Community Admin

    Have you looked at my Spectate plugin?
     
  3. Hey Wulf, sorry for my stupidity. I used the Spectate plugin a while ago and had it ready in my local resources and checked before writing, but last time I needed it I manually removed certain bits and resultingly had the wrong contents.

    Redownloaded it and double-checked, got a working solution now, all set!