Guest User

Flooder.cs

a guest
Aug 1st, 2021
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.54 KB | None | 0 0
  1. using ConVar;
  2. using Oxide.Core.Libraries;
  3. using UnityEngine;
  4.  
  5. namespace Oxide.Plugins
  6. {
  7.     [Info("Flooder", "ladyboymaguire", "1.0", ResourceId = 56745)]
  8.     public class Flooder : RustPlugin
  9.     {
  10.         private const string NotAllowed = "You do not have permission to use this method.";
  11.         private const string StartingFlood = "Starting flooding";
  12.         private const string StoppingFlood = "Stopping flooding";
  13.         private const string ResetWaterLevels = "Resetting water levels";
  14.         private const string ErrorOccurred = "Reached end of function. Something went wrong";
  15.  
  16.         private const float DefaultSeconds = 10;
  17.         private const float DefaultHeightIncrement = 0.00001f;
  18.         private const float DefaultMaxHeight = 50f;
  19.  
  20.         private float _seconds = 10;
  21.         private float _heightIncrement = 0.00001f;
  22.         private float _maxHeight = 50f;
  23.         private float _oceanLevel = 0f;
  24.         private Timer activeTimer;
  25.  
  26.         private void RaiseWaterLevel()
  27.         {
  28.             //Raise water level by heightIncrement
  29.             _oceanLevel += _heightIncrement;
  30.             ConVar.Env.oceanlevel = _oceanLevel;
  31.         }
  32.  
  33.         private bool IsAdminOrPlayer(ConsoleSystem.Arg arg)
  34.         {
  35.             if (arg.IsAdmin)
  36.             {
  37.                 return true;
  38.             }
  39.             else if(arg.Player() != null && arg.Player().IsAdmin)
  40.             {
  41.                 return true;
  42.             }
  43.             else
  44.             {
  45.                 return false;
  46.             }
  47.         }
  48.  
  49.         [ConsoleCommand("flooder.pause")]
  50.         void Stop(ConsoleSystem.Arg arg)
  51.         {
  52.             if(!IsAdminOrPlayer(arg))
  53.             {
  54.                 arg.ReplyWith(NotAllowed);
  55.                 return;
  56.             }
  57.             else
  58.             {
  59.                 if (activeTimer != null && !activeTimer.Destroyed)
  60.                 {
  61.                     activeTimer.Destroy();
  62.                 }
  63.                 arg.ReplyWith(StoppingFlood);
  64.                 return;
  65.             }
  66.         }
  67.  
  68.         [Command("flooder.reset")]
  69.         void Reset(ConsoleSystem.Arg arg)
  70.         {
  71.             Set water level to 0
  72.             if (!IsAdminOrPlayer(arg))
  73.             {
  74.                 arg.ReplyWith(NotAllowed);
  75.                return;
  76.             }
  77.             else
  78.             {
  79.                 _seconds = DefaultSeconds;
  80.                 _heightIncrement = DefaultHeightIncrement;
  81.                 _maxHeight = DefaultMaxHeight;
  82.  
  83.                 _oceanLevel = 0;
  84.                 ConVar.Env.oceanlevel = _oceanLevel;
  85.                 arg.ReplyWith(ResetWaterLevels);
  86.                 return;
  87.             }
  88.         }
  89.  
  90.         // Start routine to increase height
  91.         // Argument(s)
  92.         // seconds - how many seconds to wait between increments [DEFAULT = 10]
  93.         // heightIncrement - how much to increase the height by per increment  [DEFAULT = 0.00001]
  94.         // maxHeight - the maximum height to increase the water level to [DEFAULT = 50]
  95.         [Command("flooder.flood")]
  96.         void Start(ConsoleSystem.Arg arg)
  97.         {
  98.             if (!IsAdminOrPlayer(arg))
  99.             {
  100.                 arg.ReplyWith(NotAllowed);
  101.                 return;
  102.             }
  103.             else
  104.             {
  105.                 if (arg.HasArgs(1))
  106.                 {
  107.                     float seconds = arg.GetFloat(0);
  108.                     Puts("Seconds : " + seconds);
  109.                     if (seconds > 0)
  110.                     {
  111.                         _seconds = seconds;
  112.                     }
  113.                 }
  114.                 if (arg.HasArgs(2))
  115.                 {
  116.                     float heightIncrement = arg.GetFloat(1);
  117.                     Puts("Height Increment : " + heightIncrement);
  118.                     if (heightIncrement > 0)
  119.                     {
  120.                         _heightIncrement = heightIncrement;
  121.                     }
  122.                 }
  123.                 if (arg.HasArgs(3))
  124.                 {
  125.                     float maxHeight = arg.GetFloat(2);
  126.                     Puts("Max Height : " + maxHeight);
  127.                     if (maxHeight > 0)
  128.                     {
  129.                         _maxHeight = maxHeight;
  130.                     }
  131.                 }
  132.  
  133.                 if (!activeTimer.Destroyed)
  134.                 {
  135.                     activeTimer.Destroy();
  136.                 }
  137.                 activeTimer = timer.Repeat(_seconds, (int)(_maxHeight / _seconds / _heightIncrement), () => RaiseWaterLevel());
  138.                 return;
  139.             }
  140.  
  141.         }
  142.  
  143.     }
  144. }
  145.  
Advertisement
Add Comment
Please, Sign In to add comment