iuiu Posted September 25, 2023 Share Posted September 25, 2023 components/debuffable.lua The data passed in the AddDebuff(name, prefab, data) method was not saved. This causes the buff to be reset when exiting and reentering. For example, I added a buff and passed some parameters through the data parameter to define the function of this buff. When exiting and re entering, the data becomes empty, making it impossible to customize the buff local function RegisterDebuff(self, name, ent, data) if ent.components.debuff ~= nil then self.debuffs[name] = { inst = ent, onremove = function(debuff) self.debuffs[name] = nil if self.ondebuffremoved ~= nil then self.ondebuffremoved(self.inst, name, debuff) end end, } self.inst:ListenForEvent("onremove", self.debuffs[name].onremove, ent) ent.persists = false ent.components.debuff:AttachTo(name, self.inst, self.followsymbol, self.followoffset, data) if self.ondebuffadded ~= nil then self.ondebuffadded(self.inst, name, ent, data) end else ent:Remove() end end function Debuffable:OnSave() if next(self.debuffs) == nil then return end local data = {} for k, v in pairs(self.debuffs) do local saved--[[, refs]] = v.inst:GetSaveRecord() data[k] = saved end return { debuffs = data, add_component_if_missing = true } end function Debuffable:OnLoad(data) if data ~= nil and data.debuffs ~= nil then for k, v in pairs(data.debuffs) do if self.debuffs[k] == nil then local ent = SpawnSaveRecord(v) if ent ~= nil then RegisterDebuff(self, k, ent) end end end end end I hope to save the data parameter in the AddDebuff(name, prefab, data) method during OnSave(), and then pass it in through the RegisterDebuff() method during OnLoad(data) Link to comment https://forums.kleientertainment.com/forums/topic/151124-suggestion-for-saving-the-data-parameter-in-the-adddebuff-method-of-the-debuffable-component/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.