OnCupboardProtectionCalculated hook change to modify protect minutesSuggestion
ZugzwangI changed this once using Reflection to make it always say 69 hours. Would be nice to have a simpler way.
Would you mind giving some example code how this could be accomplish using reflection ?
Thanks.
cachedProtectedMinutes field as public so you can change it after it's calculated. I've made a PR. Can probably be merged by next Rust update.https://github.com/OxideMod/Oxide.Rust/pull/265
Testing this out, the
cachedProtectedMinutes is the value that shows in the status bar above the player's health/metabolism, not the amount that shows on the cupboard UI (which seems to be calculated client-side). kasvotonWould you mind giving some example code how this could be accomplish using reflection ?
Thanks.
Something like this. But you're better off waiting for the variable to be exposed as public.
cpm = typeof(BuildingPrivlidge).GetField("cachedProtectedMinutes", BindingFlags.NonPublic | BindingFlags.Instance);
npct = typeof(BuildingPrivlidge).GetField("nextProtectedCalcTime", BindingFlags.NonPublic | BindingFlags.Instance);
cpm.SetValue(toolcupboard, 4140f);
npct.SetValue(toolcupboard, UnityEngine.Time.time + 3024000f);
toolcupboard.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
WhiteThunder
I think the simplest solution here is to just expose thecachedProtectedMinutesfield as public so you can change it after it's calculated. I've made a PR. Can probably be merged by next Rust update.
https://github.com/OxideMod/Oxide.Rust/pull/265
Testing this out, thecachedProtectedMinutesis the value that shows in the status bar above the player's health/metabolism, not the amount that shows on the cupboard UI (which seems to be calculated client-side).
did you change the hook cause the ui is most likley calling CupboardProtectionCalculat so seting the value after the call will not work. as the ui will have already grabed the value.
While testing, I was surprised that the cupboard UI was not updated, but the upkeep UI indicator on the HUD was, so this is evidence that that field only affects the HUD. I also didn't see any other networked fields that appear to correspond to the cupboard UI amount, so the client is likely calculating them based on the cupboard inventory, plus the other networked values that correspond to cvars. Let me know if you have any proof to the contrary and I can take a other look.
Merged post
just gotto add delay to change it after the hook it called i guess.
tc.cachedProtectionMinutues = calculatedAmount;
Interface.Oxide.CallHook("OnCupboardProtectionCalculated", tc, tc.cachedProtectionMinutes);
return tc.cachedProtectionMinutes;
cachedProtectedMinutes is now public so the above recommended approach should work.You can also use the
OnEntitySaved(BuildingPrivlidge, BaseNetworkable.SaveInfo) hook to alter what the user sees independent of the actual value, like below.private void OnEntitySaved(BuildingPrivlidge buildingPrivilege, BaseNetworkable.SaveInfo saveInfo)
{
// Always display 69 hours upkeep time on the HUD, regardless of actual upkeep time
saveInfo.msg.buildingPrivilege.protectedMinutes = 4140;
}
Changing the displayed upkeep in the tool cupboard UI is possible but trickier since the client performs the calculation based on the items it believes are in the tool cupboard inventory. The way to alter this would be to network to the client that there are additional items in the inventory but outside of the visible slots (so the player doesn't see them). If you want some visible items to not be factored into the calculation, that simply isn't possible without visually hiding them, but you can alter saveInfo.msg.buildingPrivilege.protectedMinutes in the above hook based on the items in the container to cause the client to multiply or divide the displayed protection minutes, but this would require copying the game code for upkeep calculation to predict what the client will calculate.