summerscorcher Posted July 18, 2022 Share Posted July 18, 2022 (edited) Hello Klei, I've got a problem. My character has component variables that save/load a pretty essential part of her kit, which is gained as you use her perks over time (as in, unlockables). When recovering from Wonkey, the custom component is reset, including saved variables. You might understand this is problematic for something that is in essence unavoidable. When looking in the code, the methods for saving/rerolling character stats before and after Wonkey are as follows (in player_common.lua): Spoiler -------------------------------------------------------------------------- --V2C: Used by multiplayer_portal_moon for saving certain character traits -- when rerolling a new character. local function SaveForReroll(inst) --NOTE: ignoring returned refs, should be ok local curses = {} --dumptable(inst.components.inventory.itemslots) inst.components.inventory:ForEachItem(function(thing) --print("thing",thing.prefab) if thing.components.curseditem then if not curses[thing.prefab] then curses[thing.prefab] = 0 end curses[thing.prefab] = curses[thing.prefab] + (thing.components.stackable and thing.components.stackable:StackSize() or 1 ) thing:Remove() end end) local data = { age = inst.components.age ~= nil and inst.components.age:OnSave() or nil, builder = inst.components.builder ~= nil and inst.components.builder:OnSave() or nil, petleash = inst.components.petleash ~= nil and inst.components.petleash:OnSave() or nil, maps = inst.player_classified ~= nil and inst.player_classified.MapExplorer ~= nil and inst.player_classified.MapExplorer:RecordAllMaps() or nil, seamlessplayerswapper = inst.components.seamlessplayerswapper ~= nil and inst.components.seamlessplayerswapper:OnSave() or nil, curses = curses, } return next(data) ~= nil and data or nil end local function LoadForReroll(inst, data) --print("LOADING FOR REROLL") if data.age ~= nil and inst.components.age ~= nil then inst.components.age:OnLoad(data.age) end if data.builder ~= nil and inst.components.builder ~= nil then inst.components.builder:OnLoad(data.builder) end if data.petleash ~= nil and inst.components.petleash ~= nil then inst.components.petleash:OnLoad(data.petleash) end if data.maps ~= nil and inst.player_classified ~= nil and inst.player_classified.MapExplorer ~= nil then inst.player_classified.MapExplorer:LearnAllMaps(data.maps) end if data.seamlessplayerswapper ~= nil and inst.components.seamlessplayerswapper ~= nil then inst.components.seamlessplayerswapper:OnLoad(data.seamlessplayerswapper) end if data.curses then for curse,num in pairs(data.curses)do for i=1,num do local item = SpawnPrefab(curse) inst.components.inventory:GiveItem(item) end end end end Unfortunately, these aren't done very dynamically. With help of the lovely people at the Klei Discord I have tried adding my component to these methods using a PlayerPostInit, however, while SaveForReroll gets modified perfectly, LoadForReroll seems to discard/ignore the extra data. Regardless, even if this did work perfectly, it is obviously a band-aid, which brings me to the title of the topic. Instead of having them hardcoded as they are, would it be possible to have SaveForReroll loop over all the components and call a new OnSaveForReroll() function on each of them (and of course modify LoadForReroll to accommodate the change)? That way, mods can adjust their behaviour to the new mechanic, and more importantly, data won't be lost. I hope you guys think about it. Edited July 18, 2022 by Lillyth 4 Link to comment https://forums.kleientertainment.com/forums/topic/141888-to-klei-please-make-wonkey-more-mod-friendly/ Share on other sites More sharing options...
Fluxistence Posted July 18, 2022 Share Posted July 18, 2022 I second this. My own mod also adds components with state. It's not super terrible for those specifically to be lost but it's not optimal either. Something like the proposed change would be very helpful. 2 Link to comment https://forums.kleientertainment.com/forums/topic/141888-to-klei-please-make-wonkey-more-mod-friendly/#findComment-1586167 Share on other sites More sharing options...
. . . Posted July 19, 2022 Share Posted July 19, 2022 yes, it should be. it ruins basically any character which needs to save and load values Link to comment https://forums.kleientertainment.com/forums/topic/141888-to-klei-please-make-wonkey-more-mod-friendly/#findComment-1586304 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now