Hello,
I've searched the forums, scoured through the API, looked through existing mods and can't find anything to this effect.
I want to increase the maximum durability of an item when it is crafted.
Something like this..
OnItemCraft(task) {
task.blueprint.targetItem.condition.max = task.blueprint.targetItem.condition.max + 50;
}
How would I go about doing this if it is even possible?
Increase max durability on craft
Discussion in 'Rust Development' started by Your Old Best Friend, Apr 3, 2015.
-
-
I see how you are increasing the maximum durability on the item definition but is it possible on individual item instances?
Or are the definitions instanced as well? -
-
That is good information but I'm still at an impasse. I don't want to change the item definition. I don't want to change how condition is lost on every item. Only individual items crafted by specific individuals. The only solution I can conceive is to watch OnItemAddedToContainer after an OnItemCraft for the same owner/itemdef. That is not perfect because if a player moves an item of the same type that they are crafting into their inventory while I am waiting for crafting completion, that non-crafted item will get the durability bonus.
Should I submit an issue about this or is it intended? -
-
@Your Old Best Friend, sorry it took me a bit longer to get to this but I've just opened PR #289 that will implement a hook that's triggered when the item craft task has completed and the item has been given to the player (or dropped on the ground in case of a full inventory).
Code:void OnItemCraftFinished(ItemCraftTask task, Item item)
-
-
-
Regardless if the property is defined using an underscore, you could parse the mutator expression (with underscore) and check for private properties (with or without) the underscore? Anyway, it is not very important but it would be nice sugar.
With respect to access of assemblies from the scripting environment, are there any resources that outline and give examples to do this consistently? I see some mods do this occasionally with the "global" keyword but none are JavaScript and implementations seem to vary per environment. I would love documentation on this. -
Calytic Community Admin Community Mod
I'm guessing there isn't any documentation so let us attempt to settle it. The suggested method for setting a private property through reflection is this.
Code:typeof(Foo) .GetField("bar",BindingFlags.Instance|BindingFlags.NonPublic).SetValue(foo,567);
-
Calytic Community Admin Community Mod
Alright, here is the information for anyone searching for this later..
Code:var conditionfield = item.GetType().GetField("_maxCondition", rust.PrivateBindingFlag()); var maxcondition= conditionfield.GetValue(item);
-
How do I get current condition of an item?
And how do I create a new item with that condition level?
Anyone?
Thanks! -
Last I checked item.condition or item.conditionNormalized I can't remember which one, can be used to get and set. I do it in EventManager if you want to look