1. Please read my second post, as my request has changed.

    I was wondering if "base.baseEntity" could be passed in as one of the arguments in the CanCraft hook found in PlayerBlueprints (there's another one found in ItemCrafter with different parameters) so that I can set/get values of the player before the crafting begins.

    Code:
    object[] objArray = new object[] { this, itemDefinition, skinItemId };
            object obj = Interface.CallHook("CanCraft", objArray);
    to...

    Code:
    object[] objArray = new object[] { this, itemDefinition, skinItemId, base.baseEntity };
            object obj = Interface.CallHook("CanCraft", objArray);
    Thanks.
     
    Last edited by a moderator: Jan 29, 2018
  2. OnItemCraft and both CanCraft Hooks aren't called when the crafting actually begins. For instance, if an item is added to a crafting queue, but not actually being crafted, these hooks are still called even and the ItemCraftTask object has not yet been assigned specific values.

    Instead of my original request, I'd like to propose a new hook called OnItemCraftStart, which would go nicely with OnItemCraftCancelled and OnItemCraftFinished. This hook would be called at the exact time of actual crafting. I can suggest the location to put it, as seen below:


    Current code:
    Code:
    ItemCrafter line 330:
     
            float scaledDuration = ItemCrafter.GetScaledDuration(itemCraftTask.blueprint, single);
            itemCraftTask.endTime = Time.realtimeSinceStartup + scaledDuration;
            if (itemCraftTask.owner != null)
            {
                itemCraftTask.owner.Command("note.craft_start", new object[] { itemCraftTask.taskUID, scaledDuration, itemCraftTask.amount });
                if (itemCraftTask.owner.IsAdmin && Craft.instant)
                {
                    itemCraftTask.endTime = Time.realtimeSinceStartup + 1f;
                }
            }
    
    As you can see, this is when the actual crafting time (endTime) is initialized for the item about to begin being crafted

    Below, I've inserted the new code between scaledDuration and the itemCraftTask.endTime initialization so that the duration of the craft can be changed by a reference, which will influence the timer made client side (since it is being passed to the Command method further below), and it will change the time of crafting server side, since endTime is dependant on the value.

    Here's my suggested change:
    Code:
    ItemCrafter line 330:
     
            float scaledDuration = ItemCrafter.GetScaledDuration(itemCraftTask.blueprint, single);
    ►►►►►►►►►object[] objArray = new object[] { itemCraftTask, ref scaledDuration };
    ►►►►►►►►►Interface.CallHook("OnItemCraftStart", objArray);
            itemCraftTask.endTime = Time.realtimeSinceStartup + scaledDuration;
            if (itemCraftTask.owner != null)
            {
                itemCraftTask.owner.Command("note.craft_start", new object[] { itemCraftTask.taskUID, scaledDuration, itemCraftTask.amount });
                if (itemCraftTask.owner.IsAdmin && Craft.instant)
                {
                    itemCraftTask.endTime = Time.realtimeSinceStartup + 1f;
                }
            }
    
    As I see it now, there's no other clean way to change the time it takes to craft an item. Although that is one good purpose of the hook, I'm sure there are others.
     
    Last edited by a moderator: Jan 29, 2018