1. I want to know what tool is being used by the player to gather in that hook. I'm looking at the decompiled stuff and I can't figure it out.

    Can anybody help on that one? I'm using C# but anything would help at this point.

    While we're at it.. What I'm trying to do is increase the wood gather rate of the salvaged axe only. I did a first version that simply modifies the gatherDamage on the tool which works fine... Until the server restarts (or it could be player disconnect, haven't confirmed), when I get back in, any tool I crafted that worked fine before logging now has stock gatherDamage (but new ones I make or spawn ARE modified). It's like the changes I make to the tool are not persistent.

    Why are the existing items loosing their modification? Do I need to do something extra when I load the mod or when an item is equipped to reapply the change? I'm confused on that one...

    Doing it through OnGather is a workaround... if I could just make my original code work I'd be happy.

    Any help would be appreciated.
     
  2. [EDIT]The problem you are having seems to be that on default if a player loads in the item values are on default, and newly added items while the player is online has the modified version. You are basically editing the memory value of the item which gets removed when the player goes offline. (If that makes sense)
     
    Last edited by a moderator: Jun 13, 2015
  3. I suppose it does but I'm not sure how I can fix that. I get a reference to the item definition from the game and modify the values. From then on, any newly created tool will have the new value. On the Unload function, I put back the old value, but normally when someone logs off and back in, the plugin shouldn't load/unload so the value should stay to the modified value at all times during the player login/log out process.

    It seems from what I see that the gatherDamage value is copied into the new instance when creating a new tool (either by crafting or spawning). That works fine... but when the game saves that instance of the object (or reloads it), it reverts back to default even though the main definition is changed. It's as if the deserialization somehow took the default value instead of the currently active value for the item in the definition.

    I just don't know how to fix that. That's why I was asking about how to know what tool is used in the OnGather hook. This way I could just not touch the gatherDamage and modify the damage on the fly in the OnGather hook.

    I settled for a very shaky solution for now.. I look at the damage done to the "node" in OnGather and if I get 17-18 or 35-36 on a tree, I assume the player is using the salvaged axe (17-18 for small trees, 35-36 for big ones). It's a ugly patch and it doesn't multiply the last hit... but.. it kinda works until I find better.
     
  4. So OnGather uses the variables ResourceDespenser, BaseEntity, Item...

    Now ResourceDespenser would be the rock or tree or whatever possible Despenser...

    Now to get the persons active item you would do something like this...

    Code:
    string ActiveItemName = entity.ToPlayer().svActiveItem.info.shortname;
    
    Which SHOULD output the current item being held or active item name.... So if the user was using a Salvaged Axe it should output "salvaged_axe" or something along those lines.... Then you can modify the value if ActiveItemName == "salvaged_axe"... At least that would be my assumption...

    Note: this isn't the correct way of doing this... I would do a series of checks...

    Code:
    if(entity != null)
    {
           if(entity.ToPlayer() != null)
           {
                   if(entity.ToPlayer().svActiveItem != null)
                   {
                          if(entity.ToPlayer().svActiveItem.info.shortname == "axe_salvaged")
                          {
                                  // Increase gathered amount here....
                          }
                   }
           }
    }
    
    This will give EVERYONE increased gather rate with the salvaged axe... If you want to make a config file or data file with a list of players who should have access to this then you can add a check if a player has permission and such... But this is just how I would do it.... You should really look into using Telerik JustDecompiler.... Best way I have found to look for Information on how to manipulate things on the fly.
     
    Last edited by a moderator: Jun 15, 2015
  5. Thanks mate, exactly what I wanted. I'll try it out!
     
  6. Glad to help. Let me know if you need any more help.
     
  7. All good it works, just tested it. For the benefit of anyone else reading this the salvaged axe shortname is "axe_salvaged" and not "salvaged_axe" :) Might want to edit that Shadow.
     
  8. Glad it works. And I edited the post.
     
  9. How to make support float values on this hook?
     
  10. I don't think you can gather float values but you can certainly multiply the amount by a float value and then cast the result as an int.
     
  11. Yes, i talking about it. But when i try multiply gathered resources to for example 2.1, 2.2 plugin says can't compile because can't convert float values to int
    When i multiply to 1,2,3 etc all fine. But this is not what i want
     
  12. Put the whole expression you are trying to convert between paranthesis and preceed it with (int) like this:

    int a = (int)(intvalue * 2.25);