using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Configuration;
using System.Collections.Generic;
namespace Oxide.Plugins
{
[Info("SpeedSmelt", "YourName", "1.0.0")]
class SpeedSmelt : RustPlugin
{
private DynamicConfigFile configData;
private Dictionary<string, float> resourceSpeeds = new Dictionary<string, float>();
private void LoadDefaultConfig()
{
Config["Resources"] = new Dictionary<string, float>
{
{"metal.ore", 2.0},
{"sulfur.ore", 1.5},
{"wood", 1.0}
// Добавьте сюда другие ресурсы и их скорости плавки по умолчанию
};
}
private void Init()
{
configData = Interface.Oxide.DataFileSystem.GetFile("SpeedSmeltConfig");
LoadDefaultConfig();
LoadConfigValues();
LoadCommands();
}
private void LoadConfigValues()
{
resourceSpeeds = configData.ReadObject<Dictionary<string, float>>();
}
private void SaveConfigValues()
{
configData.WriteObject(resourceSpeeds);
}
private void SetSmeltSpeed(BaseOven oven, Item item)
{
string itemName = item.info.shortname;
if (resourceSpeeds.ContainsKey(itemName))
{
oven.cookingFraction *= resourceSpeeds[itemName];
}
}
void OnServerInitialized()
{
foreach (BaseOven oven in BaseOven.ovenList)
{
foreach (Item item in oven.inventory.itemList)
{
SetSmeltSpeed(oven, item);
}
oven.SendNetworkUpdateImmediate();
}
}
void OnEntitySpawned(BaseNetworkable entity)
{
BaseOven oven = entity.GetComponent<BaseOven>();
if (entity != null)
{
foreach (Item item in oven.inventory.itemList)
{
SetSmeltSpeed(oven, item);
}
oven.SendNetworkUpdateImmediate();
}
}
void Unload()
{
SaveConfigValues();
}
private void LoadCommands()
{
permission.RegisterPermission("speedsmelt.admin", this);
cmd.AddChatCommand("setsmeltspeed", this, "CmdSetSmeltSpeed");
}
private void CmdSetSmeltSpeed(BasePlayer player, string command, string[] args)
{
if (!permission.UserHasPermission(player.UserIDString, "speedsmelt.admin"))
{
SendReply(player, "You don't have permission to use this command.");
return;
}
if (args.Length < 2)
{
SendReply(player, "Usage: /setsmeltspeed <resource> <speed>");
return;
}
string resource = args[0];
float speed;
if (!float.TryParse(args[1], out speed))
{
SendReply(player, "Speed must be a number.");
return;
}
if (resourceSpeeds.ContainsKey(resource))
{
resourceSpeeds[resource] = speed;
SaveConfigValues();
SendReply(player, $"Speed for resource {resource} set to {speed}.");
}
else
{
SendReply(player, $"Resource {resource} not found in config.");
}
}
}
}