//Item Spawning Script 

let CSD = GetCurrentScriptDirectory;
let MD = GetModuleDirectory;

#include"./Event_Const.dnh"


@Initialize{}

@MainLoop { yield; }

@Event {
	alternative(GetEventType)
	case(EV_CREATE_ITEM) {
		let eventParam = GetEventArgument(0);
		let type = eventParam[0][0];
		alternative(type)
		case(0){ CreateItems01(eventParam[1][0], eventParam[2][0], eventParam[3][0], eventParam[4][0], eventParam[5][0], eventParam[6][0], eventParam[7][0]); }
		case(1) { CreateItems02(eventParam[1][0], eventParam[2][0], eventParam[3][0], eventParam[4][0], eventParam[5][0], eventParam[6][0], eventParam[7][0], eventParam[8][0], eventParam[9][0]); }
		
	}
}

task CreateItems01(amount, type, x, y, xrandfactor, yrandfactor, score){
	loop(amount){
		CreateItemA1(type, x+rand(-xrandfactor, xrandfactor), y+rand(-yrandfactor, yrandfactor), score);
	}
}

task CreateItems02(amount, type, x, y, relativexoffset, relativeyoffset, xrandfactor, yrandfactor, score){
	let xloc = 0;
	let yloc = 0;
	loop(amount){
		xloc = x+rand(-xrandfactor, xrandfactor);
		yloc = y+rand(-yrandfactor, yrandfactor);
		CreateItemA2(type, xloc, yloc, xloc+relativexoffset, yloc+relativeyoffset, score);
	}
}

function wait(w){ loop(w){ yield; } }