Guest User

Untitled

a guest
Aug 2nd, 2021
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.75 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. namespace Oxide.Plugins
  4. {
  5. [Info("Flooder", "ladyboymaguire", "1.0", ResourceId = 56745)]
  6. public class Flooder : RustPlugin
  7. {
  8. private const string NotAllowed = "You do not have permission to use this method.";
  9. private const string StartingFlood = "Starting flooding";
  10. private const string StoppingFlood = "Stopping flooding";
  11. private const string ResetWaterLevels = "Resetting water levels";
  12.  
  13. private const int DefaultFloodDurationInSeconds = 604800; // 7 days
  14. private const int DefaultIntervalDurationInSeconds = 3600; // 1 hour
  15. private const float DefaultHeightIncrement = 0.005f;
  16. private const float DefaultMaxHeight = 30f;
  17.  
  18. private int _floodDurationInSeconds;
  19. private int _intervalDurationInSeconds;
  20. private float _heightIncrement;
  21. private float _maxHeight;
  22. private float _oceanLevel;
  23. private Timer activeTimer;
  24.  
  25. void Init()
  26. {
  27. _heightIncrement = DefaultHeightIncrement;
  28. _maxHeight = DefaultMaxHeight;
  29. _floodDurationInSeconds = DefaultFloodDurationInSeconds;
  30. _intervalDurationInSeconds = DefaultIntervalDurationInSeconds;
  31. _oceanLevel = 0f;
  32. }
  33.  
  34. private void RaiseWaterLevel()
  35. {
  36. //Raise water level by heightIncrement
  37. _oceanLevel += _heightIncrement;
  38.  
  39. rust.RunServerCommand("env.oceanlevel", _oceanLevel);
  40. }
  41.  
  42. private bool IsAdminOrPlayerAdmin(ConsoleSystem.Arg arg)
  43. {
  44. if (arg.IsAdmin)
  45. {
  46. return true;
  47. }
  48. else if(arg.Player() != null && arg.Player().IsAdmin)
  49. {
  50. return true;
  51. }
  52. else
  53. {
  54. return false;
  55. }
  56. }
  57.  
  58. [ConsoleCommand("flooder.max")]
  59. void FloodMax(ConsoleSystem.Arg arg)
  60. {
  61. if (!IsAdminOrPlayerAdmin(arg))
  62. {
  63. arg.ReplyWith(NotAllowed);
  64. return;
  65. }
  66. else
  67. {
  68. rust.RunServerCommand("env.oceanlevel", _maxHeight);
  69. arg.ReplyWith("Set Ocean Level to " + _maxHeight);
  70. return;
  71. }
  72. }
  73.  
  74. [ConsoleCommand("flooder.pause")]
  75. void Pause(ConsoleSystem.Arg arg)
  76. {
  77. if (!IsAdminOrPlayerAdmin(arg))
  78. {
  79. arg.ReplyWith(NotAllowed);
  80. return;
  81. }
  82. else
  83. {
  84. if (activeTimer != null && !activeTimer.Destroyed)
  85. {
  86. activeTimer.Destroy();
  87. }
  88. arg.ReplyWith(StoppingFlood);
  89. return;
  90. }
  91. }
  92.  
  93. [ConsoleCommand("flooder.reset")]
  94. void Reset(ConsoleSystem.Arg arg)
  95. {
  96. //Set water level to 0
  97. if (!IsAdminOrPlayerAdmin(arg))
  98. {
  99. arg.ReplyWith(NotAllowed);
  100. return;
  101. }
  102. else
  103. {
  104. _floodDurationInSeconds = DefaultFloodDurationInSeconds;
  105. _heightIncrement = DefaultHeightIncrement;
  106. _maxHeight = DefaultMaxHeight;
  107.  
  108. _oceanLevel = 0;
  109.  
  110. if (activeTimer != null && !activeTimer.Destroyed)
  111. {
  112. activeTimer.Destroy();
  113. }
  114.  
  115. rust.RunServerCommand("env.oceanlevel", 0);
  116.  
  117. arg.ReplyWith(ResetWaterLevels);
  118. return;
  119. }
  120. }
  121.  
  122. // Argument(s)
  123. // Duration to flood, usually the duration of a wipe, in days. DEFAULT = 7
  124. // Duration between increments in seconds. Setting too low will badly affect server performance. DEFAULT = 3600
  125. // Maximum height to flood to. DEFAULT = 30
  126. [ConsoleCommand("flooder.flood")]
  127. void FloodOverWipe(ConsoleSystem.Arg arg)
  128. {
  129. if (!IsAdminOrPlayerAdmin(arg))
  130. {
  131. Puts(NotAllowed);
  132. arg.ReplyWith(NotAllowed);
  133. return;
  134. }
  135. else
  136. {
  137. if (arg.HasArgs(1))
  138. {
  139. int durationInDays = arg.GetInt(0);
  140. if (durationInDays > 0)
  141. {
  142. _floodDurationInSeconds = durationInDays * 24 * 60 * 60;
  143. }
  144. }
  145. if (arg.HasArgs(2))
  146. {
  147. int intervalInSeconds = arg.GetInt(1);
  148. if (intervalInSeconds > 0)
  149. {
  150. _intervalDurationInSeconds = intervalInSeconds;
  151. }
  152. }
  153. if (arg.HasArgs(3))
  154. {
  155. float maxHeight = arg.GetFloat(2);
  156. if (maxHeight > 0)
  157. {
  158. _maxHeight = maxHeight;
  159. }
  160. }
  161.  
  162. if(activeTimer != null && !activeTimer.Destroyed)
  163. {
  164. activeTimer.Destroy();
  165. }
  166.  
  167. int increments = _floodDurationInSeconds / _intervalDurationInSeconds;
  168. _heightIncrement = _maxHeight / increments;
  169.  
  170. activeTimer = timer.Repeat(_intervalDurationInSeconds, increments, () => RaiseWaterLevel());
  171. arg.ReplyWith(StartingFlood + $". Increasing oceanLevel by {_heightIncrement} every {_intervalDurationInSeconds} seconds over {increments} intervals, up to a height of {_maxHeight}");
  172. }
  173. }
  174.  
  175. }
  176. }
  177.  
Advertisement
Add Comment
Please, Sign In to add comment