function LSMR:ImplementNewModifier(name, targets, modifier, stat, value) --works on gamedataWeaponItem_Record(and its ancestors) as well as gamedataStatModifierGroup_Record local modifier_handle = TweakDB:GetRecord(name) local modifier_created = modifier_handle ~= nil local valid_targets = {} --objects stored here as handles if type(targets) ~= "table" then targets = {targets} end for _,target in pairs(targets) do --cant just use SetFlatsOn here as we need to modify the output data on a per record basis, based on input data from each specific record target = TweakDB:GetRecord(type(target) == "string" and "Items." .. target or target) --handle string, TDBID, or mixed content input if target and (target:IsA(CName("gamedataBaseObject_Record")) or target:IsA(CName("gamedataStatModifierGroup_Record"))) then if not modifier_created then --created record doesnt exist yet(doesnt mean references to it cant exist, but it would had to have been manually deleted to create this case - cant plan for everything and attempting to do so would make the code far more expensive) table.insert(valid_targets, target) else local modifiers = target:StatModifiers() local i = #modifiers repeat if modifiers[i] and modifiers[i]:GetClassName() == modifier_handle:GetClassName() then --target already has modifier, skip it(this code deliberately does not check for duplicates, as it should not be able to create them here(all duplicates are therefor treated as intentional)) break elseif i <= 1 then --target doesnt have our modifier, or has no modifiers at all table.insert(valid_targets, target) end i = i - 1 until i <= 0 end end end if #valid_targets > 0 then if not modifier_created then --create the modifier record if need be(should always execute, except after a CET reload) if not TweakDB:CreateRecord(name, "gamedataConstantStatModifier_Record") then return false end --something went wrong, abort before anything gets modified end for _,target in pairs(valid_targets) do --apply the modifier to the filtered records target = target:GetID() .. ".statModifiers" TweakDB:SetFlat(target, (function(rec3) table.insert(rec3, name) return rec3 end)(TweakDB:GetFlat(target))) end end TweakDB:SetFlats(name, {modifierType = modifier, statType = "BaseStats." .. stat, value = value}) --set/update values end