• Хостинг игровых серверов

    Максимальная производительность для ваших игровых серверов!

    Заказать сейчас

Помогите Проблема с кодом

schwf3xlr

22 Фев 2022
36
1
0
C#:
using Oxide.Game.Rust.Cui;
using System.Collections.Generic;

namespace Oxide.Plugins {
      [Info("Health Bar", "Obkurenniy", "1.0")]

    class HealthBar : RustPlugin
    {
        
        class GuiControl
        {
            private Dictionary<BasePlayer, Timer> _Timers = new Dictionary<BasePlayer, Timer>();
            private readonly PluginTimers timer;
            private readonly float destroySeconds;

            public GuiControl(PluginTimers timer, float destroySeconds)
            {
                this._Timer = timer;
                this._DestroySeconds = destroySeconds;
            }

            public void TriggerDamage(BasePlayer player, float health, float maxHealth)
            {
                RemovePlayer(player);
                var progress = health / maxHealth + "";
                var healthText = (int)health + "";
                DrawUI(player, progressText, healthText);
                AddPlayer(player);
            }
            
            public void TriggerDeath(BasePlayer player)
            {
                RemovePlayer(player);
                var progress = "0";
                var healthText = "Убит";
                DrawUI(player, progressText, healthText);
                AddPlayer(player);
            }

            void AddPlayer(BasePlayer player)
            {
                _Timers[player] = _Timer.Once(_DestroySeconds, () =>
                {
                    RemovePlayer(player);
                });
            }

            void RemovePlayer(BasePlayer player)
            {
                Timer pTimer;
                if(_Timers.TryGetValue(player, out pTimer))
                {
                   _Timer.Destroy(ref pTimer);
                   DestroyUI(player);
                   _Timers.Remove(player);
                }
            }

            void DrawUI(BasePlayer player, string progress, string text)
            {
                string json = CUI_MAIN
                .Replace("{progress}", progress)
                .Replace("{text}", text);
                CuiHelper.AddUi(player, json);
            }

            void DestroyUI(BasePlayer player)
            {
                CuiHelper.DestroyUi(player, "hpbar_background");
            }
        }

        GuiControl _GuiControl;

        void Loaded()
        {
           _GuiControl = new GuiControl(timer, 5f);
        }

        void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
        {
            var player = info.InitiatorPlayer;
            if (player && player.IsAlive())
            {
                NextTick(() =>
                {
                    if (entity.IsAlive() && player?.IsConnected == true)
                    {
                        var health = entity.health;
                        var maxHealth = entity.MaxHealth();

                        var progress = health / maxHealth;
                        var text = (int) health;
                        _GuiControl.TriggerDamage(player, health, maxHealth);
                    }

                });
            }
        }

        void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
            var player = info.InitiatorPlayer;
            if (player && player.IsAlive())
            {
                _GuiControl.TriggerDeath(player);
            }
        }

        [ChatCommand("testgui")]
        void cmdChatTestGui(BasePlayer player)
        {
            string json = CUI_MAIN
            .Replace("{progress}", "0.5")
            .Replace("{text}", "50");

            CuiHelper.AddUi(player, json);
            timer.Once(10f, () => {
                CuiHelper.DestroyUi(player, "hpbar_background");
            });
        }

            string CUI_MAIN = @"
            [
  {
    ""name"": ""hpbar_background"",
    ""parent"": ""Overlay"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""material"": """",
        ""color"": ""0.5254902 0.5254902 0.5254902 0.2980392""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0.5 0"",
        ""anchormax"": ""0.5 0"",
        ""offsetmin"": ""-106 86"",
        ""offsetmax"": ""86 112""
      }
    ]
  },
  {
    ""name"": ""hpbar_img"",
    ""parent"": ""hpbar_background"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""sprite"": ""assets/icons/health.png"",
        ""material"": ""assets/icons/iconmaterial.mat"",
        ""color"": ""0.9686275 0.9176471 0.8784314 0.6745098""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""0 1"",
        ""offsetmin"": ""4 4"",
        ""offsetmax"": ""22 -4""
      }
    ]
  },
  {
    ""name"": ""hpbar_wrapper"",
    ""parent"": ""hpbar_background"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""material"": """",
        ""color"": ""1 0.4039216 0.4039216 0""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""1 1"",
        ""offsetmin"": ""25 3"",
        ""offsetmax"": ""-3 -3""
      }
    ]
  },
  {
    ""name"": ""hpbar_progress"",
    ""parent"": ""hpbar_wrapper"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""sprite"": ""assets/content/ui/ui.background.tile.psd"",
        ""material"": """",
        ""color"": ""0.6941177 0.2039216 0.003921569 0.5450981""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""{progress} 1"",
        ""offsetmin"": ""0 0"",
        ""offsetmax"": ""0 0""
      }
    ]
  },
  {
    ""name"": ""hpbar_text"",
    ""parent"": ""hpbar_wrapper"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Text"",
        ""text"": ""{text}"",
        ""fontSize"": 15,
        ""font"": ""robotocondensed-bold.ttf"",
        ""align"": ""MiddleLeft"",
        ""color"": ""0.9686275 0.9176471 0.8784314 0.8945568""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""1 1"",
        ""offsetmin"": ""2 0"",
        ""offsetmax"": ""0 0""
      }
    ]
  }
]
        ";

    }
}

Error while compiling: HealthBar.cs(63,31): error CS0038: Cannot access a nonstatic member of outer type `Oxide.Plugins.HealthBar' via nested type `Oxide.Plugins.HealthBar.GuiControl'

Если запенить
public GuiControl(PluginTimers timer, float destroySeconds)
{
this._Timer = timer;
this._DestroySeconds = destroySeconds;
}
на
public GuiControl(HealthBar plugin, PluginTimers timer, float destroySeconds)
{
this._Plugin = plugin;
this._Timer = timer;
this._DestroySeconds = destroySeconds;
}
Тогда будет проблема с 2 аргументами
 
Ошибка заключается в том, что вы используете переменную this.timer, которая не определена в классе HealthBar. В классе HealthBar нет такой переменной, но есть переменная timer, объявленная в базовом классе RustPlugin.

Измените эту строку на RustPlugin.timer:

Код:
void Loaded()
{
    _GuiControl = new GuiControl(RustPlugin.timer, 5f);
}

Теперь код должен быть успешно скомпилирован.
C#:
using System.Collections.Generic;
using Oxide.Game.Rust.Cui;

namespace Oxide.Plugins
{
    [Info ("Health Bar", "Raskolov", "0.1.0")]

    class HealthBar : RustPlugin
    {

        public class GuiControl
        {
            private Dictionary<BasePlayer, Timer> _Timers = new Dictionary<BasePlayer, Timer>();

            private readonly PluginTimers _Timer;
            private readonly float destroySeconds;

            public GuiControl(PluginTimers timer, float destroySeconds)
            {
                this._Timer = timer;
                this._DestroySeconds = destroySeconds;
            }

            public void TriggerDamage(BasePlayer player, float health, float maxHelth)
            {
                RemovePlayer(player);
                var progressText = health / maxHelth + "";
                var healthText = (int)health + "";
                DrawUI(player, progressText, healthText);
                AddPlayer(player);
            }

            public void TriggerDeath(BasePlayer player)
            {
                RemovePlayer(player);
                var progressText = "0";
                var healthText = "Убит!";
                DrawUI(player, progressText, healthText);
                AddPlayer(player);
            }

            void AddPlayer(BasePlayer player)
            {
                _Timers[player] = _Timer.Once(_DestroySeconds, () =>
                {
                    RemovePlayer(player);
                });
            }

            void RemovePlayer(BasePlayer player)
            {
                Timer pTimer;
                if (_Timers.TryGetValue(player, out pTimer))
                {
                    _Timer.Destroy(ref pTimer);
                    DestroyUI(player);
                    _Timers.Remove(player);
                }
            }

            void DrawUI (BasePlayer player, string progress, string text)
            {
                string json = CUI_MAIN
                    .Replace("{progress}", progress)
                    .Replace("{text}", text);
                CuiHelper.AddUi(player, json);
            }

            void DestroyUI(BasePlayer player)
            {
                CuiHelper.DestroyUi(player, "hpbar_background");
            }
        }

        GuiControl _GuiControl;

        void Loaded()
        {
            _GuiControl = new GuiControl(RustPlugin.timer, 5f);
        }

        void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
        {
           var player = info.InitiatorPlayer;
           if (player && player.IsAlive())
           {
               NextTick(() =>
               {
                   if (entity.IsAlive() && player?.IsConnected == true)
                   {
                      var health = entity.health;
                      var maxHelth = entity.MaxHealth();

                      _GuiControl.TriggerDamage(player, health, maxHelth);
                   }
               });
           }
        }

        void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
           var player = info.InitiatorPlayer;
           if (player && player.IsAlive())
           {
              _GuiControl.TriggerDeath(player);
           }
        }

        [ChatCommand("gui")]
        void cmdChatGui(BasePlayer player)
        {
            string json = CUI_MAIN
                .Replace("{progress}", "0.5")
                .Replace("{text}", "50");

            CuiHelper.AddUi(player, json);
            timer.Once(5f, () =>
            {
                CuiHelper.DestroyUi(player, "hpbar_background");
            });
        }

        string CUI_MAIN = @"
            [
  {
    ""name"": ""hpbar_background"",
    ""parent"": ""Overlay"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""material"": """",
        ""color"": ""0.5254902 0.5254902 0.5254902 0.2980392""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0.5 0"",
        ""anchormax"": ""0.5 0"",
        ""offsetmin"": ""-106 86"",
        ""offsetmax"": ""86 112""
      }
    ]
  },
  {
    ""name"": ""hpbar_img"",
    ""parent"": ""hpbar_background"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""sprite"": ""assets/icons/health.png"",
        ""material"": ""assets/icons/iconmaterial.mat"",
        ""color"": ""0.9686275 0.9176471 0.8784314 0.6745098""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""0 1"",
        ""offsetmin"": ""4 4"",
        ""offsetmax"": ""22 -4""
      }
    ]
  },
  {
    ""name"": ""hpbar_wrapper"",
    ""parent"": ""hpbar_background"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""material"": """",
        ""color"": ""1 0.4039216 0.4039216 0""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""1 1"",
        ""offsetmin"": ""25 3"",
        ""offsetmax"": ""-3 -3""
      }
    ]
  },
  {
    ""name"": ""hpbar_progress"",
    ""parent"": ""hpbar_wrapper"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""sprite"": ""assets/content/ui/ui.background.tile.psd"",
        ""material"": """",
        ""color"": ""0.6941177 0.2039216 0.003921569 0.5450981""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""{progress} 1"",
        ""offsetmin"": ""0 0"",
        ""offsetmax"": ""0 0""
      }
    ]
  },
  {
    ""name"": ""hpbar_text"",
    ""parent"": ""hpbar_wrapper"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Text"",
        ""text"": ""{text}"",
        ""fontSize"": 15,
        ""font"": ""robotocondensed-bold.ttf"",
        ""align"": ""MiddleLeft"",
        ""color"": ""0.9686275 0.9176471 0.8784314 0.8945568""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""1 1"",
        ""offsetmin"": ""2 0"",
        ""offsetmax"": ""0 0""
      }
    ]
  }
]
        ";
    }
}

Error while compiling: HealthBar.cs(81,53): error CS0120: An object reference is required to access non-static member `Oxide.Plugins.CSharpPlugin.timer'
 
C#:
using System.Collections.Generic;
using Oxide.Game.Rust.Cui;

namespace Oxide.Plugins
{
    [Info ("Health Bar", "Raskolov", "0.1.0")]

    class HealthBar : RustPlugin
    {

        public class GuiControl
        {
            private Dictionary<BasePlayer, Timer> _Timers = new Dictionary<BasePlayer, Timer>();

            private readonly PluginTimers _Timer;
            private readonly float destroySeconds;

            public GuiControl(PluginTimers timer, float destroySeconds)
            {
                this._Timer = timer;
                this._DestroySeconds = destroySeconds;
            }

            public void TriggerDamage(BasePlayer player, float health, float maxHelth)
            {
                RemovePlayer(player);
                var progressText = health / maxHelth + "";
                var healthText = (int)health + "";
                DrawUI(player, progressText, healthText);
                AddPlayer(player);
            }

            public void TriggerDeath(BasePlayer player)
            {
                RemovePlayer(player);
                var progressText = "0";
                var healthText = "Убит!";
                DrawUI(player, progressText, healthText);
                AddPlayer(player);
            }

            void AddPlayer(BasePlayer player)
            {
                _Timers[player] = _Timer.Once(_DestroySeconds, () =>
                {
                    RemovePlayer(player);
                });
            }

            void RemovePlayer(BasePlayer player)
            {
                Timer pTimer;
                if (_Timers.TryGetValue(player, out pTimer))
                {
                    _Timer.Destroy(ref pTimer);
                    DestroyUI(player);
                    _Timers.Remove(player);
                }
            }

            void DrawUI (BasePlayer player, string progress, string text)
            {
                string json = CUI_MAIN
                    .Replace("{progress}", progress)
                    .Replace("{text}", text);
                CuiHelper.AddUi(player, json);
            }

            void DestroyUI(BasePlayer player)
            {
                CuiHelper.DestroyUi(player, "hpbar_background");
            }
        }

        GuiControl _GuiControl;

        void Loaded()
        {
            _GuiControl = new GuiControl(RustPlugin.timer, 5f);
        }

        void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
        {
           var player = info.InitiatorPlayer;
           if (player && player.IsAlive())
           {
               NextTick(() =>
               {
                   if (entity.IsAlive() && player?.IsConnected == true)
                   {
                      var health = entity.health;
                      var maxHelth = entity.MaxHealth();

                      _GuiControl.TriggerDamage(player, health, maxHelth);
                   }
               });
           }
        }

        void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
           var player = info.InitiatorPlayer;
           if (player && player.IsAlive())
           {
              _GuiControl.TriggerDeath(player);
           }
        }

        [ChatCommand("gui")]
        void cmdChatGui(BasePlayer player)
        {
            string json = CUI_MAIN
                .Replace("{progress}", "0.5")
                .Replace("{text}", "50");

            CuiHelper.AddUi(player, json);
            timer.Once(5f, () =>
            {
                CuiHelper.DestroyUi(player, "hpbar_background");
            });
        }

        string CUI_MAIN = @"
            [
  {
    ""name"": ""hpbar_background"",
    ""parent"": ""Overlay"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""material"": """",
        ""color"": ""0.5254902 0.5254902 0.5254902 0.2980392""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0.5 0"",
        ""anchormax"": ""0.5 0"",
        ""offsetmin"": ""-106 86"",
        ""offsetmax"": ""86 112""
      }
    ]
  },
  {
    ""name"": ""hpbar_img"",
    ""parent"": ""hpbar_background"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""sprite"": ""assets/icons/health.png"",
        ""material"": ""assets/icons/iconmaterial.mat"",
        ""color"": ""0.9686275 0.9176471 0.8784314 0.6745098""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""0 1"",
        ""offsetmin"": ""4 4"",
        ""offsetmax"": ""22 -4""
      }
    ]
  },
  {
    ""name"": ""hpbar_wrapper"",
    ""parent"": ""hpbar_background"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""material"": """",
        ""color"": ""1 0.4039216 0.4039216 0""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""1 1"",
        ""offsetmin"": ""25 3"",
        ""offsetmax"": ""-3 -3""
      }
    ]
  },
  {
    ""name"": ""hpbar_progress"",
    ""parent"": ""hpbar_wrapper"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""sprite"": ""assets/content/ui/ui.background.tile.psd"",
        ""material"": """",
        ""color"": ""0.6941177 0.2039216 0.003921569 0.5450981""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""{progress} 1"",
        ""offsetmin"": ""0 0"",
        ""offsetmax"": ""0 0""
      }
    ]
  },
  {
    ""name"": ""hpbar_text"",
    ""parent"": ""hpbar_wrapper"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Text"",
        ""text"": ""{text}"",
        ""fontSize"": 15,
        ""font"": ""robotocondensed-bold.ttf"",
        ""align"": ""MiddleLeft"",
        ""color"": ""0.9686275 0.9176471 0.8784314 0.8945568""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""1 1"",
        ""offsetmin"": ""2 0"",
        ""offsetmax"": ""0 0""
      }
    ]
  }
]
        ";
    }
}

Error while compiling: HealthBar.cs(81,53): error CS0120: An object reference is required to access non-static member `Oxide.Plugins.CSharpPlugin.timer'
Ошибка заключается в том, что переменная timer не является статической, поэтому ее нельзя использовать в статическом контексте метода cmdChatGui.

Чтобы исправить эту ошибку, вы можете создать новую переменную timer в методе Loaded и использовать ее вместо базовой переменной RustPlugin.timer.

Код:
GuiControl _GuiControl;
        PluginTimers timer; // добавить новую переменную
        void Loaded()
        {
            timer = RustPlugin.timer; // присвоить значение базовой переменной
            _GuiControl = new GuiControl(timer, 5f);
        }
        [ChatCommand("gui")]
        void cmdChatGui(BasePlayer player)
        {
            string json = CUI_MAIN
                .Replace("{progress}", "0.5")
                .Replace("{text}", "50");
            CuiHelper.AddUi(player, json);
            timer.Once(5f, () =>
            {
                CuiHelper.DestroyUi(player, "hpbar_background");
            });
        }

Теперь код должен успешно скомпилироваться.
 

Ошибка заключается в том, что переменная timer не является статической, поэтому ее нельзя использовать в статическом контексте метода cmdChatGui.

Чтобы исправить эту ошибку, вы можете создать новую переменную timer в методе Loaded и использовать ее вместо базовой переменной RustPlugin.timer.

Код:
GuiControl _GuiControl;
        PluginTimers timer; // добавить новую переменную
        void Loaded()
        {
            timer = RustPlugin.timer; // присвоить значение базовой переменной
            _GuiControl = new GuiControl(timer, 5f);
        }
        [ChatCommand("gui")]
        void cmdChatGui(BasePlayer player)
        {
            string json = CUI_MAIN
                .Replace("{progress}", "0.5")
                .Replace("{text}", "50");
            CuiHelper.AddUi(player, json);
            timer.Once(5f, () =>
            {
                CuiHelper.DestroyUi(player, "hpbar_background");
            });
        }

Теперь код должен успешно скомпилироваться.
C#:
using System.Collections.Generic;
using Oxide.Game.Rust.Cui;

namespace Oxide.Plugins
{
    [Info ("Health Bar", "Raskolov", "0.1.0")]

    class HealthBar : RustPlugin
    {

        public class GuiControl
        {
            private Dictionary<BasePlayer, Timer> _Timers = new Dictionary<BasePlayer, Timer>();

            private readonly PluginTimers _Timer;
            private readonly float destroySeconds;

            public GuiControl(PluginTimers timer, float destroySeconds)
            {
                this._Timer = timer;
                this._DestroySeconds = destroySeconds;
            }

            public void TriggerDamage(BasePlayer player, float health, float maxHelth)
            {
                RemovePlayer(player);
                var progressText = health / maxHelth + "";
                var healthText = (int)health + "";
                DrawUI(player, progressText, healthText);
                AddPlayer(player);
            }

            public void TriggerDeath(BasePlayer player, float health, float maxHelth)
            {
              
            }

            void AddPlayer(BasePlayer player)
            {
                _Timers[player] = _Timer.Once(_DestroySeconds, () =>
                {
                    RemovePlayer(player);
                });
            }

            void RemovePlayer(BasePlayer player)
            {
                Timer pTimer;
                if (_Timers.TryGetValue(player, out pTimer))
                {
                    _Timer.Destroy(ref pTimer);
                    DestroyUI(player);
                    _Timers.Remove(player);
                }
            }

            void DrawUI (BasePlayer player, string progress, string text)
            {
                string json = CUI_MAIN
                    .Replace("{progress}", progress)
                    .Replace("{text}", text);
                CuiHelper.AddUi(player, json);
            }

            void DestroyUI(BasePlayer player)
            {
                CuiHelper.DestroyUi(player, "hpbar_background");
            }
        }

        GuiControl _GuiControl;


        void Loaded()
        {
            Puts("Loaded");
        }

        void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
        {
           var player = info.InitiatorPlayer;
           if (player && player.IsAlive())
           {
               NextTick(() =>
               {
                   if (entity.IsAlive() && player?.IsConnected == true)
                   {
                      var health = entity.health;
                      var maxHelth = entity.MaxHealth();

                      var progress = health / maxHelth;
                      var text = (int) health;
                      string json = CUI_MAIN
                          .Replace("{progress}", progress.ToString())
                          .Replace("{text}", text.ToString());
                      CuiHelper.DestroyUi(player, "hpbar_background");
                      CuiHelper.AddUi(player, json);
                   }
               });
           }
        }

        void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
           var player = info.InitiatorPlayer;
           if (player && player.IsAlive())
           {
                string json = CUI_MAIN
                    .Replace("{progress}", "0")
                    .Replace("{text}", "Убит!");
                CuiHelper.DestroyUi(player, "hpbar_background");
                CuiHelper.AddUi(player, json);
           }
        }

        [ChatCommand("gui")]
        void cmdChatGui(BasePlayer player)
        {
            string json = CUI_MAIN
                .Replace("{progress}", "0.5")
                .Replace("{text}", "50");

            CuiHelper.AddUi(player, json);
            timer.Once(5f, () =>
            {
                CuiHelper.DestroyUi(player, "hpbar_background");
            });
        }

        string CUI_MAIN = @"
            [
  {
    ""name"": ""hpbar_background"",
    ""parent"": ""Overlay"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""material"": """",
        ""color"": ""0.5254902 0.5254902 0.5254902 0.2980392""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0.5 0"",
        ""anchormax"": ""0.5 0"",
        ""offsetmin"": ""-106 86"",
        ""offsetmax"": ""86 112""
      }
    ]
  },
  {
    ""name"": ""hpbar_img"",
    ""parent"": ""hpbar_background"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""sprite"": ""assets/icons/health.png"",
        ""material"": ""assets/icons/iconmaterial.mat"",
        ""color"": ""0.9686275 0.9176471 0.8784314 0.6745098""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""0 1"",
        ""offsetmin"": ""4 4"",
        ""offsetmax"": ""22 -4""
      }
    ]
  },
  {
    ""name"": ""hpbar_wrapper"",
    ""parent"": ""hpbar_background"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""material"": """",
        ""color"": ""1 0.4039216 0.4039216 0""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""1 1"",
        ""offsetmin"": ""25 3"",
        ""offsetmax"": ""-3 -3""
      }
    ]
  },
  {
    ""name"": ""hpbar_progress"",
    ""parent"": ""hpbar_wrapper"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""sprite"": ""assets/content/ui/ui.background.tile.psd"",
        ""material"": """",
        ""color"": ""0.6941177 0.2039216 0.003921569 0.5450981""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""{progress} 1"",
        ""offsetmin"": ""0 0"",
        ""offsetmax"": ""0 0""
      }
    ]
  },
  {
    ""name"": ""hpbar_text"",
    ""parent"": ""hpbar_wrapper"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Text"",
        ""text"": ""{text}"",
        ""fontSize"": 15,
        ""font"": ""robotocondensed-bold.ttf"",
        ""align"": ""MiddleLeft"",
        ""color"": ""0.9686275 0.9176471 0.8784314 0.8945568""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""1 1"",
        ""offsetmin"": ""2 0"",
        ""offsetmax"": ""0 0""
      }
    ]
  }
]
        ";
    }
}

Error while compiling: HealthBar.cs(61,31): error CS0038: Cannot access a nonstatic member of outer type `Oxide.Plugins.HealthBar' via nested type `Oxide.Plugins.HealthBar.GuiControl'
 
C#:
using System.Collections.Generic;
using Oxide.Game.Rust.Cui;

namespace Oxide.Plugins
{
    [Info ("Health Bar", "Raskolov", "0.1.0")]

    class HealthBar : RustPlugin
    {

        public class GuiControl
        {
            private Dictionary<BasePlayer, Timer> _Timers = new Dictionary<BasePlayer, Timer>();

            private readonly PluginTimers _Timer;
            private readonly float destroySeconds;

            public GuiControl(PluginTimers timer, float destroySeconds)
            {
                this._Timer = timer;
                this._DestroySeconds = destroySeconds;
            }

            public void TriggerDamage(BasePlayer player, float health, float maxHelth)
            {
                RemovePlayer(player);
                var progressText = health / maxHelth + "";
                var healthText = (int)health + "";
                DrawUI(player, progressText, healthText);
                AddPlayer(player);
            }

            public void TriggerDeath(BasePlayer player, float health, float maxHelth)
            {
              
            }

            void AddPlayer(BasePlayer player)
            {
                _Timers[player] = _Timer.Once(_DestroySeconds, () =>
                {
                    RemovePlayer(player);
                });
            }

            void RemovePlayer(BasePlayer player)
            {
                Timer pTimer;
                if (_Timers.TryGetValue(player, out pTimer))
                {
                    _Timer.Destroy(ref pTimer);
                    DestroyUI(player);
                    _Timers.Remove(player);
                }
            }

            void DrawUI (BasePlayer player, string progress, string text)
            {
                string json = CUI_MAIN
                    .Replace("{progress}", progress)
                    .Replace("{text}", text);
                CuiHelper.AddUi(player, json);
            }

            void DestroyUI(BasePlayer player)
            {
                CuiHelper.DestroyUi(player, "hpbar_background");
            }
        }

        GuiControl _GuiControl;


        void Loaded()
        {
            Puts("Loaded");
        }

        void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
        {
           var player = info.InitiatorPlayer;
           if (player && player.IsAlive())
           {
               NextTick(() =>
               {
                   if (entity.IsAlive() && player?.IsConnected == true)
                   {
                      var health = entity.health;
                      var maxHelth = entity.MaxHealth();

                      var progress = health / maxHelth;
                      var text = (int) health;
                      string json = CUI_MAIN
                          .Replace("{progress}", progress.ToString())
                          .Replace("{text}", text.ToString());
                      CuiHelper.DestroyUi(player, "hpbar_background");
                      CuiHelper.AddUi(player, json);
                   }
               });
           }
        }

        void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
           var player = info.InitiatorPlayer;
           if (player && player.IsAlive())
           {
                string json = CUI_MAIN
                    .Replace("{progress}", "0")
                    .Replace("{text}", "Убит!");
                CuiHelper.DestroyUi(player, "hpbar_background");
                CuiHelper.AddUi(player, json);
           }
        }

        [ChatCommand("gui")]
        void cmdChatGui(BasePlayer player)
        {
            string json = CUI_MAIN
                .Replace("{progress}", "0.5")
                .Replace("{text}", "50");

            CuiHelper.AddUi(player, json);
            timer.Once(5f, () =>
            {
                CuiHelper.DestroyUi(player, "hpbar_background");
            });
        }

        string CUI_MAIN = @"
            [
  {
    ""name"": ""hpbar_background"",
    ""parent"": ""Overlay"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""material"": """",
        ""color"": ""0.5254902 0.5254902 0.5254902 0.2980392""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0.5 0"",
        ""anchormax"": ""0.5 0"",
        ""offsetmin"": ""-106 86"",
        ""offsetmax"": ""86 112""
      }
    ]
  },
  {
    ""name"": ""hpbar_img"",
    ""parent"": ""hpbar_background"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""sprite"": ""assets/icons/health.png"",
        ""material"": ""assets/icons/iconmaterial.mat"",
        ""color"": ""0.9686275 0.9176471 0.8784314 0.6745098""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""0 1"",
        ""offsetmin"": ""4 4"",
        ""offsetmax"": ""22 -4""
      }
    ]
  },
  {
    ""name"": ""hpbar_wrapper"",
    ""parent"": ""hpbar_background"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""material"": """",
        ""color"": ""1 0.4039216 0.4039216 0""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""1 1"",
        ""offsetmin"": ""25 3"",
        ""offsetmax"": ""-3 -3""
      }
    ]
  },
  {
    ""name"": ""hpbar_progress"",
    ""parent"": ""hpbar_wrapper"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""sprite"": ""assets/content/ui/ui.background.tile.psd"",
        ""material"": """",
        ""color"": ""0.6941177 0.2039216 0.003921569 0.5450981""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""{progress} 1"",
        ""offsetmin"": ""0 0"",
        ""offsetmax"": ""0 0""
      }
    ]
  },
  {
    ""name"": ""hpbar_text"",
    ""parent"": ""hpbar_wrapper"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Text"",
        ""text"": ""{text}"",
        ""fontSize"": 15,
        ""font"": ""robotocondensed-bold.ttf"",
        ""align"": ""MiddleLeft"",
        ""color"": ""0.9686275 0.9176471 0.8784314 0.8945568""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""1 1"",
        ""offsetmin"": ""2 0"",
        ""offsetmax"": ""0 0""
      }
    ]
  }
]
        ";
    }
}

Error while compiling: HealthBar.cs(61,31): error CS0038: Cannot access a nonstatic member of outer type `Oxide.Plugins.HealthBar' via nested type `Oxide.Plugins.HealthBar.GuiControl'
Ошибка заключается в том, что переменная timer не объявлена в методе cmdChatGui. Вы должны создать новую переменную timer внутри метода и присвоить ей значение базовой переменной RustPlugin.timer.

Код:
[ChatCommand(&quot;gui&quot;)]
void cmdChatGui(BasePlayer player)
{
    PluginTimers timer = RustPlugin.timer; // добавить новую переменную
    string json = CUI_MAIN
        .Replace(&quot;{progress}&quot;, &quot;0.5&quot;)
        .Replace(&quot;{text}&quot;, &quot;50&quot;);
    CuiHelper.AddUi(player, json);
    timer.Once(5f, () =&gt;
    {
        CuiHelper.DestroyUi(player, &quot;hpbar_background&quot;);
    });
}

Теперь код должен успешно скомпилироваться.
 
C#:
using System.Collections.Generic;
using Oxide.Game.Rust.Cui;

namespace Oxide.Plugins
{
    [Info ("Health Bar", "Raskolov", "0.1.0")]

    class HealthBar : RustPlugin
    {

        public class GuiControl
        {
            private Dictionary<BasePlayer, Timer> _Timers = new Dictionary<BasePlayer, Timer>();

            private readonly PluginTimers _Timer;
            private readonly float destroySeconds;

            public GuiControl(PluginTimers timer, float destroySeconds)
            {
                this._Timer = timer;
                this._DestroySeconds = destroySeconds;
            }

            public void TriggerDamage(BasePlayer player, float health, float maxHelth)
            {
                RemovePlayer(player);
                var progressText = health / maxHelth + "";
                var healthText = (int)health + "";
                DrawUI(player, progressText, healthText);
                AddPlayer(player);
            }

            public void TriggerDeath(BasePlayer player, float health, float maxHelth)
            {
              
            }

            void AddPlayer(BasePlayer player)
            {
                _Timers[player] = _Timer.Once(_DestroySeconds, () =>
                {
                    RemovePlayer(player);
                });
            }

            void RemovePlayer(BasePlayer player)
            {
                Timer pTimer;
                if (_Timers.TryGetValue(player, out pTimer))
                {
                    _Timer.Destroy(ref pTimer);
                    DestroyUI(player);
                    _Timers.Remove(player);
                }
            }

            void DrawUI (BasePlayer player, string progress, string text)
            {
                string json = CUI_MAIN
                    .Replace("{progress}", progress)
                    .Replace("{text}", text);
                CuiHelper.AddUi(player, json);
            }

            void DestroyUI(BasePlayer player)
            {
                CuiHelper.DestroyUi(player, "hpbar_background");
            }
        }

        GuiControl _GuiControl;


        void Loaded()
        {
            Puts("Loaded");
        }

        void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
        {
           var player = info.InitiatorPlayer;
           if (player && player.IsAlive())
           {
               NextTick(() =>
               {
                   if (entity.IsAlive() && player?.IsConnected == true)
                   {
                      var health = entity.health;
                      var maxHelth = entity.MaxHealth();

                      var progress = health / maxHelth;
                      var text = (int) health;
                      string json = CUI_MAIN
                          .Replace("{progress}", progress.ToString())
                          .Replace("{text}", text.ToString());
                      CuiHelper.DestroyUi(player, "hpbar_background");
                      CuiHelper.AddUi(player, json);
                   }
               });
           }
        }

        void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
           var player = info.InitiatorPlayer;
           if (player && player.IsAlive())
           {
                string json = CUI_MAIN
                    .Replace("{progress}", "0")
                    .Replace("{text}", "Убит!");
                CuiHelper.DestroyUi(player, "hpbar_background");
                CuiHelper.AddUi(player, json);
           }
        }

        [ChatCommand("gui")]
        void cmdChatGui(BasePlayer player)
        {
            string json = CUI_MAIN
                .Replace("{progress}", "0.5")
                .Replace("{text}", "50");

            CuiHelper.AddUi(player, json);
            timer.Once(5f, () =>
            {
                CuiHelper.DestroyUi(player, "hpbar_background");
            });
        }

        string CUI_MAIN = @"
            [
  {
    ""name"": ""hpbar_background"",
    ""parent"": ""Overlay"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""material"": """",
        ""color"": ""0.5254902 0.5254902 0.5254902 0.2980392""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0.5 0"",
        ""anchormax"": ""0.5 0"",
        ""offsetmin"": ""-106 86"",
        ""offsetmax"": ""86 112""
      }
    ]
  },
  {
    ""name"": ""hpbar_img"",
    ""parent"": ""hpbar_background"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""sprite"": ""assets/icons/health.png"",
        ""material"": ""assets/icons/iconmaterial.mat"",
        ""color"": ""0.9686275 0.9176471 0.8784314 0.6745098""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""0 1"",
        ""offsetmin"": ""4 4"",
        ""offsetmax"": ""22 -4""
      }
    ]
  },
  {
    ""name"": ""hpbar_wrapper"",
    ""parent"": ""hpbar_background"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""material"": """",
        ""color"": ""1 0.4039216 0.4039216 0""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""1 1"",
        ""offsetmin"": ""25 3"",
        ""offsetmax"": ""-3 -3""
      }
    ]
  },
  {
    ""name"": ""hpbar_progress"",
    ""parent"": ""hpbar_wrapper"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""sprite"": ""assets/content/ui/ui.background.tile.psd"",
        ""material"": """",
        ""color"": ""0.6941177 0.2039216 0.003921569 0.5450981""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""{progress} 1"",
        ""offsetmin"": ""0 0"",
        ""offsetmax"": ""0 0""
      }
    ]
  },
  {
    ""name"": ""hpbar_text"",
    ""parent"": ""hpbar_wrapper"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Text"",
        ""text"": ""{text}"",
        ""fontSize"": 15,
        ""font"": ""robotocondensed-bold.ttf"",
        ""align"": ""MiddleLeft"",
        ""color"": ""0.9686275 0.9176471 0.8784314 0.8945568""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""1 1"",
        ""offsetmin"": ""2 0"",
        ""offsetmax"": ""0 0""
      }
    ]
  }
]
        ";
    }
}

Error while compiling: HealthBar.cs(61,31): error CS0038: Cannot access a nonstatic member of outer type `Oxide.Plugins.HealthBar' via nested type `Oxide.Plugins.HealthBar.GuiControl'
Ошибка заключается в том, что переменная timer не инициализирована в методе cmdChatGui.

Чтобы исправить эту ошибку, вам нужно передать переменную timer в метод cmdChatGui через параметр:

Код:
[ChatCommand("gui")]
void cmdChatGui(BasePlayer player)
{
    string json = CUI_MAIN
        .Replace("{progress}", "0.5")
        .Replace("{text}", "50");
    CuiHelper.AddUi(player, json);
    _GuiControl.timer.Once(5f, () =>
    {
        CuiHelper.DestroyUi(player, "hpbar_background");
    });
}

Теперь код должен успешно скомпилироваться.
 
Ошибка заключается в том, что переменная timer не инициализирована в методе cmdChatGui.

Чтобы исправить эту ошибку, вам нужно передать переменную timer в метод cmdChatGui через параметр:

Код:
[ChatCommand("gui")]
void cmdChatGui(BasePlayer player)
{
    string json = CUI_MAIN
        .Replace("{progress}", "0.5")
        .Replace("{text}", "50");
    CuiHelper.AddUi(player, json);
    _GuiControl.timer.Once(5f, () =>
    {
        CuiHelper.DestroyUi(player, "hpbar_background");
    });
}

Теперь код должен успешно скомпилироваться.
C#:
using System.Collections.Generic;
using Oxide.Game.Rust.Cui;
namespace Oxide.Plugins 
{
    [Info ("Health Bar", "Raskolov", "0.1.0")]
    class HealthBar : RustPlugin 
    {
        public class GuiControl
        {
            private Dictionary<BasePlayer, Timer> _Timers = new Dictionary<BasePlayer, Timer>();
            private readonly PluginTimers _Timer;
            private readonly float destroySeconds;
            public GuiControl(PluginTimers timer, float destroySeconds)
            {
                this._Timer = timer;
                this._DestroySeconds = destroySeconds;
            }
            public void TriggerDamage(BasePlayer player, float health, float maxHelth)
            {
                RemovePlayer(player);
                var progressText = health / maxHelth + "";
                var healthText = (int)health + "";
                DrawUI(player, progressText, healthText);
                AddPlayer(player);
            }
            public void TriggerDeath(BasePlayer player, float health, float maxHelth)
            {
              
            }
            void AddPlayer(BasePlayer player)
            {
                _Timers[player] = _Timer.Once(_DestroySeconds, () => 
                {
                    RemovePlayer(player);
                });
            }
            void RemovePlayer(BasePlayer player)
            {
                Timer pTimer;
                if (_Timers.TryGetValue(player, out pTimer))
                {
                    _Timer.Destroy(ref pTimer);
                    DestroyUI(player);
                    _Timers.Remove(player);
                }
            }
            void DrawUI (BasePlayer player, string progress, string text)
            {
                string json = CUI_MAIN
                    .Replace("{progress}", progress)
                    .Replace("{text}", text);
                CuiHelper.AddUi(player, json);
            }
            void DestroyUI(BasePlayer player)
            {
                CuiHelper.DestroyUi(player, "hpbar_background");
            }
        }
        GuiControl _GuiControl;

        void Loaded()
        {
            Puts("Loaded");
        }
        void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
        {
           var player = info.InitiatorPlayer;
           if (player && player.IsAlive())
           {
               NextTick(() => 
               {
                   if (entity.IsAlive() && player?.IsConnected == true)
                   {
                      var health = entity.health;
                      var maxHelth = entity.MaxHealth();
                      var progress = health / maxHelth;
                      var text = (int) health;
                      string json = CUI_MAIN
                          .Replace("{progress}", progress.ToString())
                          .Replace("{text}", text.ToString());
                      CuiHelper.DestroyUi(player, "hpbar_background");
                      CuiHelper.AddUi(player, json);
                   }
               });
           }
        }
        void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
           var player = info.InitiatorPlayer;
           if (player && player.IsAlive())
           {
                string json = CUI_MAIN
                    .Replace("{progress}", "0")
                    .Replace("{text}", "Убит!");
                CuiHelper.DestroyUi(player, "hpbar_background");
                CuiHelper.AddUi(player, json);
           }
        }
        [ChatCommand("gui")]
        void cmdChatGui(BasePlayer player)
        {
            string json = CUI_MAIN
                .Replace("{progress}", "0.5")
                .Replace("{text}", "50");
            CuiHelper.AddUi(player, json);
            _GuiControl.timer.Once(5f, () =>
            {
                CuiHelper.DestroyUi(player, "hpbar_background");
            });
        }
        string CUI_MAIN = @"
            [
  {
    ""name"": ""hpbar_background"",
    ""parent"": ""Overlay"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""material"": """",
        ""color"": ""0.5254902 0.5254902 0.5254902 0.2980392""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0.5 0"",
        ""anchormax"": ""0.5 0"",
        ""offsetmin"": ""-106 86"",
        ""offsetmax"": ""86 112""
      }
    ]
  },
  {
    ""name"": ""hpbar_img"",
    ""parent"": ""hpbar_background"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""sprite"": ""assets/icons/health.png"",
        ""material"": ""assets/icons/iconmaterial.mat"",
        ""color"": ""0.9686275 0.9176471 0.8784314 0.6745098""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""0 1"",
        ""offsetmin"": ""4 4"",
        ""offsetmax"": ""22 -4""
      }
    ]
  },
  {
    ""name"": ""hpbar_wrapper"",
    ""parent"": ""hpbar_background"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""material"": """",
        ""color"": ""1 0.4039216 0.4039216 0""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""1 1"",
        ""offsetmin"": ""25 3"",
        ""offsetmax"": ""-3 -3""
      }
    ]
  },
  {
    ""name"": ""hpbar_progress"",
    ""parent"": ""hpbar_wrapper"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""sprite"": ""assets/content/ui/ui.background.tile.psd"",
        ""material"": """",
        ""color"": ""0.6941177 0.2039216 0.003921569 0.5450981""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""{progress} 1"",
        ""offsetmin"": ""0 0"",
        ""offsetmax"": ""0 0""
      }
    ]
  },
  {
    ""name"": ""hpbar_text"",
    ""parent"": ""hpbar_wrapper"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Text"",
        ""text"": ""{text}"",
        ""fontSize"": 15,
        ""font"": ""robotocondensed-bold.ttf"",
        ""align"": ""MiddleLeft"",
        ""color"": ""0.9686275 0.9176471 0.8784314 0.8945568""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""1 1"",
        ""offsetmin"": ""2 0"",
        ""offsetmax"": ""0 0""
      }
    ]
  }
]
        ";
    }
}
Error while compiling: HealthBar.cs(125,25): error CS1061: Type `Oxide.Plugins.HealthBar.GuiControl' does not contain a definition for `timer' and no extension method `timer' of type `Oxide.Plugins.HealthBar.GuiControl' could be found. Are you missing an assembly reference?
 
C#:
using System.Collections.Generic;
using Oxide.Game.Rust.Cui;
namespace Oxide.Plugins 
{
    [Info ("Health Bar", "Raskolov", "0.1.0")]
    class HealthBar : RustPlugin 
    {
        public class GuiControl
        {
            private Dictionary<BasePlayer, Timer> _Timers = new Dictionary<BasePlayer, Timer>();
            private readonly PluginTimers _Timer;
            private readonly float destroySeconds;
            public GuiControl(PluginTimers timer, float destroySeconds)
            {
                this._Timer = timer;
                this._DestroySeconds = destroySeconds;
            }
            public void TriggerDamage(BasePlayer player, float health, float maxHelth)
            {
                RemovePlayer(player);
                var progressText = health / maxHelth + "";
                var healthText = (int)health + "";
                DrawUI(player, progressText, healthText);
                AddPlayer(player);
            }
            public void TriggerDeath(BasePlayer player, float health, float maxHelth)
            {
              
            }
            void AddPlayer(BasePlayer player)
            {
                _Timers[player] = _Timer.Once(_DestroySeconds, () => 
                {
                    RemovePlayer(player);
                });
            }
            void RemovePlayer(BasePlayer player)
            {
                Timer pTimer;
                if (_Timers.TryGetValue(player, out pTimer))
                {
                    _Timer.Destroy(ref pTimer);
                    DestroyUI(player);
                    _Timers.Remove(player);
                }
            }
            void DrawUI (BasePlayer player, string progress, string text)
            {
                string json = CUI_MAIN
                    .Replace("{progress}", progress)
                    .Replace("{text}", text);
                CuiHelper.AddUi(player, json);
            }
            void DestroyUI(BasePlayer player)
            {
                CuiHelper.DestroyUi(player, "hpbar_background");
            }
        }
        GuiControl _GuiControl;

        void Loaded()
        {
            Puts("Loaded");
        }
        void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
        {
           var player = info.InitiatorPlayer;
           if (player && player.IsAlive())
           {
               NextTick(() => 
               {
                   if (entity.IsAlive() && player?.IsConnected == true)
                   {
                      var health = entity.health;
                      var maxHelth = entity.MaxHealth();
                      var progress = health / maxHelth;
                      var text = (int) health;
                      string json = CUI_MAIN
                          .Replace("{progress}", progress.ToString())
                          .Replace("{text}", text.ToString());
                      CuiHelper.DestroyUi(player, "hpbar_background");
                      CuiHelper.AddUi(player, json);
                   }
               });
           }
        }
        void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
           var player = info.InitiatorPlayer;
           if (player && player.IsAlive())
           {
                string json = CUI_MAIN
                    .Replace("{progress}", "0")
                    .Replace("{text}", "Убит!");
                CuiHelper.DestroyUi(player, "hpbar_background");
                CuiHelper.AddUi(player, json);
           }
        }
        [ChatCommand("gui")]
        void cmdChatGui(BasePlayer player)
        {
            string json = CUI_MAIN
                .Replace("{progress}", "0.5")
                .Replace("{text}", "50");
            CuiHelper.AddUi(player, json);
            _GuiControl.timer.Once(5f, () =>
            {
                CuiHelper.DestroyUi(player, "hpbar_background");
            });
        }
        string CUI_MAIN = @"
            [
  {
    ""name"": ""hpbar_background"",
    ""parent"": ""Overlay"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""material"": """",
        ""color"": ""0.5254902 0.5254902 0.5254902 0.2980392""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0.5 0"",
        ""anchormax"": ""0.5 0"",
        ""offsetmin"": ""-106 86"",
        ""offsetmax"": ""86 112""
      }
    ]
  },
  {
    ""name"": ""hpbar_img"",
    ""parent"": ""hpbar_background"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""sprite"": ""assets/icons/health.png"",
        ""material"": ""assets/icons/iconmaterial.mat"",
        ""color"": ""0.9686275 0.9176471 0.8784314 0.6745098""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""0 1"",
        ""offsetmin"": ""4 4"",
        ""offsetmax"": ""22 -4""
      }
    ]
  },
  {
    ""name"": ""hpbar_wrapper"",
    ""parent"": ""hpbar_background"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""material"": """",
        ""color"": ""1 0.4039216 0.4039216 0""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""1 1"",
        ""offsetmin"": ""25 3"",
        ""offsetmax"": ""-3 -3""
      }
    ]
  },
  {
    ""name"": ""hpbar_progress"",
    ""parent"": ""hpbar_wrapper"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""sprite"": ""assets/content/ui/ui.background.tile.psd"",
        ""material"": """",
        ""color"": ""0.6941177 0.2039216 0.003921569 0.5450981""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""{progress} 1"",
        ""offsetmin"": ""0 0"",
        ""offsetmax"": ""0 0""
      }
    ]
  },
  {
    ""name"": ""hpbar_text"",
    ""parent"": ""hpbar_wrapper"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Text"",
        ""text"": ""{text}"",
        ""fontSize"": 15,
        ""font"": ""robotocondensed-bold.ttf"",
        ""align"": ""MiddleLeft"",
        ""color"": ""0.9686275 0.9176471 0.8784314 0.8945568""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""1 1"",
        ""offsetmin"": ""2 0"",
        ""offsetmax"": ""0 0""
      }
    ]
  }
]
        ";
    }
}
Error while compiling: HealthBar.cs(125,25): error CS1061: Type `Oxide.Plugins.HealthBar.GuiControl' does not contain a definition for `timer' and no extension method `timer' of type `Oxide.Plugins.HealthBar.GuiControl' could be found. Are you missing an assembly reference?
Ошибка в этом коде заключается в том, что переменная timer не была правильно инициализирована при создании объекта GuiControl.

Исправьте это, обратившись к переменной timer через поле _Timer:

Код:
[ChatCommand(&quot;gui&quot;)]
void cmdChatGui(BasePlayer player)
{
    string json = CUI_MAIN
        .Replace(&quot;{progress}&quot;, &quot;0.5&quot;)
        .Replace(&quot;{text}&quot;, &quot;50&quot;);
    CuiHelper.AddUi(player, json);
    _GuiControl._Timer.Once(5f, () =&gt;
    {
        CuiHelper.DestroyUi(player, &quot;hpbar_background&quot;);
    });
}

Теперь код должен успешно скомпилироваться.
 
Ошибка в этом коде заключается в том, что переменная timer не была правильно инициализирована при создании объекта GuiControl.

Исправьте это, обратившись к переменной timer через поле _Timer:

Код:
[ChatCommand(&quot;gui&quot;)]
void cmdChatGui(BasePlayer player)
{
    string json = CUI_MAIN
        .Replace(&quot;{progress}&quot;, &quot;0.5&quot;)
        .Replace(&quot;{text}&quot;, &quot;50&quot;);
    CuiHelper.AddUi(player, json);
    _GuiControl._Timer.Once(5f, () =&gt;
    {
        CuiHelper.DestroyUi(player, &quot;hpbar_background&quot;);
    });
}

Теперь код должен успешно скомпилироваться.
C#:
using System.Collections.Generic;
using Oxide.Game.Rust.Cui;

namespace Oxide.Plugins
{
    [Info ("Health Bar", "Raskolov", "0.1.0")]

    public class HealthBar : RustPlugin
    {

        public class GuiControl
        {
            private Dictionary<BasePlayer, Timer> _Timers = new Dictionary<BasePlayer, Timer>();

            public readonly PluginTimers _Timer;
            public readonly float destroySeconds;

            public GuiControl(PluginTimers timer, float destroySeconds)
            {
                this._Timer = timer;
                this._DestroySeconds = destroySeconds;
            }

            public void TriggerDamage(BasePlayer player, float health, float maxHelth)
            {
                RemovePlayer(player);
                var progressText = health / maxHelth + "";
                var healthText = (int)health + "";
                DrawUI(player, progressText, healthText);
                AddPlayer(player);
            }

            public void TriggerDeath(BasePlayer player, float health, float maxHelth)
            {
                RemovePlayer(player);
                var progressText = "0";
                var healthText = "Убит!";
                DrawUI(player, progressText, healthText);
                AddPlayer(player);
            }

            void AddPlayer(BasePlayer player)
            {
                _Timers[player] = _Timer.Once(_DestroySeconds, () =>
                {
                    RemovePlayer(player);
                });
            }

            void RemovePlayer(BasePlayer player)
            {
                Timer pTimer;
                if (_Timers.TryGetValue(player, out pTimer))
                {
                    _Timer.Destroy(ref pTimer);
                    DestroyUI(player);
                    _Timers.Remove(player);
                }
            }

            void DrawUI (BasePlayer player, string progress, string text)
            {
                string json = CUI_MAIN
                    .Replace("{progress}", progress)
                    .Replace("{text}", text);
                CuiHelper.AddUi(player, json);
            }

            void DestroyUI(BasePlayer player)
            {
                CuiHelper.DestroyUi(player, "hpbar_background");
            }
        }

        GuiControl _GuiControl;


        void Loaded()
        {
            Puts("Loaded");
        }

        void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
        {
           var player = info.InitiatorPlayer;
           if (player && player.IsAlive())
           {
               NextTick(() =>
               {
                   if (entity.IsAlive() && player?.IsConnected == true)
                   {
                      var health = entity.health;
                      var maxHelth = entity.MaxHealth();

                      var progress = health / maxHelth;
                      var text = (int) health;
                      string json = CUI_MAIN
                          .Replace("{progress}", progress.ToString())
                          .Replace("{text}", text.ToString());
                      CuiHelper.DestroyUi(player, "hpbar_background");
                      CuiHelper.AddUi(player, json);
                   }
               });
           }
        }

        void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
           var player = info.InitiatorPlayer;
           if (player && player.IsAlive())
           {
                string json = CUI_MAIN
                    .Replace("{progress}", "0")
                    .Replace("{text}", "Убит!");
                CuiHelper.DestroyUi(player, "hpbar_background");
                CuiHelper.AddUi(player, json);
           }
        }

        [ChatCommand("gui")]
        void cmdChatGui(BasePlayer player)
        {
            string json = CUI_MAIN
                .Replace("{progress}", "0.5")
                .Replace("{text}", "50");

            CuiHelper.AddUi(player, json);
            timer.Once(5f, () =>
            {
                CuiHelper.DestroyUi(player, "hpbar_background");
            });
        }

        string CUI_MAIN = @"
            [
  {
    ""name"": ""hpbar_background"",
    ""parent"": ""Overlay"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""material"": """",
        ""color"": ""0.5254902 0.5254902 0.5254902 0.2980392""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0.5 0"",
        ""anchormax"": ""0.5 0"",
        ""offsetmin"": ""-106 86"",
        ""offsetmax"": ""86 112""
      }
    ]
  },
  {
    ""name"": ""hpbar_img"",
    ""parent"": ""hpbar_background"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""sprite"": ""assets/icons/health.png"",
        ""material"": ""assets/icons/iconmaterial.mat"",
        ""color"": ""0.9686275 0.9176471 0.8784314 0.6745098""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""0 1"",
        ""offsetmin"": ""4 4"",
        ""offsetmax"": ""22 -4""
      }
    ]
  },
  {
    ""name"": ""hpbar_wrapper"",
    ""parent"": ""hpbar_background"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""material"": """",
        ""color"": ""1 0.4039216 0.4039216 0""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""1 1"",
        ""offsetmin"": ""25 3"",
        ""offsetmax"": ""-3 -3""
      }
    ]
  },
  {
    ""name"": ""hpbar_progress"",
    ""parent"": ""hpbar_wrapper"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""sprite"": ""assets/content/ui/ui.background.tile.psd"",
        ""material"": """",
        ""color"": ""0.6941177 0.2039216 0.003921569 0.5450981""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""{progress} 1"",
        ""offsetmin"": ""0 0"",
        ""offsetmax"": ""0 0""
      }
    ]
  },
  {
    ""name"": ""hpbar_text"",
    ""parent"": ""hpbar_wrapper"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Text"",
        ""text"": ""{text}"",
        ""fontSize"": 15,
        ""font"": ""robotocondensed-bold.ttf"",
        ""align"": ""MiddleLeft"",
        ""color"": ""0.9686275 0.9176471 0.8784314 0.8945568""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""1 1"",
        ""offsetmin"": ""2 0"",
        ""offsetmax"": ""0 0""
      }
    ]
  }
]
        ";
    }
}

Error while compiling: HealthBar.cs(65,31): error CS0038: Cannot access a nonstatic member of outer type `Oxide.Plugins.HealthBar' via nested type `Oxide.Plugins.HealthBar.GuiControl'
 
C#:
using System.Collections.Generic;
using Oxide.Game.Rust.Cui;

namespace Oxide.Plugins
{
    [Info ("Health Bar", "Raskolov", "0.1.0")]

    public class HealthBar : RustPlugin
    {

        public class GuiControl
        {
            private Dictionary<BasePlayer, Timer> _Timers = new Dictionary<BasePlayer, Timer>();

            public readonly PluginTimers _Timer;
            public readonly float destroySeconds;

            public GuiControl(PluginTimers timer, float destroySeconds)
            {
                this._Timer = timer;
                this._DestroySeconds = destroySeconds;
            }

            public void TriggerDamage(BasePlayer player, float health, float maxHelth)
            {
                RemovePlayer(player);
                var progressText = health / maxHelth + "";
                var healthText = (int)health + "";
                DrawUI(player, progressText, healthText);
                AddPlayer(player);
            }

            public void TriggerDeath(BasePlayer player, float health, float maxHelth)
            {
                RemovePlayer(player);
                var progressText = "0";
                var healthText = "Убит!";
                DrawUI(player, progressText, healthText);
                AddPlayer(player);
            }

            void AddPlayer(BasePlayer player)
            {
                _Timers[player] = _Timer.Once(_DestroySeconds, () =>
                {
                    RemovePlayer(player);
                });
            }

            void RemovePlayer(BasePlayer player)
            {
                Timer pTimer;
                if (_Timers.TryGetValue(player, out pTimer))
                {
                    _Timer.Destroy(ref pTimer);
                    DestroyUI(player);
                    _Timers.Remove(player);
                }
            }

            void DrawUI (BasePlayer player, string progress, string text)
            {
                string json = CUI_MAIN
                    .Replace("{progress}", progress)
                    .Replace("{text}", text);
                CuiHelper.AddUi(player, json);
            }

            void DestroyUI(BasePlayer player)
            {
                CuiHelper.DestroyUi(player, "hpbar_background");
            }
        }

        GuiControl _GuiControl;


        void Loaded()
        {
            Puts("Loaded");
        }

        void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
        {
           var player = info.InitiatorPlayer;
           if (player && player.IsAlive())
           {
               NextTick(() =>
               {
                   if (entity.IsAlive() && player?.IsConnected == true)
                   {
                      var health = entity.health;
                      var maxHelth = entity.MaxHealth();

                      var progress = health / maxHelth;
                      var text = (int) health;
                      string json = CUI_MAIN
                          .Replace("{progress}", progress.ToString())
                          .Replace("{text}", text.ToString());
                      CuiHelper.DestroyUi(player, "hpbar_background");
                      CuiHelper.AddUi(player, json);
                   }
               });
           }
        }

        void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
           var player = info.InitiatorPlayer;
           if (player && player.IsAlive())
           {
                string json = CUI_MAIN
                    .Replace("{progress}", "0")
                    .Replace("{text}", "Убит!");
                CuiHelper.DestroyUi(player, "hpbar_background");
                CuiHelper.AddUi(player, json);
           }
        }

        [ChatCommand("gui")]
        void cmdChatGui(BasePlayer player)
        {
            string json = CUI_MAIN
                .Replace("{progress}", "0.5")
                .Replace("{text}", "50");

            CuiHelper.AddUi(player, json);
            timer.Once(5f, () =>
            {
                CuiHelper.DestroyUi(player, "hpbar_background");
            });
        }

        string CUI_MAIN = @"
            [
  {
    ""name"": ""hpbar_background"",
    ""parent"": ""Overlay"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""material"": """",
        ""color"": ""0.5254902 0.5254902 0.5254902 0.2980392""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0.5 0"",
        ""anchormax"": ""0.5 0"",
        ""offsetmin"": ""-106 86"",
        ""offsetmax"": ""86 112""
      }
    ]
  },
  {
    ""name"": ""hpbar_img"",
    ""parent"": ""hpbar_background"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""sprite"": ""assets/icons/health.png"",
        ""material"": ""assets/icons/iconmaterial.mat"",
        ""color"": ""0.9686275 0.9176471 0.8784314 0.6745098""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""0 1"",
        ""offsetmin"": ""4 4"",
        ""offsetmax"": ""22 -4""
      }
    ]
  },
  {
    ""name"": ""hpbar_wrapper"",
    ""parent"": ""hpbar_background"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""material"": """",
        ""color"": ""1 0.4039216 0.4039216 0""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""1 1"",
        ""offsetmin"": ""25 3"",
        ""offsetmax"": ""-3 -3""
      }
    ]
  },
  {
    ""name"": ""hpbar_progress"",
    ""parent"": ""hpbar_wrapper"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""sprite"": ""assets/content/ui/ui.background.tile.psd"",
        ""material"": """",
        ""color"": ""0.6941177 0.2039216 0.003921569 0.5450981""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""{progress} 1"",
        ""offsetmin"": ""0 0"",
        ""offsetmax"": ""0 0""
      }
    ]
  },
  {
    ""name"": ""hpbar_text"",
    ""parent"": ""hpbar_wrapper"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Text"",
        ""text"": ""{text}"",
        ""fontSize"": 15,
        ""font"": ""robotocondensed-bold.ttf"",
        ""align"": ""MiddleLeft"",
        ""color"": ""0.9686275 0.9176471 0.8784314 0.8945568""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""1 1"",
        ""offsetmin"": ""2 0"",
        ""offsetmax"": ""0 0""
      }
    ]
  }
]
        ";
    }
}

Error while compiling: HealthBar.cs(65,31): error CS0038: Cannot access a nonstatic member of outer type `Oxide.Plugins.HealthBar' via nested type `Oxide.Plugins.HealthBar.GuiControl'
Ошибка в этом коде заключается в том, что переменная timer не была объявлена и правильно инициализирована в методе cmdChatGui.

Исправьте это, объявив переменную timer и присваивая ей значение timers в методе Loaded:

Код:
[Info("Health Bar", "Raskolov", "0.1.0")]
public class HealthBar : RustPlugin
{
    public class GuiControl
    {
        private Dictionary<BasePlayer, Timer> _Timers = new Dictionary<BasePlayer, Timer>();
        public readonly PluginTimers _Timer;
        public readonly float destroySeconds;
        public GuiControl(PluginTimers timer, float destroySeconds)
        {
            this._Timer = timer;
            this.destroySeconds = destroySeconds;
        }
        // Остальной код без изменений
    }
    GuiControl _GuiControl;
    void Loaded()
    {
        Puts("Loaded");
        var timers = GetLibrary<PluginTimers>();
        timer = timers.GetTimer(this, "HealthBarTimer");
        _GuiControl = new GuiControl(timer, 5f);
    }
    // Остальной код без изменений
    [ChatCommand("gui")]
    void cmdChatGui(BasePlayer player)
    {
        string json = CUI_MAIN
            .Replace("{progress}", "0.5")
            .Replace("{text}", "50");
        CuiHelper.AddUi(player, json);
        timer.Once(5f, () =>
        {
            CuiHelper.DestroyUi(player, "hpbar_background");
        });
    }
    Timer timer;
    // Остальной код без изменений
}

Теперь код должен успешно скомпилироваться.
 
Ошибка в этом коде заключается в том, что переменная timer не была объявлена и правильно инициализирована в методе cmdChatGui.

Исправьте это, объявив переменную timer и присваивая ей значение timers в методе Loaded:

Код:
[Info("Health Bar", "Raskolov", "0.1.0")]
public class HealthBar : RustPlugin
{
    public class GuiControl
    {
        private Dictionary<BasePlayer, Timer> _Timers = new Dictionary<BasePlayer, Timer>();
        public readonly PluginTimers _Timer;
        public readonly float destroySeconds;
        public GuiControl(PluginTimers timer, float destroySeconds)
        {
            this._Timer = timer;
            this.destroySeconds = destroySeconds;
        }
        // Остальной код без изменений
    }
    GuiControl _GuiControl;
    void Loaded()
    {
        Puts("Loaded");
        var timers = GetLibrary<PluginTimers>();
        timer = timers.GetTimer(this, "HealthBarTimer");
        _GuiControl = new GuiControl(timer, 5f);
    }
    // Остальной код без изменений
    [ChatCommand("gui")]
    void cmdChatGui(BasePlayer player)
    {
        string json = CUI_MAIN
            .Replace("{progress}", "0.5")
            .Replace("{text}", "50");
        CuiHelper.AddUi(player, json);
        timer.Once(5f, () =>
        {
            CuiHelper.DestroyUi(player, "hpbar_background");
        });
    }
    Timer timer;
    // Остальной код без изменений
}

Теперь код должен успешно скомпилироваться.

C#:
using System.Collections.Generic;
using Oxide.Game.Rust.Cui;

namespace Oxide.Plugins
{
    [Info ("Health Bar", "Raskolov", "0.1.0")]

    public class HealthBar : RustPlugin
    {

        public class GuiControl
        {
            private Dictionary<BasePlayer, Timer> _Timers = new Dictionary<BasePlayer, Timer>();

            public readonly PluginTimers _Timer;
            public readonly float destroySeconds;

            public GuiControl(PluginTimers timer, float destroySeconds)
            {
                this._Timer = timer;
                this.destroySeconds = destroySeconds;
            }

            public void TriggerDamage(BasePlayer player, float health, float maxHelth)
            {
                RemovePlayer(player);
                var progressText = health / maxHelth + "";
                var healthText = (int)health + "";
                DrawUI(player, progressText, healthText);
                AddPlayer(player);
            }

            public void TriggerDeath(BasePlayer player, float health, float maxHelth)
            {
                RemovePlayer(player);
                var progressText = "0";
                var healthText = "Убит!";
                DrawUI(player, progressText, healthText);
                AddPlayer(player);
            }

            void AddPlayer(BasePlayer player)
            {
                _Timers[player] = _Timer.Once(_DestroySeconds, () =>
                {
                    RemovePlayer(player);
                });
            }

            void RemovePlayer(BasePlayer player)
            {
                Timer pTimer;
                if (_Timers.TryGetValue(player, out pTimer))
                {
                    _Timer.Destroy(ref pTimer);
                    DestroyUI(player);
                    _Timers.Remove(player);
                }
            }

            void DrawUI (BasePlayer player, string progress, string text)
            {
                string json = CUI_MAIN
                    .Replace("{progress}", progress)
                    .Replace("{text}", text);
                CuiHelper.AddUi(player, json);
            }

            void DestroyUI(BasePlayer player)
            {
                CuiHelper.DestroyUi(player, "hpbar_background");
            }
        }

        GuiControl _GuiControl;


        void Loaded()
        {
              Puts("Loaded");
              var timers = GetLibrary<PluginTimers>();
              timer = timers.GetTimer(this, "HealthBarTimer");
              _GuiControl = new GuiControl(timer, 5f);
        }

        void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
        {
           var player = info.InitiatorPlayer;
           if (player && player.IsAlive())
           {
               NextTick(() =>
               {
                   if (entity.IsAlive() && player?.IsConnected == true)
                   {
                      var health = entity.health;
                      var maxHelth = entity.MaxHealth();

                      var progress = health / maxHelth;
                      var text = (int) health;
                      string json = CUI_MAIN
                          .Replace("{progress}", progress.ToString())
                          .Replace("{text}", text.ToString());
                      CuiHelper.DestroyUi(player, "hpbar_background");
                      CuiHelper.AddUi(player, json);
                   }
               });
           }
        }

        void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
           var player = info.InitiatorPlayer;
           if (player && player.IsAlive())
           {
                string json = CUI_MAIN
                    .Replace("{progress}", "0")
                    .Replace("{text}", "Убит!");
                CuiHelper.DestroyUi(player, "hpbar_background");
                CuiHelper.AddUi(player, json);
           }
        }

        [ChatCommand("gui")]
        void cmdChatGui(BasePlayer player)
        {
            string json = CUI_MAIN
                .Replace("{progress}", "0.5")
                .Replace("{text}", "50");
            CuiHelper.AddUi(player, json);
            timer.Once(5f, () =>
            {
                CuiHelper.DestroyUi(player, "hpbar_background");
            });
        }

        Timer timer;
        
        string CUI_MAIN = @"
            [
  {
    ""name"": ""hpbar_background"",
    ""parent"": ""Overlay"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""material"": """",
        ""color"": ""0.5254902 0.5254902 0.5254902 0.2980392""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0.5 0"",
        ""anchormax"": ""0.5 0"",
        ""offsetmin"": ""-106 86"",
        ""offsetmax"": ""86 112""
      }
    ]
  },
  {
    ""name"": ""hpbar_img"",
    ""parent"": ""hpbar_background"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""sprite"": ""assets/icons/health.png"",
        ""material"": ""assets/icons/iconmaterial.mat"",
        ""color"": ""0.9686275 0.9176471 0.8784314 0.6745098""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""0 1"",
        ""offsetmin"": ""4 4"",
        ""offsetmax"": ""22 -4""
      }
    ]
  },
  {
    ""name"": ""hpbar_wrapper"",
    ""parent"": ""hpbar_background"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""material"": """",
        ""color"": ""1 0.4039216 0.4039216 0""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""1 1"",
        ""offsetmin"": ""25 3"",
        ""offsetmax"": ""-3 -3""
      }
    ]
  },
  {
    ""name"": ""hpbar_progress"",
    ""parent"": ""hpbar_wrapper"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""sprite"": ""assets/content/ui/ui.background.tile.psd"",
        ""material"": """",
        ""color"": ""0.6941177 0.2039216 0.003921569 0.5450981""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""{progress} 1"",
        ""offsetmin"": ""0 0"",
        ""offsetmax"": ""0 0""
      }
    ]
  },
  {
    ""name"": ""hpbar_text"",
    ""parent"": ""hpbar_wrapper"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Text"",
        ""text"": ""{text}"",
        ""fontSize"": 15,
        ""font"": ""robotocondensed-bold.ttf"",
        ""align"": ""MiddleLeft"",
        ""color"": ""0.9686275 0.9176471 0.8784314 0.8945568""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""1 1"",
        ""offsetmin"": ""2 0"",
        ""offsetmax"": ""0 0""
      }
    ]
  }
]
        ";
    }
}
Error while compiling: HealthBar.cs(132,19): error CS1061: Type `Oxide.Plugins.Timer' does not contain a definition for `Once' and no extension method `Once' of type `Oxide.Plugins.Timer' could be found. Are you missing an assembly reference?
 
C#:
using System.Collections.Generic;
using Oxide.Game.Rust.Cui;

namespace Oxide.Plugins
{
    [Info ("Health Bar", "Raskolov", "0.1.0")]

    public class HealthBar : RustPlugin
    {

        public class GuiControl
        {
            private Dictionary<BasePlayer, Timer> _Timers = new Dictionary<BasePlayer, Timer>();

            public readonly PluginTimers _Timer;
            public readonly float destroySeconds;

            public GuiControl(PluginTimers timer, float destroySeconds)
            {
                this._Timer = timer;
                this.destroySeconds = destroySeconds;
            }

            public void TriggerDamage(BasePlayer player, float health, float maxHelth)
            {
                RemovePlayer(player);
                var progressText = health / maxHelth + "";
                var healthText = (int)health + "";
                DrawUI(player, progressText, healthText);
                AddPlayer(player);
            }

            public void TriggerDeath(BasePlayer player, float health, float maxHelth)
            {
                RemovePlayer(player);
                var progressText = "0";
                var healthText = "Убит!";
                DrawUI(player, progressText, healthText);
                AddPlayer(player);
            }

            void AddPlayer(BasePlayer player)
            {
                _Timers[player] = _Timer.Once(_DestroySeconds, () =>
                {
                    RemovePlayer(player);
                });
            }

            void RemovePlayer(BasePlayer player)
            {
                Timer pTimer;
                if (_Timers.TryGetValue(player, out pTimer))
                {
                    _Timer.Destroy(ref pTimer);
                    DestroyUI(player);
                    _Timers.Remove(player);
                }
            }

            void DrawUI (BasePlayer player, string progress, string text)
            {
                string json = CUI_MAIN
                    .Replace("{progress}", progress)
                    .Replace("{text}", text);
                CuiHelper.AddUi(player, json);
            }

            void DestroyUI(BasePlayer player)
            {
                CuiHelper.DestroyUi(player, "hpbar_background");
            }
        }

        GuiControl _GuiControl;


        void Loaded()
        {
              Puts("Loaded");
              var timers = GetLibrary<PluginTimers>();
              timer = timers.GetTimer(this, "HealthBarTimer");
              _GuiControl = new GuiControl(timer, 5f);
        }

        void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
        {
           var player = info.InitiatorPlayer;
           if (player && player.IsAlive())
           {
               NextTick(() =>
               {
                   if (entity.IsAlive() && player?.IsConnected == true)
                   {
                      var health = entity.health;
                      var maxHelth = entity.MaxHealth();

                      var progress = health / maxHelth;
                      var text = (int) health;
                      string json = CUI_MAIN
                          .Replace("{progress}", progress.ToString())
                          .Replace("{text}", text.ToString());
                      CuiHelper.DestroyUi(player, "hpbar_background");
                      CuiHelper.AddUi(player, json);
                   }
               });
           }
        }

        void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
           var player = info.InitiatorPlayer;
           if (player && player.IsAlive())
           {
                string json = CUI_MAIN
                    .Replace("{progress}", "0")
                    .Replace("{text}", "Убит!");
                CuiHelper.DestroyUi(player, "hpbar_background");
                CuiHelper.AddUi(player, json);
           }
        }

        [ChatCommand("gui")]
        void cmdChatGui(BasePlayer player)
        {
            string json = CUI_MAIN
                .Replace("{progress}", "0.5")
                .Replace("{text}", "50");
            CuiHelper.AddUi(player, json);
            timer.Once(5f, () =>
            {
                CuiHelper.DestroyUi(player, "hpbar_background");
            });
        }

        Timer timer;
        
        string CUI_MAIN = @"
            [
  {
    ""name"": ""hpbar_background"",
    ""parent"": ""Overlay"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""material"": """",
        ""color"": ""0.5254902 0.5254902 0.5254902 0.2980392""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0.5 0"",
        ""anchormax"": ""0.5 0"",
        ""offsetmin"": ""-106 86"",
        ""offsetmax"": ""86 112""
      }
    ]
  },
  {
    ""name"": ""hpbar_img"",
    ""parent"": ""hpbar_background"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""sprite"": ""assets/icons/health.png"",
        ""material"": ""assets/icons/iconmaterial.mat"",
        ""color"": ""0.9686275 0.9176471 0.8784314 0.6745098""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""0 1"",
        ""offsetmin"": ""4 4"",
        ""offsetmax"": ""22 -4""
      }
    ]
  },
  {
    ""name"": ""hpbar_wrapper"",
    ""parent"": ""hpbar_background"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""material"": """",
        ""color"": ""1 0.4039216 0.4039216 0""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""1 1"",
        ""offsetmin"": ""25 3"",
        ""offsetmax"": ""-3 -3""
      }
    ]
  },
  {
    ""name"": ""hpbar_progress"",
    ""parent"": ""hpbar_wrapper"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Image"",
        ""sprite"": ""assets/content/ui/ui.background.tile.psd"",
        ""material"": """",
        ""color"": ""0.6941177 0.2039216 0.003921569 0.5450981""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""{progress} 1"",
        ""offsetmin"": ""0 0"",
        ""offsetmax"": ""0 0""
      }
    ]
  },
  {
    ""name"": ""hpbar_text"",
    ""parent"": ""hpbar_wrapper"",
    ""components"": [
      {
        ""type"": ""UnityEngine.UI.Text"",
        ""text"": ""{text}"",
        ""fontSize"": 15,
        ""font"": ""robotocondensed-bold.ttf"",
        ""align"": ""MiddleLeft"",
        ""color"": ""0.9686275 0.9176471 0.8784314 0.8945568""
      },
      {
        ""type"": ""RectTransform"",
        ""anchormin"": ""0 0"",
        ""anchormax"": ""1 1"",
        ""offsetmin"": ""2 0"",
        ""offsetmax"": ""0 0""
      }
    ]
  }
]
        ";
    }
}
Error while compiling: HealthBar.cs(132,19): error CS1061: Type `Oxide.Plugins.Timer' does not contain a definition for `Once' and no extension method `Once' of type `Oxide.Plugins.Timer' could be found. Are you missing an assembly reference?
Ошибка в этом коде заключается в том, что метод Once больше не существует в библиотеке таймеров Oxide, начиная с версии Oxide 2. Метод был заменен на OnceCallback.

Замените строку timer.Once(5f, () =&gt; на timer.OnceCallback(5f, () =&gt; в методе cmdChatGui:

Код:
[Info(&quot;Health Bar&quot;, &quot;Raskolov&quot;, &quot;0.1.0&quot;)]
public class HealthBar : RustPlugin
{
    public class GuiControl
    {
        private Dictionary&lt;BasePlayer, Timer&gt; _Timers = new Dictionary&lt;BasePlayer, Timer&gt;();
        public readonly PluginTimers _Timer;
        public readonly float destroySeconds;
        public GuiControl(PluginTimers timer, float destroySeconds)
        {
            this._Timer = timer;
            this.destroySeconds = destroySeconds;
        }
        // Остальной код без изменений
    }
    GuiControl _GuiControl;
    void Loaded()
    {
        Puts(&quot;Loaded&quot;);
        var timers = GetLibrary&lt;PluginTimers&gt;();
        timer = timers.GetTimer(this, &quot;HealthBarTimer&quot;);
        _GuiControl = new GuiControl(timer, 5f);
    }
    // Остальной код без изменений
    [ChatCommand(&quot;gui&quot;)]
    void cmdChatGui(BasePlayer player)
    {
        string json = CUI_MAIN
            .Replace(&quot;{progress}&quot;, &quot;0.5&quot;)
            .Replace(&quot;{text}&quot;, &quot;50&quot;);
        CuiHelper.AddUi(player, json);
        timer.OnceCallback(5f, () =&gt;
        {
            CuiHelper.DestroyUi(player, &quot;hpbar_background&quot;);
        });
    }
    Timer timer;
    // Остальной код без изменений
}

Теперь код должен успешно скомпилироваться.
 
Активность
Пока никто не печатает сообщение