Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- namespace Oxide.Plugins
- {
- [Info("Flooder", "ladyboymaguire", "1.0", ResourceId = 56745)]
- public class Flooder : RustPlugin
- {
- private const string NotAllowed = "You do not have permission to use this method.";
- private const string StartingFlood = "Starting flooding";
- private const string StoppingFlood = "Stopping flooding";
- private const string ResetWaterLevels = "Resetting water levels";
- private const int DefaultFloodDurationInSeconds = 604800; // 7 days
- private const int DefaultIntervalDurationInSeconds = 3600; // 1 hour
- private const float DefaultHeightIncrement = 0.005f;
- private const float DefaultMaxHeight = 30f;
- private int _floodDurationInSeconds;
- private int _intervalDurationInSeconds;
- private float _heightIncrement;
- private float _maxHeight;
- private float _oceanLevel;
- private Timer activeTimer;
- void Init()
- {
- _heightIncrement = DefaultHeightIncrement;
- _maxHeight = DefaultMaxHeight;
- _floodDurationInSeconds = DefaultFloodDurationInSeconds;
- _intervalDurationInSeconds = DefaultIntervalDurationInSeconds;
- _oceanLevel = 0f;
- }
- private void RaiseWaterLevel()
- {
- //Raise water level by heightIncrement
- _oceanLevel += _heightIncrement;
- rust.RunServerCommand("env.oceanlevel", _oceanLevel);
- }
- private bool IsAdminOrPlayerAdmin(ConsoleSystem.Arg arg)
- {
- if (arg.IsAdmin)
- {
- return true;
- }
- else if(arg.Player() != null && arg.Player().IsAdmin)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- [ConsoleCommand("flooder.max")]
- void FloodMax(ConsoleSystem.Arg arg)
- {
- if (!IsAdminOrPlayerAdmin(arg))
- {
- arg.ReplyWith(NotAllowed);
- return;
- }
- else
- {
- rust.RunServerCommand("env.oceanlevel", _maxHeight);
- arg.ReplyWith("Set Ocean Level to " + _maxHeight);
- return;
- }
- }
- [ConsoleCommand("flooder.pause")]
- void Pause(ConsoleSystem.Arg arg)
- {
- if (!IsAdminOrPlayerAdmin(arg))
- {
- arg.ReplyWith(NotAllowed);
- return;
- }
- else
- {
- if (activeTimer != null && !activeTimer.Destroyed)
- {
- activeTimer.Destroy();
- }
- arg.ReplyWith(StoppingFlood);
- return;
- }
- }
- [ConsoleCommand("flooder.reset")]
- void Reset(ConsoleSystem.Arg arg)
- {
- //Set water level to 0
- if (!IsAdminOrPlayerAdmin(arg))
- {
- arg.ReplyWith(NotAllowed);
- return;
- }
- else
- {
- _floodDurationInSeconds = DefaultFloodDurationInSeconds;
- _heightIncrement = DefaultHeightIncrement;
- _maxHeight = DefaultMaxHeight;
- _oceanLevel = 0;
- if (activeTimer != null && !activeTimer.Destroyed)
- {
- activeTimer.Destroy();
- }
- rust.RunServerCommand("env.oceanlevel", 0);
- arg.ReplyWith(ResetWaterLevels);
- return;
- }
- }
- // Argument(s)
- // Duration to flood, usually the duration of a wipe, in days. DEFAULT = 7
- // Duration between increments in seconds. Setting too low will badly affect server performance. DEFAULT = 3600
- // Maximum height to flood to. DEFAULT = 30
- [ConsoleCommand("flooder.flood")]
- void FloodOverWipe(ConsoleSystem.Arg arg)
- {
- if (!IsAdminOrPlayerAdmin(arg))
- {
- Puts(NotAllowed);
- arg.ReplyWith(NotAllowed);
- return;
- }
- else
- {
- if (arg.HasArgs(1))
- {
- int durationInDays = arg.GetInt(0);
- if (durationInDays > 0)
- {
- _floodDurationInSeconds = durationInDays * 24 * 60 * 60;
- }
- }
- if (arg.HasArgs(2))
- {
- int intervalInSeconds = arg.GetInt(1);
- if (intervalInSeconds > 0)
- {
- _intervalDurationInSeconds = intervalInSeconds;
- }
- }
- if (arg.HasArgs(3))
- {
- float maxHeight = arg.GetFloat(2);
- if (maxHeight > 0)
- {
- _maxHeight = maxHeight;
- }
- }
- if(activeTimer != null && !activeTimer.Destroyed)
- {
- activeTimer.Destroy();
- }
- int increments = _floodDurationInSeconds / _intervalDurationInSeconds;
- _heightIncrement = _maxHeight / increments;
- activeTimer = timer.Repeat(_intervalDurationInSeconds, increments, () => RaiseWaterLevel());
- arg.ReplyWith(StartingFlood + $". Increasing oceanLevel by {_heightIncrement} every {_intervalDurationInSeconds} seconds over {increments} intervals, up to a height of {_maxHeight}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment