function random(ary){
    return ary[Math.floor(Math.random()*ary.length)];
}

var shieldCount = ['3', '4', '5'];

onEvent('entity.spawned', event => {
    if(event.entity.isMonster()) {
    
	var atLeastOne = false;
    event.world.players.forEach((player) => {
	if(player.stages.has("curse_lich")) {
    atLeastOne = true;
	}
	});
  
        if(atLeastOne) {
        event.server.scheduleInTicks(7, cb => {
        
        var UUID = event.entity.getFullNBT().UUID;
      
      event.server.runCommandSilent('data merge entity @e[nbt={UUID:'+UUID+'},limit=1] {ForgeCaps: {"twilightforest:cap_shield": {permshields: 0, tempshields: '+random(shieldCount)+'}}}');
    });
    }
}
});