task ItemHandling{
	let temparray=[];
	loop{
		temparray=GetCommonDataDefault("ITEMDROP", [ [], [], [] ]);
		ascent(i in 0..length(temparray[0])){
			item(temparray[0][i], temparray[1][i], temparray[2][i]);
		}
		SetCommonData("ITEMDROP", [ [], [], [] ]);
		yield;
	}
}

task item(type, x, y){
	let xv=rand(-1, 1);
	let yv=rand(-0.5, -1);
	let xvb=-xv/120;
	let yvb=rand(0.02, 0.04);
	let collection=0;
	let tempval=0;
	let tick=0;
	let angle=0;
	let obj=CreateRObjEffect(itemimg, 4);
	Obj_SetPosition(obj, x, y);
	ObjEffect_SetXYRect(obj, -16, -16, 16, 16);
	while(tempval<16){
		if(floor(type/16)==tempval){
			ObjEffect_SetUVRect(obj, (type%16)*32, tempval*32, (type%16)*32+32, tempval*32+32);
		}
		tempval++;
	}
	ObjEffect_SetScale(obj, 0.5, 0.5);
	while(Obj_BeDeleted(obj)==false){
		if(type==0){angle+=3; ObjEffect_SetAngle(obj, 0, angle, 0);}
		if(type>1){angle+=3; ObjEffect_SetAngle(obj, 0, 0, angle);}
		if(OnPlayerMissed==true && tick==0 && collection==1){
			collection=0;
			xv=5*cos(AngleToPlayer(Obj_GetX(obj), Obj_GetY(obj)));
			yv=5*sin(AngleToPlayer(Obj_GetX(obj), Obj_GetY(obj)));
			xvb=xv/120;
			yvb=rand(0.02, 0.04);
			tick=1;
		}
		if(collection==0){
			Obj_SetPosition(obj, Obj_GetX(obj)+xv, Obj_GetY(obj)+yv);
			if(xv!=0){xv+=-xvb;}
			if(yv<3){yv+=yvb;}
			if(Obj_GetX(obj)<GetClipMinX || Obj_GetX(obj)>GetClipMaxX){
				xv=-xv;
			}
		}else{
			Obj_SetPosition(obj, Obj_GetX(obj)+8*cos(AngleToPlayer(Obj_GetX(obj), Obj_GetY(obj))),
								Obj_GetY(obj)+8*sin(AngleToPlayer(Obj_GetX(obj), Obj_GetY(obj))));
		}
		if(GetPlayerY<GetClipMinY+120){collection=1;}
		if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD){
			if(Distance(Obj_GetX(obj), Obj_GetY(obj), GetPlayerX, GetPlayerY)<42){
				collection=1;
			}
		}else{
			if(Distance(Obj_GetX(obj), Obj_GetY(obj), GetPlayerX, GetPlayerY)<15){
				collection=1;
			}
		}
		if(Distance(Obj_GetX(obj), Obj_GetY(obj), GetPlayerX, GetPlayerY)<5 && OnPlayerMissed==false){
			Item_Collection(type);
			Obj_Delete(obj);
		}
		if(Distance(Obj_GetX(obj), Obj_GetY(obj), GetCommonData("ITEMCOL")[0], GetCommonData("ITEMCOL")[1])<30 && OnPlayerMissed==false && GetCommonData("ITEMCOLB")=="TRUE"){
			collection=1;
		}
		if(Obj_GetY(obj)>GetClipMaxY+30){Obj_Delete(obj);}
		yield;
	}
}

function Item_Collection(type){
	let temparray=[];
	if(type==0){SetCommonData("MONEYGET", GetCommonData("MONEYGET")+1);}
	if(type>=1){
		temparray=GetCommonData("MATERIALS");
		temparray[type-1]=temparray[type-1]+1;
		SetCommonData("MATERIALS", temparray);
		SaveCommonData;
	}
}