Solved Editing metabolism rate manually?
Discussion in 'Rust Development' started by Mheetu, Sep 29, 2016.
-
Yes, here's an example of adding 500 calories:
Code:player.metabolism.calories.Add(500);
-
Actually, I think I misunderstood what OnRunPlayerMetabolism does... Does it run once on connection or is it an override method that allows me to define my own metabolism method?
Basically, what I'm wanting to do is pause the effects of the metabolism under a certain condition... would simply returning from this hook accomplish that? If so, how would I resume default behavior when such a condition is false? -
Wulf Community Admin
OnRunPlayerMetabolism is a hook that is called whenever the metabolism changes on a player, usually when running. If you want to "pause" or cancel it, just return a non-null value (usually true or false). -
Not sure what I'm doing wrong, according to the docs, returning true will cancel the update... so I'd assume returning false would let it behave normally. However, the follow code seems to cancel the update no matter the returned value.
Code:void OnRunPlayerMetabolism(PlayerMetabolism metabolism, BaseCombatEntity entity) { var player = entity.ToPlayer(); if (player == null) return false; SendReply(player, metabolism.calories.value.ToString()); if (condition) { // Lock thirst/hunger, don't change it. return true; } else { // Proceed normally with default metabolism. return false; } }Last edited by a moderator: Sep 29, 2016 -
To my understanding:
Correct me if im wrongCode:object OnRunPlayerMetabolism(PlayerMetabolism metabolism, BaseCombatEntity entity) { var player = entity.ToPlayer(); if (player == null) return null; SendReply(player, metabolism.calories.value.ToString()); if (condition) { // Lock thirst/hunger, don't change it. return true; //(or false) } else { // Proceed normally with default metabolism. return null; } } -
Ahh, that works... Perhaps the docs should be a bit more clear on that.
Thanks everyone for the help!
-
Well they are accurate for calling the function, but if you require to return something you need to assign it correctly.
Just a question, how much experience have you had with C#?
