Jump to content

Recommended Posts

Now there are several specific properties for the character.

inst.level = data.level or 0
inst.skillpoints = data.skillpoints or 0

How could I restore them after swapping from Wonkey?
I've tried setting inst.SaveForReroll and inst.LoadForReroll in the character prefab, but nothing seemed to be preserved.

If you only want these properties to be saved after swapping from Wonkey, you should put them into a component and add TransferComponent method to it.

-- components/extra_properties.lua
function ExtraProperties:TransferComponent(newinst)
  local newcmp = newinst.components.extra_properties
  if newcmp then
    newcmp.level = self.level
    newcmp.skillpoints = self.skillpoints
  end
end

-- modmain.lua
if GLOBAL.TheNet:GetIsServer() then
  AddPrefabPostInit(YourCharacter, function(inst)
    inst:AddComponent("extra_properties")
  end)
  AddPrefabPostInit("wonkey", function(inst)
    inst:AddComponent("extra_properties")
  end)
end

 

23 minutes ago, LeafyFly said:

If you only want these properties to be saved after swapping from Wonkey, you should put them into a component and add TransferComponent method to it.

-- components/extra_properties.lua
function ExtraProperties:TransferComponent(newinst)
  local newcmp = newinst.components.extra_properties
  if newcmp then
    newcmp.level = self.level
    newcmp.skillpoints = self.skillpoints
  end
end

-- modmain.lua
if GLOBAL.TheNet:GetIsServer() then
  AddPrefabPostInit(YourCharacter, function(inst)
    inst:AddComponent("extra_properties")
  end)
  AddPrefabPostInit("wonkey", function(inst)
    inst:AddComponent("extra_properties")
  end)
end

 

Oh, I have found it feasible to use SaveForReroll and LoadForReroll to store these variables, as long as they are added through AddPrefabPostInit. The LoadForReroll of other characters has not been changed, so it only works for the transformation process of monkey.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...