-- replacement light id
local replacementLightId = ""
-- list of light item ids you want to replace
local toReplace = {
"",
"",
""
}
-- helper function to check if a list contains a value
local function tableContains(tbl, str)
for i, val in pairs tbl do
if (val == str) return true end
end
return false
end
-- function runs when the "active" event is triggered.
local function activateCallback(e)
-- If it's not the player then ignore
if (e.activator ~= tes3.player) then return end
-- if not a light then ignore
if (e.target.object.objectType ~= tes3.objectType.light) then return end
-- If the light being activated is in our "toReplace" list
-- then do the thing.
-- Delete the object. This is dangerous btw. I wouldn't do this -- in a published mod but for personal use it's ok I guess.
-- Add the replacement to the player's inventory.
if (tableContains(toReplace, e.target.object.id) then
tes3.deleteObject(e.target.object)
tes3.addItem({reference = tes3.player, item = replacementLightId})
end
end
-- register the activateCallback function event.register(tes3.event.activate, activateCallback)