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.
Solved What tool is used in OnGather?
Discussion in 'Rust Development' started by Deicide666ra, Jun 13, 2015.
-
[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 -
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. -
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;
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.... } } } }
Last edited by a moderator: Jun 15, 2015 -
Thanks mate, exactly what I wanted. I'll try it out!
-
Glad to help. Let me know if you need any more help.
-
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.
-
-
How to make support float values on this hook?
-
-
When i multiply to 1,2,3 etc all fine. But this is not what i want -
Put the whole expression you are trying to convert between paranthesis and preceed it with (int) like this:
int a = (int)(intvalue * 2.25);