Mr.CrazyPotato Posted August 20, 2024 Share Posted August 20, 2024 Hello modding community! I recently came across a problem that after writing the following commands their effect is not saved if you exit and enter the world again. c_select().AnimState:SetErosionParams(0, -1, -1.0) c_select().AnimState:SetBrightness(2) c_select().Transform:SetScale(1,1,1) c_select().Physics:SetCylinder(0,0) c_select().AnimState:SetMultColour(0, 0, 0, 1) I tried to make my own mod to solve this but a lot of versions just didn't work and this one crashes :P modmain.lua I don't really know what to do with this code, it's just don't work and the amount of problems in it compared with my code skill is just impossible. So I asking for help second time (I didn't know that Klei Forums had modding section so I posted FIRST post in public section). Please help me with some code advices or maybe there way to achieve my goal without modding. I would be grateful for any kind of support (here mod error after trying to save and restart) Link to comment https://forums.kleientertainment.com/forums/topic/159113-modding-saving-animstate-physics-transform/ Share on other sites More sharing options...
Mr.CrazyPotato Posted August 20, 2024 Author Share Posted August 20, 2024 I remade code and now it's works!!! But i still need help. The cylinder and erosion is not getting saved. I don't know why, but here's my code: local function SaveParameters(inst) if inst.AnimState then if inst.AnimState.GetErosionParams then inst.saved_erosion_params = { inst.AnimState:GetErosionParams() } end if inst.AnimState.GetBrightness then inst.saved_brightness = inst.AnimState:GetBrightness() end if inst.AnimState.GetMultColour then inst.saved_colour = { inst.AnimState:GetMultColour() } end end if inst.Transform then if inst.Transform.GetScale then inst.saved_scale = { inst.Transform:GetScale() } end end if inst.Physics then if inst.Physics.GetCylinder then inst.saved_cylinder = { inst.Physics:GetCylinder() } end end end local function ApplyParameters(inst) if inst.AnimState then if inst.saved_erosion_params and inst.AnimState.SetErosionParams then local params = inst.saved_erosion_params inst.AnimState:SetErosionParams(params[1] or 0, params[2] or -1, params[3] or -1.0) end if inst.saved_brightness and inst.AnimState.SetBrightness then inst.AnimState:SetBrightness(inst.saved_brightness) end if inst.saved_colour and inst.AnimState.SetMultColour then local colour = inst.saved_colour inst.AnimState:SetMultColour(colour[1] or 0, colour[2] or 0, colour[3] or 0, colour[4] or 1) end end if inst.Transform then if inst.saved_scale then local scale = inst.saved_scale inst.Transform:SetScale(scale[1] or 1, scale[2] or 1, scale[3] or 1) end end if inst.Physics then if inst.saved_cylinder then local cylinder = inst.saved_cylinder inst.Physics:SetCylinder(cylinder[1] or 0, cylinder[2] or 0) end end end local function OnSave(inst, data) SaveParameters(inst) if inst.saved_erosion_params then data.saved_erosion_params = inst.saved_erosion_params end if inst.saved_brightness then data.saved_brightness = inst.saved_brightness end if inst.saved_colour then data.saved_colour = inst.saved_colour end if inst.saved_scale then data.saved_scale = inst.saved_scale end if inst.saved_cylinder then data.saved_cylinder = inst.saved_cylinder end end local function OnLoad(inst, data) if data then if data.saved_erosion_params then inst.saved_erosion_params = data.saved_erosion_params end if data.saved_brightness then inst.saved_brightness = data.saved_brightness end if data.saved_colour then inst.saved_colour = data.saved_colour end if data.saved_scale then inst.saved_scale = data.saved_scale end if data.saved_cylinder then inst.saved_cylinder = data.saved_cylinder end end inst:DoTaskInTime(0, function() ApplyParameters(inst) end) inst:ListenForEvent("onload", function() ApplyParameters(inst) end) end AddPrefabPostInitAny(function(inst) inst.OnSave = function(inst, data) OnSave(inst, data) end inst.OnLoad = function(inst, data) OnLoad(inst, data) end end) modmain.lua Link to comment https://forums.kleientertainment.com/forums/topic/159113-modding-saving-animstate-physics-transform/#findComment-1741517 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