this makes the player invisible when under knockout animation

local core = require('openmw.core')
local self = require('openmw.self')
local anim = require('openmw.animation')
local I = require('openmw.interfaces')
local types = require('openmw.types')

I.AnimationController.addTextKeyHandler('', function(groupname, key) 

    local spell = "Invisibility" 
			    -- "chameleon" -- "fifth barrier"
    local gear = "common_amulet_05" 
			    -- might need equipment splot check sometimes for use case

    local equips = types.Actor.getEquipment(self)
    for c, _ in pairs(equips) do
      if equips[c].recordId == gear and groupname == "knockout" then 
											-- this can be changed easily to other group

	      types.Actor.activeSpells(self):add({ id = spell, effects = {0}})
      end  
      if anim.isPlaying(self,"knockout") == false then
											-- under any other group
      
		     local effects = core.magic.spells.records[spell].effects
			   for i=1, #effects do   
		        types.Actor.activeEffects(self):remove(effects[i].id)
						    --CAUTION: removes all the spell effects, also from other spells
	       end
      end
    end
end)  

for checking what spells / effects actor has

      local spells = types.Actor.activeSpells(self)
      --local spells = types.Actor.activeEffects(self)
      
      for _, b in pairs(spells) do
        print(b.id)
      end

otherwise this could be used under

      local spells = types.Actor.activeSpells(self)
      
      for a, b in pairs(spells) do
        if b.id == spell then
          print(b.id)
          types.Actor.activeSpells(self):remove(b.id) 
        end
      end