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.
to...Code:object[] objArray = new object[] { this, itemDefinition, skinItemId }; object obj = Interface.CallHook("CanCraft", objArray);
Thanks.Code:object[] objArray = new object[] { this, itemDefinition, skinItemId, base.baseEntity }; object obj = Interface.CallHook("CanCraft", objArray);
Request New OnItemCraftStart Hook(Rust) - Called at Time of Actual Crafting
Discussion in 'Feature Suggestions' started by Abnormal Zombie, Jan 28, 2018.
-
Could you use this hook instead? -> OnItemCraft(ItemCraftTask item)
Or even this -> CanCraft(ItemCrafter itemCrafter, ItemBlueprint bp, int amount) -
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; } }
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; } }
Last edited by a moderator: Jan 29, 2018