function randomcurse(ary,chance){
  var ranint = Math.random() * (100 - 0) + 0;
  if (ranint <= chance){
    return ary[Math.floor(Math.random()*ary.length)];
  } else {
    return '';
  }
}

var curses = ['curse_ants', 'curse_lich']

events.listen('item.right_click', event => {
	
  var execCurse = randomcurse(curses,12.5);
  
  if (event.item.id == 'kubejs:dreadful_contract') {

	event.player.playSound('evilcraft:effect.box.beam');

	event.server.runCommandSilent('execute as ' +event.player.name+ ' run back');
if (!execCurse == '') {
	event.server.runCommandSilent('execute as ' +event.player.name+ ' run gamestage add ' +event.player.name+ ' '+execCurse);
	event.server.runCommandSilent('execute as '+event.player.name+' run title '+event.player.name+' times 40 200 40');
	event.player.playSound('quark:entity.stoneling.meep');
		if (execCurse == 'curse_ants') {
		event.server.runCommandSilent('execute as '+event.player.name+' run title '+event.player.name+' subtitle {"text":"You obtained the Curse Of The Ants","color":"dark_red"}');
		event.server.runCommandSilent('execute as '+event.player.name+' run title '+event.player.name+' title {"text":"Everything Seems Smaller","color":"yellow"}');
		event.server.runCommandSilent('tellraw @a ["",{"text":"'+event.player.name+'","bold":true,"color":"light_purple"},{"text":" has obtained the","color":"yellow"},{"text":" Curse Of The Ants","italic":true,"color":"dark_red"},{"text":" for ","color":"yellow"},{"text":"5 Minutes","underlined":true,"color":"yellow"},{"text":"!","color":"yellow"}]');
		};
		if (execCurse == 'curse_lich') {
		event.server.runCommandSilent('execute as '+event.player.name+' run title '+event.player.name+' subtitle {"text":"You obtained the Curse Of The Lich","color":"dark_red"}');
		event.server.runCommandSilent('execute as '+event.player.name+' run title '+event.player.name+' title {"text":"Shields For Everyone","color":"yellow"}');
		event.server.runCommandSilent('tellraw @a ["",{"text":"'+event.player.name+'","bold":true,"color":"light_purple"},{"text":" has obtained the","color":"yellow"},{"text":" Curse Of The Lich","italic":true,"color":"dark_red"},{"text":" for ","color":"yellow"},{"text":"5 Minutes","underlined":true,"color":"yellow"},{"text":"!","color":"yellow"}]');
		};
	event.server.scheduleInTicks(6000, cb => {
	event.player.playSound('occultism:tuning_fork');
	event.server.runCommandSilent('execute as ' +event.player.name + ' run gamestage remove ' +event.player.name+ ' '+execCurse);
	});
	}
    if (!event.player.isCreativeMode()) {
    
    event.item.setCount(event.item.getCount() - 1)
    }
    }
});