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;
        var cleanUUID = '[I;'+UUID.toString().substring(1);
      
      event.server.runCommandSilent('data merge entity @e[nbt={UUID:'+cleanUUID+'},limit=1] {ForgeCaps: {"twilightforest:cap_shield": {permshields: 0, tempshields: '+random(shieldCount)+'}}}');
    });
    }
}
});