C#:
/*
* <----- End-User License Agreement ----->
* Copyright © 2024 Iftebinjan
* Devoloper: Iftebinjan (Contact: https://discord.gg/HFaGs8YwsH)
*
* You may not copy, modify, merge, publish, distribute, sublicense, or sell copies of This Software without the Developer’s consent
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*
*/
using Facepunch;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("MixingSpeed", "ifte", "1.0.0")]
[Description("Change the speed of mixing table")]
public class MixingSpeed : RustPlugin
{
/*------------------------------------
*
* MixingSpeed by Ifte
* Support: https://discord.gg/cCWadjcapr
* Fiverr: https://www.fiverr.com/s/e2pkYY
* Eror404 not found
*
-------------------------------------*/
private Configuration config;
private class Configuration
{
[JsonProperty(PropertyName = "Mixing Table Default Speed in percentage(Increase to reduce mixing time)")]
public float MixingTableSpeed { get; set; }
[JsonProperty("Permission-based speed in percentage(Increase to reduce mixing time)", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public SortedDictionary<string, float> PermissionSpeed { get; set; }
public VersionNumber Version { get; set; }
}
private Configuration GetBaseConfig()
{
return new Configuration
{
MixingTableSpeed = 1f,
PermissionSpeed = new SortedDictionary<string, float>
{
["mixingspeed.vip"] = 10f,
["mixingspeed.premium"] = 15f,
["mixingspeed.deluxe"] = 20f,
["mixingspeed.elite"] = 25f,
["mixingspeed.archon"] = 30f
},
Version = Version
};
}
protected override void LoadDefaultConfig()
=> config = GetBaseConfig();
protected override void LoadConfig()
{
base.LoadConfig();
config = Config.ReadObject<Configuration>();
if (config.Version < Version)
UpdateConfigValues();
Config.WriteObject(config, true);
}
protected override void SaveConfig()
=> Config.WriteObject(config, true);
private void UpdateConfigValues()
{
PrintWarning("Your config file is outdated! Updating config values...");
config.Version = Version;
PrintWarning("Config updated!");
}
private void Init()
{
foreach(var perm in config.PermissionSpeed)
permission.RegisterPermission(perm.Key, this);
}
private void OnMixingTableToggle(MixingTable mixingTable, BasePlayer player)
{
if (mixingTable == null || player == null) return;
float adjustmentFactor = 1f;
foreach (var perm in config.PermissionSpeed)
{
if (permission.UserHasPermission(player.UserIDString, perm.Key))
{
adjustmentFactor = 1f - (perm.Value / 100f);
break; //Apply the first matching permission and stop checking further or.......................}
}
if (Mathf.Approximately(adjustmentFactor, 1f))
{
adjustmentFactor = 1f - (config.MixingTableSpeed / 100f);
}
NextTick(() =>
{
if (mixingTable.IsOn())
{
float originalTime = mixingTable.RemainingMixTime;
mixingTable.RemainingMixTime = Mathf.Max(originalTime * adjustmentFactor, 1f);
}
});
}
}
}