Auto equip script *spoilerish*

I was wondering if it's possible to write an AI script to get a character to equip and unequip an item under certain circumstances. Say I want a character to equip a cloak when outside in daylight and to place said cloak in the inventory the rest of the time
How would I go about that?

0