Failed to call hook 'OnItemCraft' on plugin 'CraftingController v3.2.9' (NullReferenceException: Object reference not set to an instance of an object) at Item.OnChanged () [0x0001d] in <3e15ca7896a1410db6d120bc00d1300d>:0
at Item.MarkDirty () [0x00000] in <3e15ca7896a1410db6d120bc00d1300d>:0
at Item.set_maxCondition (System.Single value) [0x00029] in <3e15ca7896a1410db6d120bc00d1300d>:0
at Item.Initialize (ItemDefinition template) [0x00015] in <3e15ca7896a1410db6d120bc00d1300d>:0
at ItemManager.Create (ItemDefinition template, System.Int32 iAmount, System.UInt64 skin) [0x00065] in <3e15ca7896a1410db6d120bc00d1300d>:0
at Oxide.Plugins.CraftingController.InstantBulkCraft (BasePlayer player, ItemCraftTask task, ItemDefinition item, System.Collections.Generic.List`1[T] stacks, System.Int32 craftSkin, System.UInt64 skin) [0x00028] in <29db957461e04c27a247a5acfa71ea9f>:0
at Oxide.Plugins.CraftingController.OnItemCraft (ItemCraftTask task, BasePlayer player) [0x000d4] in <29db957461e04c27a247a5acfa71ea9f>:0
at Oxide.Plugins.CraftingController.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x0022a] in <29db957461e04c27a247a5acfa71ea9f>:0
at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <87ce9ac9776a48658bc55eae6debe38b>:0
at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <18d4f19bbc844191b11ed9e69284d09b>:0
at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <18d4f19bbc844191b11ed9e69284d09b>:0
I am looking into this to see what to do to fix it. Maybe youll get it before me haha or have an idea.
Onitemcraft hook error.
Does it happen often if so I can give you a debug version
I ended up fixing the onitemcraft. It is now not giving the issue. Just wanted to let you know. It was doing it every time anyone crafted something. I was away for a bit and apoligize for not getting back sooner.
Do you know what was causing the issue ?
private object OnItemCraft(ItemCraftTask task, BasePlayer player)
{
var target = task.blueprint.targetItem;
if (task == null || task?.instanceData?.dataInt != null || task?.amount == 0) return null;
var stacks = GetStacks(target, task.amount * task.blueprint.amountToCreate);
ulong defaultskin = 0uL;
int freeslots = FreeSlots(player);
bool f = false;
if (!config.FullInventory && stacks.Count >= freeslots)
{
f = true;
int space = FreeSpace(player, target);
if (space < 1)
{
ReturnCraft(task, player);
return false;
}
int taskamt = task.amount * task.blueprint.amountToCreate;
for (int i = 0; i < 20 && taskamt > space; i++)
{
var oldtaskamt = taskamt;
taskamt = space;
foreach (var item in task.takenItems)
{
var itemtogive = item;
double fraction = (double)taskamt / (double)oldtaskamt;
int amttogive = (int)(item.amount * (1 - fraction));
if (amttogive <= 1)
{
ReturnCraft(task, player);
return false;
}
itemtogive = ItemManager.Create(item.info, amttogive, 0uL);
item.amount -= amttogive;
player.GiveItem(itemtogive);
}
space -= (freeslots - FreeSlots(player)) * target.stackable;
if (space < 1 || taskamt < 1)
{
ReturnCraft(task, player);
return false;
}
if (taskamt <= space) break;
}
task.amount = (int)(taskamt / task.blueprint.amountToCreate);
}
if (task.skinID == 0)
{
CraftingData data;
if (config.CraftingOptions.TryGetValue(target.shortname, out data))
{
defaultskin = data.defaultskinid;
}
if (config.RandomSkins && defaultskin == 0)
{
List<ulong> skins = GetSkins(ItemManager.FindItemDefinition(target.itemid));
defaultskin = skins.GetRandom();
}
if (defaultskin > 999999)
skinupdate[task] = defaultskin;
else
task.skinID = (int)defaultskin;
}
float bonusperm_time = float.MaxValue;
foreach (var bonusperm in permissionsBonusMultiplier)
{
if (!HasPerm(player.UserIDString, $"{bonusperm}")) continue;
if (bonusperm_time < (float)config.BonusMultiplier[bonusperm.Split('.')[1]]) continue;
bonusperm_time = (float)config.BonusMultiplier[bonusperm.Split('.')[1]];
}
if(bonusperm_time != float.MaxValue)
{
task.blueprint = UnityEngine.Object.Instantiate(task.blueprint);
task.blueprint.time *= bonusperm_time / 100;
}
if (task.blueprint.time == 0f || HasPerm(player.UserIDString, perminstantbulkcraft))
{
skinupdate.Remove(task);
if (f)
stacks = GetStacks(target, task.amount * task.blueprint.amountToCreate);
InstantBulkCraft(player, task, target, stacks, task.skinID, defaultskin);
task.cancelled = true;
return false;
}
return null;
}
This is what I ended up doing. This fixed it.
Merged post
Sorry for late replies.. Life has been hell atm.