WoodBurner was compiled successfully in 1653ms
Loaded plugin Wood Burner v1.0.0 by Austin9675
I Dont see nothing wrong off hand but that timer is going to cause some laggin issues i would log all furnaces on init and when placed to a list to loop threw
using System.Collections.Generic;
using Oxide.Core.Plugins;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("Wood Burner", "Austin9675", "1.0.0")]
[Description("Burns 1 wood per tick to cook 10 ore.")]
public class WoodBurner : RustPlugin
{
private const int WoodPerTick = 1;
private const int OrePerTick = 10;
private void OnServerInitialized()
{
timer.Every(1f, () =>
{
foreach (var entity in BaseNetworkable.serverEntities)
{
var oven = entity as BaseOven;
if (oven != null && oven.IsOn())
{
ConsumeWoodAndCook(oven.inventory);
}
}
});
}
private void ConsumeWoodAndCook(ItemContainer container)
{
var woodItem = container.GetAmount(1443579727, false);
if (woodItem >= WoodPerTick)
{
container.Take(null, 1443579727, WoodPerTick);
CookOre(container);
}
}
private void CookOre(ItemContainer container)
{
var oreItems = new Dictionary<int, int> { { -1059362949, 1970616650 }, { 889398893, 889398893 } };
foreach (var oreItem in oreItems)
{
int oreAmount = container.GetAmount(oreItem.Key, false);
if (oreAmount >= OrePerTick)
{
container.Take(null, oreItem.Key, OrePerTick);
container.AddItem(ItemManager.FindItemDefinition(oreItem.Value), OrePerTick);
}
}
}
}
}
Merged postHere is an example of a better way to loop.
using System.Collections.Generic;
using Oxide.Core.Plugins;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("Wood Burner", "Austin9675", "1.0.0")]
[Description("Burns 1 wood per tick to cook 10 ore.")]
public class WoodBurner : RustPlugin
{
private const int WoodPerTick = 1;
private const int OrePerTick = 10;
private List<BaseOven> _allOvens = new List<BaseOven>();
private void OnServerInitialized()
{
foreach (BaseNetworkable entity in BaseNetworkable.serverEntities)
{
if (entity != null && entity is BaseOven)
{
_allOvens.Add((entity as BaseOven));
}
}
timer.Every(1f, () =>
{
foreach (BaseOven oven in _allOvens)
{
if (oven != null && oven.IsOn())
{
ConsumeWoodAndCook(oven.inventory);
}
}
});
}
private void OnEntityBuilt(Planner plan, GameObject gameObject)
{
BaseOven baseOven = gameObject.GetComponent<BaseOven>();
if (baseOven != null && _allOvens.Contains(baseOven))
_allOvens.Add(baseOven);
}
private void ConsumeWoodAndCook(ItemContainer container)
{
var woodItem = container.GetAmount(1443579727, false);
if (woodItem >= WoodPerTick)
{
container.Take(null, 1443579727, WoodPerTick);
CookOre(container);
}
}
private void CookOre(ItemContainer container)
{
var oreItems = new Dictionary<int, int> { { -1059362949, 1970616650 }, { 889398893, 889398893 } };
foreach (var oreItem in oreItems)
{
int oreAmount = container.GetAmount(oreItem.Key, false);
if (oreAmount >= OrePerTick)
{
container.Take(null, oreItem.Key, OrePerTick);
container.AddItem(ItemManager.FindItemDefinition(oreItem.Value), OrePerTick);
}
}
}
}
}