1. 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?
     
  2. I don't think it would be possible doing this from within the OnItemCraft hook. Another thing you could look into is the plugin ItemConfig. I'm not entirely sure right now if it will allow you to successfully modify it, but it's worth a shot.
     
  3. 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?
     
  4. Every Item is created with the settings in the corresponding ItemDefinition so it would change it for every weapon of a single type. If you want to do it on individual items the easiest way is by modifying the amount of condition that is lost by using the new OnLoseCondition(Item item, ref float amount) hook. The usage of the hook is a bit language dependent however as the ref float amount is only of real use for C#, modifying the amount in another language won't do anything but you can modify the condition on the weapon however at that point to reduce the amount of condition is lost eventually.
     
  5. 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?
     
  6. It's how Rust works with the item conditions and the crafting, when you craft something it is crafted based on the definition of the item you craft and the hook that is available (OnItemCraft) is a pre-hook which means that the hook runs before the item actually starts crafting. It might be possible by adding a post-hook that triggers when the craft completes which would allow you to do what you want. I'll try to look into it at some point this weekend when I'm able to.
     
  7. @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)
    To alter the maximum condition of the item you will most likely need to use reflection to alter the value of the private field _maxCondition. I haven't done a lot of tries but modifications to item.info.condition.max seemed to be pointless and the property item.maxCondition cannot exceed item.info.condition.max. So using reflection to alter _maxCondition should avoid this limitation.
     
  8. This requires that I use C#? Would it be technically feasible to have Oxide recognize private property mutation and do the necessary reflection using some sort of convention? For example, any property that is mutated with an underscore _ as the first character uses Reflection and not the standard mutator?
     
  9. You don't necessarily need to use C# to use reflection, it's also possible to do with Lua plugins. And regarding properties with an underscore, it rarely happens actually that the private properties have an underscore in Assembly-CSharp.dll, haven't seen those a lot to be honest.
     
  10. I hate to keep bugging you about this.

    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.
     
  11. Calytic

    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);
    How would do this in JavaScript on a BuildingBlock health or Item durability?
     
  12. Calytic

    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);
     
  13. How do I get current condition of an item?

    And how do I create a new item with that condition level?

    Anyone?

    Thanks!
     
  14. 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