Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using ConVar;
- using Oxide.Core.Libraries;
- 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 string ErrorOccurred = "Reached end of function. Something went wrong";
- private const float DefaultSeconds = 10;
- private const float DefaultHeightIncrement = 0.00001f;
- private const float DefaultMaxHeight = 50f;
- private float _seconds = 10;
- private float _heightIncrement = 0.00001f;
- private float _maxHeight = 50f;
- private float _oceanLevel = 0f;
- private Timer activeTimer;
- private void RaiseWaterLevel()
- {
- //Raise water level by heightIncrement
- _oceanLevel += _heightIncrement;
- ConVar.Env.oceanlevel = _oceanLevel;
- }
- private bool IsAdminOrPlayer(ConsoleSystem.Arg arg)
- {
- if (arg.IsAdmin)
- {
- return true;
- }
- else if(arg.Player() != null && arg.Player().IsAdmin)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- [ConsoleCommand("flooder.pause")]
- void Stop(ConsoleSystem.Arg arg)
- {
- if(!IsAdminOrPlayer(arg))
- {
- arg.ReplyWith(NotAllowed);
- return;
- }
- else
- {
- if (activeTimer != null && !activeTimer.Destroyed)
- {
- activeTimer.Destroy();
- }
- arg.ReplyWith(StoppingFlood);
- return;
- }
- }
- [Command("flooder.reset")]
- void Reset(ConsoleSystem.Arg arg)
- {
- Set water level to 0
- if (!IsAdminOrPlayer(arg))
- {
- arg.ReplyWith(NotAllowed);
- return;
- }
- else
- {
- _seconds = DefaultSeconds;
- _heightIncrement = DefaultHeightIncrement;
- _maxHeight = DefaultMaxHeight;
- _oceanLevel = 0;
- ConVar.Env.oceanlevel = _oceanLevel;
- arg.ReplyWith(ResetWaterLevels);
- return;
- }
- }
- // Start routine to increase height
- // Argument(s)
- // seconds - how many seconds to wait between increments [DEFAULT = 10]
- // heightIncrement - how much to increase the height by per increment [DEFAULT = 0.00001]
- // maxHeight - the maximum height to increase the water level to [DEFAULT = 50]
- [Command("flooder.flood")]
- void Start(ConsoleSystem.Arg arg)
- {
- if (!IsAdminOrPlayer(arg))
- {
- arg.ReplyWith(NotAllowed);
- return;
- }
- else
- {
- if (arg.HasArgs(1))
- {
- float seconds = arg.GetFloat(0);
- Puts("Seconds : " + seconds);
- if (seconds > 0)
- {
- _seconds = seconds;
- }
- }
- if (arg.HasArgs(2))
- {
- float heightIncrement = arg.GetFloat(1);
- Puts("Height Increment : " + heightIncrement);
- if (heightIncrement > 0)
- {
- _heightIncrement = heightIncrement;
- }
- }
- if (arg.HasArgs(3))
- {
- float maxHeight = arg.GetFloat(2);
- Puts("Max Height : " + maxHeight);
- if (maxHeight > 0)
- {
- _maxHeight = maxHeight;
- }
- }
- if (!activeTimer.Destroyed)
- {
- activeTimer.Destroy();
- }
- activeTimer = timer.Repeat(_seconds, (int)(_maxHeight / _seconds / _heightIncrement), () => RaiseWaterLevel());
- return;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment