Trying to add condition to respawn button
Hello,

I'm learning C# and I'm trying to make a plugin that enable/disable respawn button depending conditions.

private object OnServerCommand(ConsoleSystem.Arg arg)
        {
            if (arg.Args[0].ToLower() == "respawn")
            {
                if (doAllowRespawn == true) {
                    Puts("Respawn allowed.");
                    return null;
                }
                else {
                    Puts("Respawn not allowed.");
                    return false;
                }
            }
            else {
                Puts("Not respawn command.");
                return false;
            }
        }​

I tried many Arg but no one return the "respawn" value. Can you help me?
5e13a8d5b2bc5.jpg Wulf
You'd want to be using OnPlayerRespawn and such, not trying to intercept a command (which I don't think even exists). https://umod.org/documentation/games/rust#onplayerrespawn

Thank you for your answer! But I'm still stuck...

private void OnPlayerDeath(BasePlayer player, HitInfo info)
        {
            Puts("onPlayerDeath function.");
            doAllowRespawn = false;
            Puts("doAllowRespawn " + doAllowRespawn);
            ServerMgr.Instance.StartCoroutine(respawnTime());
        }

object OnPlayerRespawn(BasePlayer player)
        {
            if (doAllowRespawn == true)
            {
                Puts("Respawn allowed.");
                return null;
            }
            else
            {
                Puts("Respawn not allowed.");
                return false;
            }
        }
I don't understand why it isn't working :/
Just asking is doAllowRespawn a global variable?
Maybe if you cover the whole death screen with your own user interface.
OnPlayerRespawn actually can not be canceled. It can only be used to change the spawn point for the player.
You can use your approach of canceling the command, however you'll need to check arg.cmd.FullName instead of the first argument.
If you want to cover all ways for a player to respawn, you need to check for the commands "global.respawn" and "global.respawn_sleepingbag".

This of course will only result in the respawn buttons on the death screen not doing anything. For a better user experience I recommend to combine this with something like Zugzwang suggested above, using your own GUI (CUI) overlay to explain that they can not respawn.
5b5bc6885b278.png LaserHydra
OnPlayerRespawn actually can not be canceled. It can only be used to change the spawn point for the player.
You can use your approach of canceling the command, however you'll need to check arg.cmd.FullName instead of the first argument.
If you want to cover all ways for a player to respawn, you need to check for the commands "global.respawn" and "global.respawn_sleepingbag".

This of course will only result in the respawn buttons on the death screen not doing anything. For a better user experience I recommend to combine this with something like Zugzwang suggested above, using your own GUI (CUI) overlay to explain that they can not respawn.
Thank you for your answer, it helped me a lot, I finished the first part of my first plugin! It's working!
I learned to create a plugin, to create/manage permissions and to create a config file! I'll try to learn how to make a GUI to show time before allowed to spawn :)
Maelep
Thank you for your answer, it helped me a lot, I finished the first part of my first plugin! It's working!
I learned to create a plugin, to create/manage permissions and to create a config file! I'll try to learn how to make a GUI to show time before allowed to spawn :)

I'm glad I was able to help :)