let primarytick=0;

task mainmenu{
	yield;
	let selectnum=0;
	let back=CreateRObjEffect(blackimg, 8);
	Obj_SetPosition(back, 320, 240);
	ObjEffect_SetUVRect(back, 0, 0, 1000, 1000);
	ObjEffect_SetXYRect(back, -500, -500, 500, 500);
	let backb=CreateRObjEffect(nitorigarage, 8);
	ObjEffect_SetUVRect(backb, 0, 0, 375, 580);
	ObjEffect_SetXYRect(backb, 0, 80, 258, 480);
	let selection=CreateRObjEffect(mapleimg, 8);
	ObjEffect_SetUVRect(selection, 0, 0, 32, 32);
	ObjEffect_SetXYRect(selection, -16, -16, 16, 16);
	DrawTextCustom("Stage Select", 420, 120, 640, 255, 255, 255, 255, 1, 0, 0, 0);
	DrawTextCustom("Garage", 400, 150, 640, 255, 255, 255, 255, 1, 0, 0, 0);
	DrawTextCustom("Edit Vehicle", 380, 180, 640, 255, 255, 255, 255, 1, 0, 0, 0);
	DrawTextCustom("Weapon List", 360, 210, 640, 255, 255, 255, 255, 1, 0, 0, 0);
	DrawTextCustom("Music Room", 340, 240, 640, 255, 255, 255, 255, 1, 0, 0, 0);
	DrawTextCustom("Options", 320, 270, 640, 255, 255, 255, 255, 1, 0, 0, 0);
	DrawTextCustom("Quit", 300, 300, 640, 255, 255, 255, 255, 1, 0, 0, 0);
	DrawTextCustom("Reset Data", 280, 330, 640, 255, 255, 255, 255, 1, 0, 0, 0);
	DrawTextCustom("Update Data", 260, 360, 640, 255, 255, 255, 255, 1, 0, 0, 0);
	if(GetCommonDataDefault("PROLOGUE", 0)==0){
		DrawTextCustom("You have not yet played the prologue. For now, selecting any of the first 4 menus will 
		bring you to the prologue.", 20, 20, 620, 255, 255, 255, 255, 1, 0, 0, 0);
	}
	DrawTextCustom("Select a stage. Be sure that you created your vehicle first!", 260, 400, 620, 255, 255, 255, 255, 1, 0, 1, 0);
	
	while(Obj_BeDeleted(back)==false){
		Obj_SetPosition(selection, 400-selectnum*20, 120+selectnum*30);
		if(GetKeyState(VK_UP)==KEY_PUSH){selectnum--; PlaySE(GCSD~"change.wav");}
		if(GetKeyState(VK_DOWN)==KEY_PUSH){selectnum++; PlaySE(GCSD~"change.wav");}
		if(selectnum<0){selectnum=8;}else if(selectnum>8){selectnum=0;}
		if(GetKeyState(VK_UP)==KEY_PUSH || GetKeyState(VK_DOWN)==KEY_PUSH){
			if(selectnum==0){
				DrawTextCustom("Select a stage. Be sure that you created your vehicle first!", 260, 400, 620, 255, 255, 255, 255, 1, 0, 1, 0);
			}
			if(selectnum==1){
				DrawTextCustom("Go to the garage.", 260, 400, 620, 255, 255, 255, 255, 1, 0, 1, 0);
			}
			if(selectnum==2){
				DrawTextCustom("Create your vehicle.", 260, 400, 620, 255, 255, 255, 255, 1, 0, 1, 0);
			}
			if(selectnum==3){
				DrawTextCustom("See a list of your weapons.", 260, 400, 620, 255, 255, 255, 255, 1, 0, 1, 0);
			}
			if(selectnum==4){
				DrawTextCustom("Listen to the various background musics used in the game.", 260, 400, 620, 255, 255, 255, 255, 1, 0, 1, 0);
			}
			if(selectnum==5){
				DrawTextCustom("Change the difficulty and handicap to affect the multiplier. INCOMPLETE", 260, 400, 620, 255, 255, 255, 255, 1, 0, 1, 0);
			}
			if(selectnum==6){
				DrawTextCustom("Quit the game. Do not leave!", 260, 400, 620, 255, 255, 255, 255, 1, 0, 1, 0);
			}
			if(selectnum==7){
				DrawTextCustom("Reset your data. WARNING! RESETTING WILL REMOVE EVERYTHING YOU HAVE ACCOMPLISED!", 260, 400, 620, 255, 255, 255, 255, 1, 0, 1, 0);
			}
			if(selectnum==8){
				DrawTextCustom("To be used to fix the array lengths in the common data when the game advances.", 260, 400, 620, 255, 255, 255, 255, 1, 0, 1, 0);
			}
		}
		ForbidBomb(true);
		ForbidShot(true);
		if(GetKeyState(VK_SHOT)==KEY_PUSH){
			if(GetCommonDataDefault("PROLOGUE", 0)==0 && selectnum<=3){
				Prologue;
				currentstage=[0, 0];
				SetCommonData("PROLOGUE", 1);
				Obj_Delete(back);
				Obj_Delete(selection);
				Obj_Delete(backb);
			}else{
				if(selectnum==0){
					if(primarytick==1){
						StageMenu;
						PlaySE(GCSD~"select.wav");
					}else{
						PlaySE(GCSD~"error.wav");
						mainmenu;
					}
				}
				if(selectnum==1){Garage; PlaySE(GCSD~"select.wav");}
				if(selectnum==2){VehicleMenu; PlaySE(GCSD~"select.wav");}
				if(selectnum==3){WeaponList; PlaySE(GCSD~"select.wav");}
				if(selectnum==4){MusicMenu; PlaySE(GCSD~"select.wav");}
				if(selectnum==5){OptionsMenu; PlaySE(GCSD~"select.wav");}
				if(selectnum==6){Clear; PlaySE(GCSD~"select.wav");}
				if(selectnum==7){ResetAll; PlaySE(GCSD~"reset.wav"); mainmenu;}
				if(selectnum==8){UpdateAll; PlaySE(GCSD~"reset.wav"); mainmenu;}
				Obj_Delete(back);
				Obj_Delete(selection);
				Obj_Delete(backb);
			}
		}
		yield;
	}
	ForbidBomb(false);
	ForbidShot(false);
}

task StageMenu{
	let selectnum=0;
	let selectnumb=1;
	let back=CreateRObjEffect(blackimg, 8);
	Obj_SetPosition(back, 320, 240);
	ObjEffect_SetUVRect(back, 0, 0, 1000, 1000);
	ObjEffect_SetXYRect(back, -500, -500, 500, 500);
	let selection=CreateRObjEffect(mapleimg, 8);
	ObjEffect_SetUVRect(selection, 0, 0, 32, 32);
	ObjEffect_SetXYRect(selection, -8, -8, 8, 8);
	ascent(i in 0..length(stagelist[1])){
		if(GetCommonData("STAGES")[selectnumb][i]>=1){
			DrawTextCustom(stagelist[selectnumb][i], 33, 50+i*20, 640, 255, 255, 255, 255, 1, 1, 0, 1);
		}else{
			DrawTextCustom("LOCKED", 33, 50+i*20, 640, 150, 255, 255, 255, 1, 1, 0, 1);
		}
	}
	DrawTextCustom(stagelistb[1][0]~"    "~stagelistb[1][1], 23, 30, 640, 255, 255, 255, 255, 1, 1, 0, 1);
	
	yield;
	while(Obj_BeDeleted(back)==false){
		ForbidBomb(true);
		ForbidShot(true);
		Obj_SetPosition(selection, 30, 55+selectnum*20);
		if(GetKeyState(VK_UP)==KEY_PUSH){selectnum--; PlaySE(GCSD~"change.wav");}
		if(GetKeyState(VK_DOWN)==KEY_PUSH){selectnum++; PlaySE(GCSD~"change.wav");}
		if(GetKeyState(VK_LEFT)==KEY_PUSH){selectnumb--; PlaySE(GCSD~"change.wav");}
		if(GetKeyState(VK_RIGHT)==KEY_PUSH){selectnumb++; PlaySE(GCSD~"change.wav");}
		if(selectnumb<0){selectnumb=length(stagelist)-1;}
		if(selectnumb>=length(stagelist)){selectnumb=0;}
		if(selectnum<0){selectnum=length(stagelist[selectnumb])-1;}
		if(selectnum>=length(stagelist[selectnumb])){selectnum=0;}
		if(GetKeyState(VK_LEFT)==KEY_PUSH || GetKeyState(VK_RIGHT)==KEY_PUSH){
			ascent(i in 0..length(stagelist[selectnumb])){
				if(GetCommonData("STAGES")[selectnumb][i]>=1){
					DrawTextCustom(stagelist[selectnumb][i], 33, 50+i*20, 640, 255, 255, 255, 255, 1, 1, 0, 1);
				}else{
					DrawTextCustom("LOCKED", 33, 50+i*20, 640, 150, 255, 255, 255, 1, 1, 0, 1);
				}
			}
			if(GetCommonData("STAGES")[selectnumb][0]>=1){
				DrawTextCustom(stagelistb[selectnumb][0]~"    "~stagelistb[selectnumb][1], 23, 30, 640, 255, 255, 255, 255, 1, 1, 0, 1);
			}else{
				DrawTextCustom(stagelistb[selectnumb][0]~"    LOCKED", 23, 30, 640, 150, 255, 255, 255, 1, 1, 0, 1);
			}
		}
		if(GetKeyState(VK_SHOT)==KEY_PUSH){
			if(GetCommonData("STAGES")[selectnumb][selectnum]==0){
				PlaySE(GCSD~"error.wav");
				ascent(i in 0..length(stagelist[selectnumb])){
					if(GetCommonData("STAGES")[selectnumb][i]>=1){
						DrawTextCustom(stagelist[selectnumb][i], 33, 50+i*20, 640, 255, 255, 255, 255, 1, 1, 0, 1);
					}else{
						DrawTextCustom("LOCKED", 33, 50+i*20, 640, 150, 255, 255, 255, 1, 1, 0, 1);
					}
				}
				if(GetCommonData("STAGES")[selectnumb][0]>=1){
					DrawTextCustom(stagelistb[selectnumb][0]~"    "~stagelistb[selectnumb][1], 23, 30, 640, 255, 255, 255, 255, 1, 1, 0, 1);
				}else{
					DrawTextCustom(stagelistb[selectnumb][0]~"    LOCKED", 23, 30, 640, 150, 255, 255, 255, 1, 1, 0, 1);
				}
			}else{
				PlaySE(GCSD~"select.wav");
				StageSelected(selectnumb, selectnum+1);
				Obj_Delete(back);
				Obj_Delete(selection);
			}
		}
		if(GetKeyState(VK_BOMB)==KEY_PUSH){
			PlaySE(GCSD~"cancel.wav");
			mainmenu;
			Obj_Delete(back);
			Obj_Delete(selection);
		}
		yield;
	}
	ForbidBomb(false);
	ForbidShot(false);
	
	function StageSelected(area, stage){
		if(GetCommonData("HELPERS")[0]==1){
			Hmenu(area, stage);
		}else{
			MenuStageBegin(area, stage);
		}
	}
}

task Garage{
	let selectnum=0;
	let back=CreateRObjEffect(blackimg, 8);
	Obj_SetPosition(back, 320, 240);
	ObjEffect_SetUVRect(back, 0, 0, 1000, 1000);
	ObjEffect_SetXYRect(back, -500, -500, 500, 500);
	let selection=CreateRObjEffect(mapleimg, 8);
	ObjEffect_SetUVRect(selection, 0, 0, 32, 32);
	ObjEffect_SetXYRect(selection, -8, -8, 8, 8);
	DrawTextCustom("Vehicle Garage", GetCenterX, GetCenterY-60, 640, 255, 255, 255, 255, 1, 1, 0, 0);
	DrawTextCustom("Weapons Garage", GetCenterX, GetCenterY, 640, 255, 255, 255, 255, 1, 1, 0, 0);
	DrawTextCustom("Research Lab", GetCenterX, GetCenterY+60, 640, 255, 255, 255, 255, 1, 1, 0, 0);
	DrawTextCustom("Go here to upgrade your vehicle.", 20, 400, 620, 255, 255, 255, 255, 1, 1, 1, 0);
	
	yield;
	while(Obj_BeDeleted(back)==false){
		Obj_SetPosition(selection, GetCenterX-5, GetCenterY-60+selectnum*60);
		if(GetKeyState(VK_UP)==KEY_PUSH){selectnum--; PlaySE(GCSD~"change.wav");}
		if(GetKeyState(VK_DOWN)==KEY_PUSH){selectnum++; PlaySE(GCSD~"change.wav");}
		if(GetKeyState(VK_UP)==KEY_PUSH || GetKeyState(VK_DOWN)==KEY_PUSH){
			if(selectnum<0){selectnum=2;}
			if(selectnum>2){selectnum=0;}
			if(selectnum==0){
				DrawTextCustom("Go here to upgrade your vehicle.", 20, 400, 620, 255, 255, 255, 255, 1, 1, 1, 0);
			}
			if(selectnum==1){
				DrawTextCustom("Go here to create previously made weapons. NOT YET IMPLEMENTED", 20, 400, 620, 255, 255, 255, 255, 1, 1, 1, 0);
			}
			if(selectnum==2){
				DrawTextCustom("Go here for experiments and researches.", 20, 400, 620, 255, 255, 255, 255, 1, 1, 1, 0);
			}
		}
		if(GetKeyState(VK_SHOT)==KEY_PUSH){
			PlaySE(GCSD~"select.wav");
			if(selectnum==0){VGarage;}
			if(selectnum==1){WGarage;}
			if(selectnum==2){RGarage;}
			Obj_Delete(back);
			Obj_Delete(selection);
		}
		ForbidBomb(true);
		ForbidShot(true);
		if(GetKeyState(VK_BOMB)==KEY_PUSH){
			PlaySE(GCSD~"cancel.wav");
			mainmenu;
			Obj_Delete(back);
			Obj_Delete(selection);
		}
		yield;
	}
	ForbidBomb(false);
	ForbidShot(false);
}

task VGarage{
	let selectnum=0;
	let selectnumb=0;
	let state=0;
	let placementx=0;
	let placementy=0;
	let restart=0;
	let vehicle=[];
	let temparray=[];
	let temparrayb=[];
	let temparrayc=[];
	let back=CreateRObjEffect(holebackimg, 8);
	Obj_SetPosition(back, 0, 0);
	ObjEffect_SetUVRect(back, 0, 0, 640, 480);
	ObjEffect_SetXYRect(back, 0, 0, 640, 480);
	let selection=CreateRObjEffect(mapleimg, 8);
	ObjEffect_SetUVRect(selection, 0, 0, 32, 32);
	ObjEffect_SetXYRect(selection, -8, -8, 8, 8);
	ascent(i in 0..length(vehiclelist)){
		if(GetCommonData("VEHICLES")[i][0][0]>=1){
			DrawImageCustom(vehicleimg[i], 0, 0, 90, 30, 53.5+i*90, 30, 255, 255, 255, 255, 0, 1, 0, 0);
		}else{
			DrawTextCustom("LOCKED", 8.5+i*89, 25, 120+i*89, 150, 255, 255, 255, 0, 1, 0, 0);
		}
	}
	vehicle=GetCommonData("VEHICLES")[selectnum];
	DrawTextCustom("COINS: "~NumberToString(GetCommonData("MONEY")), 20, 450, 640, 255, 255, 255, 255, 1, 1, 0, 0);
	drawstats;
	
	yield;
	while(Obj_BeDeleted(back)==false){
		SetPlayerX(GetClipMaxX-65); SetPlayerY(GetCenterY-90);
		ForbidBomb(true);
		ForbidShot(true);
		if(state==0){
			if(GetKeyState(VK_LEFT)==KEY_PUSH){selectnum--; PlaySE(GCSD~"change.wav");}
			if(GetKeyState(VK_RIGHT)==KEY_PUSH){selectnum++; PlaySE(GCSD~"change.wav");}
			Obj_SetPosition(selection, 53.5+selectnum*90, 60);
			if(selectnum<0){selectnum=length(vehiclelist)-1;}
			if(selectnum>=length(vehiclelist)){selectnum=0;}
			if(GetKeyState(VK_LEFT)==KEY_PUSH || GetKeyState(VK_RIGHT)==KEY_PUSH){
				vehicle=GetCommonData("VEHICLES")[selectnum];
				drawstats;
			}
			if(GetKeyState(VK_SHOT)==KEY_PUSH){
				if(GetCommonData("VEHICLES")[selectnum][0][0]>=1){
					PlaySE(GCSD~"select.wav");
					drawupgrade;
					drawstats;
					state=1;
					yield;
				}else{
					PlaySE(GCSD~"error.wav");
					drawstats;
				}
				DrawTextCustom("COINS: "~NumberToString(GetCommonData("MONEY")), 20, 450, 640, 255, 255, 255, 255, 1, 1, 0, 0);
			}
			SetCommonData("VEHICLE", vehiclelist[selectnum]);
			if(GetKeyState(VK_BOMB)==KEY_PUSH){
				PlaySE(GCSD~"cancel.wav");
				Garage;
				Obj_Delete(back);
				Obj_Delete(selection);
			}
		}
		if(state==1){
			if(GetKeyState(VK_LEFT)==KEY_PUSH || GetKeyState(VK_RIGHT)==KEY_PUSH){
				drawstats;
			}
			if(GetKeyState(VK_UP)==KEY_PUSH){
				selectnumb--;
				PlaySE(GCSD~"change.wav");
			}
			if(GetKeyState(VK_DOWN)==KEY_PUSH){
				selectnumb++;
				PlaySE(GCSD~"change.wav");
			}
			Obj_SetPosition(selection, 20, 95+selectnumb*20);
			if(GetKeyState(VK_BOMB)==KEY_PUSH){state=0; PlaySE(GCSD~"cancel.wav");}
			if(selectnumb<0){selectnumb=4;}
			if(selectnumb>4){selectnumb=0;}
			if(GetKeyState(VK_UP)==KEY_PUSH || GetKeyState(VK_DOWN)==KEY_PUSH){
				drawupgrade;
			}
			if(GetKeyState(VK_BOMB)==KEY_PUSH){
				ascent(i in 0..length(vehiclelist)){
					if(GetCommonData("VEHICLES")[i][0][0]>=1){
						DrawImageCustom(vehicleimg[i], 0, 0, 90, 30, 53.5+i*90, 30, 255, 255, 255, 255, 0, 1, 0, 0);
					}else{
						DrawTextCustom("LOCKED", 8.5+i*89, 25, 120+i*89, 150, 255, 255, 255, 0, 1, 0, 0);
					}
				}
				DrawTextCustom("COINS: "~NumberToString(GetCommonData("MONEY")), 20, 450, 640, 255, 255, 255, 255, 1, 1, 0, 0);
				drawstats;
			}
			if(GetKeyState(VK_SHOT)==KEY_PUSH){
				if(GetCommonData("MONEY")>=GetCommonData("UPGRADECOSTS")[selectnum][selectnumb][0] && vehicle[selectnumb+1][0]<vehicle[selectnumb+1][2]){
					PlaySE(GCSD~"select.wav");
					SetCommonData("MONEY", GetCommonData("MONEY")-GetCommonData("UPGRADECOSTS")[selectnum][selectnumb][0]);
					temparray=GetCommonData("UPGRADECOSTS");
					temparrayb=temparray[selectnum];
					temparrayc=temparrayb[selectnumb];
					temparrayc[0]=temparrayc[0]+temparrayc[1];
					temparrayb[selectnumb]=temparrayc;
					temparray[selectnum]=temparrayb;
					SetCommonData("UPGRADECOSTS", temparray);
					temparray=[];
					temparrayb=[];
					temparrayc=[];
					temparray=GetCommonData("VEHICLES");
					temparrayb=temparray[selectnum];
					temparrayc=temparrayb[selectnumb+1];
					temparrayc[0]=temparrayc[0]+temparrayc[1];
					temparrayb[selectnumb+1]=temparrayc;
					temparray[selectnum]=temparrayb;
					SetCommonData("VEHICLES", temparray);
					temparray=[];
					temparrayb=[];
					temparrayc=[];
					vehicle=GetCommonData("VEHICLES")[selectnum];
					drawupgrade;
					drawstats;
					SaveCommonData;
				}else{
					PlaySE(GCSD~"error.wav");
					drawupgrade;
					drawstats;
				}
				DrawTextCustom("COINS: "~NumberToString(GetCommonData("MONEY")), 20, 450, 640, 255, 255, 255, 255, 1, 1, 0, 0);
			}
		}
		yield;
	}
	ForbidBomb(false);
	ForbidShot(false);
	
	function drawstats{
		if(vehicle[0][0]>=1){
			DrawTextCustom("CAPACITY: "~NumberToString(vehicle[1][0]), 20, 90, 640, 255, 255, 255, 255, 1, 1, 0, 1);
			DrawTextCustom("ENERGY: "~NumberToString(vehicle[2][0]), 20, 110, 640, 255, 255, 255, 255, 1, 1, 0, 1);
			DrawTextCustom("ARMOR: "~NumberToString(vehicle[3][0]), 20, 130, 640, 255, 255, 255, 255, 1, 1, 0, 1);
			DrawTextCustom("SPEED (PRIMARY): "~NumberToString(vehicle[4][0]), 20, 150, 640, 255, 255, 255, 255, 1, 1, 0, 1);
			DrawTextCustom("SPEED (SECONDARY): "~NumberToString(vehicle[5][0]), 20, 170, 640, 255, 255, 255, 255, 1, 1, 0, 1);
		}else{
			DrawTextCustom("CAPACITY: ???", 20, 90, 640, 255, 255, 255, 255, 1, 1, 0, 1);
			DrawTextCustom("ENERGY: ???", 20, 110, 640, 255, 255, 255, 255, 1, 1, 0, 1);
			DrawTextCustom("ARMOR: ???", 20, 130, 640, 255, 255, 255, 255, 1, 1, 0, 1);
			DrawTextCustom("SPEED (PRIMARY): ???", 20, 150, 640, 255, 255, 255, 255, 1, 1, 0, 1);
			DrawTextCustom("SPEED (SECONDARY): ???", 20, 170, 640, 255, 255, 255, 255, 1, 1, 0, 1);
		}
		SetPlayerX(GetClipMaxX-70); SetPlayerY(GetCenterY-12);
	}
	function drawupgrade{
		if(vehicle[selectnumb+1][0]==vehicle[selectnumb+1][2]){
			if(selectnumb==0){
				DrawTextCustom("CAPACITY: "~NumberToString(vehicle[1][0]), 20, 250, 640, 255, 255, 64, 64, 1, 1, 1, 0);
				DrawTextCustom("UPGRADED CAPACITY: MAX CAPACITY REACHED", 20, 270, 640, 255, 255, 64, 64, 1, 1, 1, 0);
				DrawTextCustom("MAX CAPACITY: "~NumberToString(vehicle[1][2]), 20, 310, 640, 255, 255, 64, 64, 1, 1, 1, 0);
			}
			if(selectnumb==1){
				DrawTextCustom("ENERGY: "~NumberToString(vehicle[2][0]), 20, 250, 640, 255, 255, 64, 64, 1, 1, 1, 0);
				DrawTextCustom("UPGRADED ENERGY: MAX ENERGY REACHED", 20, 270, 640, 255, 255, 64, 64, 1, 1, 1, 0);
				DrawTextCustom("MAX ENERGY: "~NumberToString(vehicle[2][2]), 20, 310, 640, 255, 255, 64, 64, 1, 1, 1, 0);
			}
			if(selectnumb==2){
				DrawTextCustom("ARMOR: "~NumberToString(vehicle[3][0]), 20, 250, 640, 255, 255, 64, 64, 1, 1, 1, 0);
				DrawTextCustom("UPGRADED ARMOR: MAX ARMOR REACHED", 20, 270, 640, 255, 255, 64, 64, 1, 1, 1, 0);
				DrawTextCustom("MAX ARMOR: "~NumberToString(vehicle[3][2]), 20, 310, 640, 255, 255, 64, 64, 1, 1, 1, 0);
			}
			if(selectnumb==3){
				DrawTextCustom("SPEED (PRIMARY): "~NumberToString(vehicle[4][0]), 20, 250, 640, 255, 255, 64, 64, 1, 1, 1, 0);
				DrawTextCustom("UPGRADED SPEED (PRIMARY): MAX SPEED (PRIMARY) REACHED", 20, 270, 640, 255, 255, 64, 64, 1, 1, 1, 0);
				DrawTextCustom("MAX SPEED (PRIMARY): "~NumberToString(vehicle[4][2]), 20, 310, 640, 255, 255, 64, 64, 1, 1, 1, 0);
			}
			if(selectnumb==4){
				DrawTextCustom("SPEED (SECONDARY): "~NumberToString(vehicle[5][0]), 20, 250, 640, 255, 255, 64, 64, 1, 1, 1, 0);
				DrawTextCustom("UPGRADED SPEED (SECONDARY): MAX SPEED(SECONDARY) REACHED", 20, 270, 640, 255, 255, 64, 64, 1, 1, 1, 0);
				DrawTextCustom("MAX SPEED (SECONDARY): "~NumberToString(vehicle[5][2]), 20, 310, 640, 255, 255, 64, 64, 1, 1, 1, 0);
			}
		}else{
			if(selectnumb==0){
				DrawTextCustom("CAPACITY: "~NumberToString(vehicle[1][0]), 20, 250, 640, 255, 255, 255, 255, 1, 1, 1, 0);
				DrawTextCustom("UPGRADED CAPACITY: "~NumberToString(vehicle[1][0]+vehicle[1][1]), 20, 270, 640, 255, 255, 255, 255, 1, 1, 1, 0);
				DrawTextCustom("MAX CAPACITY: "~NumberToString(vehicle[1][2]), 20, 310, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			}
			if(selectnumb==1){
				DrawTextCustom("ENERGY: "~NumberToString(vehicle[2][0]), 20, 250, 640, 255, 255, 255, 255, 1, 1, 1, 0);
				DrawTextCustom("UPGRADED ENERGY: "~NumberToString(vehicle[2][0]+vehicle[2][1]), 20, 270, 640, 255, 255, 255, 255, 1, 1, 1, 0);
				DrawTextCustom("MAX ENERGY: "~NumberToString(vehicle[2][2]), 20, 310, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			}
			if(selectnumb==2){
				DrawTextCustom("ARMOR: "~NumberToString(vehicle[3][0]), 20, 250, 640, 255, 255, 255, 255, 1, 1, 1, 0);
				DrawTextCustom("UPGRADED ARMOR: "~NumberToString(vehicle[3][0]+vehicle[3][1]), 20, 270, 640, 255, 255, 255, 255, 1, 1, 1, 0);
				DrawTextCustom("MAX ARMOR: "~NumberToString(vehicle[3][2]), 20, 310, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			}
			if(selectnumb==3){
				DrawTextCustom("SPEED (PRIMARY): "~NumberToString(vehicle[4][0]), 20, 250, 640, 255, 255, 255, 255, 1, 1, 1, 0);
				DrawTextCustom("UPGRADED SPEED (PRIMARY): "~NumberToString(vehicle[4][0]+vehicle[4][1]), 20, 270, 640, 255, 255, 255, 255, 1, 1, 1, 0);
				DrawTextCustom("MAX SPEED (PRIMARY): "~NumberToString(vehicle[4][2]), 20, 310, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			}
			if(selectnumb==4){
				DrawTextCustom("SPEED (SECONDARY): "~NumberToString(vehicle[5][0]), 20, 250, 640, 255, 255, 255, 255, 1, 1, 1, 0);
				DrawTextCustom("UPGRADED SPEED (SECONDARY): "~NumberToString(vehicle[5][0]+vehicle[5][1]), 20, 270, 640, 255, 255, 255, 255, 1, 1, 1, 0);
				DrawTextCustom("MAX SPEED (SECONDARY): "~NumberToString(vehicle[5][2]), 20, 310, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			}
		}
		if(GetCommonData("MONEY")<GetCommonData("UPGRADECOSTS")[selectnum][selectnumb][0]){
			DrawTextCustom("COST: "~NumberToString(GetCommonData("UPGRADECOSTS")[selectnum][selectnumb][0]), 20, 290, 640, 255, 255, 64, 64, 1, 1, 1, 0);
		}else{
			DrawTextCustom("COST: "~NumberToString(GetCommonData("UPGRADECOSTS")[selectnum][selectnumb][0]), 20, 290, 640, 255, 255, 255, 255, 1, 1, 1, 0);
		}
	}
		
}

task WGarage{
	let back=CreateRObjEffect(blackimg, 8);
	Obj_SetPosition(back, 320, 240);
	ObjEffect_SetUVRect(back, 0, 0, 1000, 1000);
	ObjEffect_SetXYRect(back, -500, -500, 500, 500);
	DrawTextCustom("Coming Soon", GetCenterX, GetCenterY, 640, 255, 255, 255, 255, 0, 1, 0, 0);
	
	yield;
	while(Obj_BeDeleted(back)==false){
		ForbidBomb(true);
		ForbidShot(true);
		if(GetKeyState(VK_BOMB)==KEY_PUSH){
			PlaySE(GCSD~"cancel.wav");
			mainmenu;
			Obj_Delete(back);
		}
		yield;
	}
	ForbidBomb(false);
	ForbidShot(false);
}

task RGarage{
	let selectnum=0;
	let back=CreateRObjEffect(blackimg, 8);
	Obj_SetPosition(back, 320, 240);
	ObjEffect_SetUVRect(back, 0, 0, 1000, 1000);
	ObjEffect_SetXYRect(back, -500, -500, 500, 500);
	let selection=CreateRObjEffect(mapleimg, 8);
	ObjEffect_SetUVRect(selection, 0, 0, 32, 32);
	ObjEffect_SetXYRect(selection, -8, -8, 8, 8);
	DrawTextCustom("Experiment", GetCenterX, GetCenterY-30, 640, 255, 255, 255, 255, 1, 1, 0, 0);
	DrawTextCustom("Research", GetCenterX, GetCenterY+30, 640, 255, 255, 255, 255, 1, 1, 0, 0);
	DrawTextCustom("Go here to experiment with ingredients.", 20, 400, 620, 255, 255, 255, 255, 1, 1, 1, 0);
	
	yield;
	while(Obj_BeDeleted(back)==false){
		Obj_SetPosition(selection, GetCenterX-5, GetCenterY-30+selectnum*60);
		if(GetKeyState(VK_UP)==KEY_PUSH){selectnum--; PlaySE(GCSD~"change.wav");}
		if(GetKeyState(VK_DOWN)==KEY_PUSH){selectnum++; PlaySE(GCSD~"change.wav");}
		if(GetKeyState(VK_UP)==KEY_PUSH || GetKeyState(VK_DOWN)==KEY_PUSH){
			if(selectnum<0){selectnum=1;}
			if(selectnum>1){selectnum=0;}
			if(selectnum==0){
				DrawTextCustom("Go here to experiment with ingredients.", 20, 400, 620, 255, 255, 255, 255, 1, 1, 1, 0);
			}
			if(selectnum==1){
				DrawTextCustom("Go here to research for blueprints.", 20, 400, 620, 255, 255, 255, 255, 1, 1, 1, 0);
			}
		}
		if(GetKeyState(VK_SHOT)==KEY_PUSH){
			PlaySE(GCSD~"select.wav");
			if(selectnum==0){EGarage;}
			if(selectnum==1){RLab;}
			Obj_Delete(back);
			Obj_Delete(selection);
		}
		ForbidBomb(true);
		ForbidShot(true);
		if(GetKeyState(VK_BOMB)==KEY_PUSH){
			PlaySE(GCSD~"cancel.wav");
			Garage;
			Obj_Delete(back);
			Obj_Delete(selection);
		}
		yield;
	}
	ForbidBomb(false);
	ForbidShot(false);
}

task EGarage{
	let materials=[];
	let materialsb=[];
	let temparray=[];
	let temparrayb=[];
	let temparrayc=[];
	let temparrayd=[];
	let selectnum=0;
	let selectnumb=0;
	let selectnumc=0;
	let selectnumca=0;
	let selectnumcb=0;
	let tempval=0;
	let addtick=0;
	let temptick=0;
	let back=CreateRObjEffect(experimentbackimg, 8);
	Obj_SetPosition(back, 320, 240);
	ObjEffect_SetUVRect(back, 0, 0, 640, 480);
	ObjEffect_SetXYRect(back, -320, -240, 320, 240);
	let selection=CreateRObjEffect(mapleimg, 8);
	ObjEffect_SetUVRect(selection, 0, 0, 32, 32);
	ObjEffect_SetXYRect(selection, -8, -8, 8, 8);
	ascent(i in 0..length(GetCommonData("MATERIALS"))){
		if(GetCommonData("MATERIALS")[i]>=1){
			materials=materials~[ materialslist[i] ];
			materialsb=materialsb~[ i ];
			temparray=temparray~[ [i, 0] ];
		}
	}
	if(length(materials)>10){
		ascent(i in 0..10){
			DrawTextCustom(NumberToString(GetCommonData("MATERIALS")[materialsb[i]])~"x "~materials[i], 15, 20+i*20, 640, 255, 255, 255, 255, 1, 1, 1, 0);
		}
	}else{
		ascent(i in 0..length(materials)){
			DrawTextCustom(NumberToString(GetCommonData("MATERIALS")[materialsb[i]])~"x "~materials[i], 15, 20+i*20, 640, 255, 255, 255, 255, 1, 1, 1, 0);
		}
	}
	
	yield;
	while(Obj_BeDeleted(back)==false){
		if(selectnumc==0){
			Obj_SetPosition(selection, 18, 25+selectnum*20);
		}
		if(selectnumc==1){
			Obj_SetPosition(selection, 253, 25+selectnumca*20);
		}
		if(selectnumc==0){
			if(GetKeyState(VK_UP)==KEY_PUSH){selectnum--; PlaySE(GCSD~"change.wav");}
			if(GetKeyState(VK_DOWN)==KEY_PUSH){selectnum++; PlaySE(GCSD~"change.wav");}
			if(length(materials)>10){
				if(selectnum<0){
					if(selectnumb>0){
						selectnum=0;
						selectnumb--;
					}else{
						selectnum=9;
						selectnumb=length(materials)-10;
					}
				}
				if(selectnum>9){
					if(selectnumb<=length(materials)-11){
						selectnum=9;
						selectnumb++;
					}else{
						selectnum=0;
						selectnumb=0;
					}
				}
			}else{
				if(selectnum<0){
					selectnum=length(materials)-1;
				}
				if(selectnum>=length(materials)){
					selectnum=0;
				}
			}
		}else if(selectnumc==1){
			if(GetKeyState(VK_UP)==KEY_PUSH){selectnumca--; PlaySE(GCSD~"change.wav");}
			if(GetKeyState(VK_DOWN)==KEY_PUSH){selectnumca++; PlaySE(GCSD~"change.wav");}
			if(tempval>10){
				if(selectnumca<0){
					if(selectnumcb>0){
						selectnumca=0;
						selectnumcb--;
					}else{
						selectnumca=9;
						selectnumcb=tempval-10;
					}
				}
				if(selectnumca>9){
					if(selectnumcb<=tempval-11){
						selectnumca=9;
						selectnumcb++;
					}else{
						selectnumca=0;
						selectnumcb=0;
					}
				}
			}else{
				if(selectnumca<0){
					selectnumca=tempval-1;
				}
				if(selectnumca>=tempval){
					selectnumca=0;
				}
			}
		}
		if(GetKeyState(VK_UP)==KEY_PUSH || GetKeyState(VK_DOWN)==KEY_PUSH){
			if(length(materials)>10){
				ascent(i in selectnumb..selectnumb+10){
					DrawTextCustom(NumberToString(GetCommonData("MATERIALS")[materialsb[i]])~"x "~materials[i], 15, 20+(i-selectnumb)*20, 640, 255, 255, 255, 255, 1, 1, 1, 0);
				}	
			}else{
				ascent(i in 0..length(materials)){
					DrawTextCustom(NumberToString(GetCommonData("MATERIALS")[materialsb[i]])~"x "~materials[i], 15, 20+i*20, 640, 255, 255, 255, 255, 1, 1, 1, 0);
				}
			}
			if(tempval>10){
				ascent(i in selectnumcb..selectnumcb+10){
					DrawTextCustom(NumberToString(temparrayc[i][1])~"x "~materialslist[temparray[temparrayc[i][0]][0]], 250, 20+(i-selectnumcb)*20, 640, 255, 255, 255, 255, 1, 1, 1, 0);
				}	
			}else{
				ascent(i in 0..length(temparrayc)){
					DrawTextCustom(NumberToString(temparrayc[i][1])~"x "~materialslist[temparray[temparrayc[i][0]][0]], 250, 20+i*20, 640, 255, 255, 255, 255, 1, 1, 1, 0);
				}
			}
		}
		if(GetKeyState(VK_LEFT)==KEY_PUSH){selectnumc++; PlaySE(GCSD~"change.wav");}
		if(GetKeyState(VK_RIGHT)==KEY_PUSH){selectnumc--; PlaySE(GCSD~"change.wav");}
		if(selectnumc>1 || tempval==0){selectnumc=0;} if(selectnumc<0){selectnumc=1;}
		ForbidBomb(true);
		ForbidShot(true);
		if(GetKeyState(VK_SHOT)==KEY_PUSH){
			if(selectnumc==0){
				if(temparray[selectnum+selectnumb][1]<GetCommonData("MATERIALS")[materialsb[selectnum+selectnumb]]){
					temparrayb=temparray[selectnum+selectnumb];
					temparrayb[1]=temparrayb[1]+1;
					temparray[selectnum+selectnumb]=temparrayb;
					PlaySE(GCSD~"select.wav");
				}else{
					PlaySE(GCSD~"error.wav");
				}
			}
			if(selectnumc==1){
				temparrayb=temparray[temparrayc[selectnumca+selectnumcb][0]];
				temparrayb[1]=temparrayb[1]-1;
				temparray[temparrayc[selectnumca+selectnumcb][0]]=temparrayb;
				PlaySE(GCSD~"select.wav");
			}
			temparrayc=[];
			tempval=0;
			ascent(i in 0..length(temparray)){
				if(temparray[i][1]>=1){temparrayc=temparrayc~[ [i, temparray[i][1]] ];}
				if(temparray[i][1]>=1){tempval++;}
			}
			if(tempval>10){
				ascent(i in selectnumcb..selectnumcb+10){
					DrawTextCustom(NumberToString(temparrayc[i][1])~"x "~materialslist[temparray[temparrayc[i][0]][0]], 250, 20+(i-selectnumcb)*20, 640, 255, 255, 255, 255, 1, 1, 1, 0);
				}	
			}else{
				ascent(i in 0..length(temparrayc)){
					DrawTextCustom(NumberToString(temparrayc[i][1])~"x "~materialslist[temparray[temparrayc[i][0]][0]], 250, 20+i*20, 640, 255, 255, 255, 255, 1, 1, 1, 0);
				}
			}
			if(length(materials)>10){
				ascent(i in selectnumb..selectnumb+10){
					DrawTextCustom(NumberToString(GetCommonData("MATERIALS")[materialsb[i]])~"x "~materials[i], 15, 20+(i-selectnumb)*20, 640, 255, 255, 255, 255, 1, 1, 1, 0);
				}	
			}else{
				ascent(i in 0..length(materials)){
					DrawTextCustom(NumberToString(GetCommonData("MATERIALS")[materialsb[i]])~"x "~materials[i], 15, 20+i*20, 640, 255, 255, 255, 255, 1, 1, 1, 0);
				}
			}
		}
		if(GetKeyState(VK_USER)==KEY_PUSH){
			temparrayd=[];
			temptick=1;
			addtick=0;
			ascent(i in 0..length(materialslist)){
				temptick=1;
				addtick=0;
				while(temptick!=0 && addtick<length(temparray)){
					if(temparray[addtick][0]==i){
						temparrayd=temparrayd~[temparray[addtick][1]];
						temptick=0;
					}
					addtick++;
				}
				if(temptick!=0){temparrayd=temparrayd~[0];}
			}
			temptick=1;
			addtick=0;
			while(temptick!=0 && addtick<length(experimentrequirements)){
				temptick=0.5;
				ascent(i in 0..length(temparrayd)){
					if(experimentrequirements[addtick][i]!=temparrayd[i]){
						temptick=1;
					}
				}
				if(temptick==0.5){
					temptick=0;
				}
				addtick++;
			}
			if(temptick==0){
				ExperimentSuccess(addtick-1);
				ascent(i in 0..length(temparray)){
					temparray[i]=[temparray[i][0], 0];
					temparrayc=[];
				}
				materials=[];
				materialsb=[];
				temparray=[];
				ascent(i in 0..length(GetCommonData("MATERIALS"))){
					if(GetCommonData("MATERIALS")[i]>=1){
						materials=materials~[ materialslist[i] ];
						materialsb=materialsb~[ i ];
						temparray=temparray~[ [i, 0] ];
					}
				}
			}else{
				PlaySE(GCSD~"error.wav");
			}
		}
		if(GetKeyState(VK_BOMB)==KEY_PUSH){
			PlaySE(GCSD~"cancel.wav");
			RGarage;
			Obj_Delete(back);
			Obj_Delete(selection);
		}
		yield;
	}
	ForbidBomb(false);
	ForbidShot(false);
}

task RLab{
	let selectnum=0;
	let selectnumb=0;
	let temparray=[];
	let temparrayb=[];
	let weapon=[];
	let back=CreateRObjEffect(blueprintbackimg, 8);
	Obj_SetPosition(back, 320, 240);
	ObjEffect_SetUVRect(back, 0, 0, 640, 480);
	ObjEffect_SetXYRect(back, -320, -240, 320, 240);
	let selection=CreateRObjEffect(mapleimg, 8);
	ObjEffect_SetUVRect(selection, 0, 0, 32, 32);
	ObjEffect_SetXYRect(selection, -8, -8, 8, 8);
	ascent(i in 0..10){
		if(GetCommonData("BLUEPRINTS")[i][0]==1){
			DrawTextCustom(blueprintslist[i][0], 23, 20+i*20, 640, 255, 255, 255, 255, 1, 1, 1, 0);
		}
		if(GetCommonData("BLUEPRINTS")[i][0]==0 && GetCommonData("BLUEPRINTS")[i][1]==1){
			DrawTextCustom(blueprintslist[i][0], 23, 20+i*20, 640, 150, 255, 255, 255, 1, 1, 1, 0);
		}
		if(GetCommonData("BLUEPRINTS")[i][1]==0){
			DrawTextCustom("LOCKED", 23, 20+i*20, 640, 150, 255, 255, 255, 1, 1, 1, 0);
		}
		if(GetCommonData("BLUEPRINTS")[i][0]==0.5){
			DrawTextCustom(blueprintslist[i][0]~"   (Researching)", 23, 20+(i-selectnumb)*20, 640, 205, 255, 255, 255, 1, 1, 1, 0);
		}
	}
	if(GetCommonData("BLUEPRINTS")[selectnum+selectnumb][0]==1){
		DrawTextCustom(blueprintslist[selectnum+selectnumb][1], 20, 260, 620, 255, 255, 255, 255, 1, 1, 1, 0);
	}
	DrawTextCustom("COINS: "~NumberToString(GetCommonData("MONEY")), 20, 450, 640, 255, 255, 255, 255, 1, 1, 0, 0);
	SetBlueprintWeapon;
	drawstats;
	
	yield;
	while(Obj_BeDeleted(back)==false){
		Obj_SetPosition(selection, 20, 25+selectnum*20);
		if(GetKeyState(VK_UP)==KEY_PUSH){selectnum--; PlaySE(GCSD~"change.wav");}
		if(GetKeyState(VK_DOWN)==KEY_PUSH){selectnum++; PlaySE(GCSD~"change.wav");}
		if(selectnum<0){
			if(selectnumb>0){
				selectnum=0;
				selectnumb--;
			}else{
				selectnum=9;
				selectnumb=length(blueprintslist)-10;
			}
		}
		if(selectnum>9){
			if(selectnumb<=length(blueprintslist)-11){
				selectnum=9;
				selectnumb++;
			}else{
				selectnum=0;
				selectnumb=0;
			}
		}
		if(GetKeyState(VK_UP)==KEY_PUSH || GetKeyState(VK_DOWN)==KEY_PUSH){
			ascent(i in selectnumb..selectnumb+10){
				if(GetCommonData("BLUEPRINTS")[i][0]==1){
					DrawTextCustom(blueprintslist[i][0], 23, 20+(i-selectnumb)*20, 640, 255, 255, 255, 255, 1, 1, 1, 0);
				}
				if(GetCommonData("BLUEPRINTS")[i][0]==0 && GetCommonData("BLUEPRINTS")[i][1]==1){
					DrawTextCustom(blueprintslist[i][0], 23, 20+(i-selectnumb)*20, 640, 150, 255, 255, 255, 1, 1, 1, 0);
				}
				if(GetCommonData("BLUEPRINTS")[i][1]==0){
					DrawTextCustom("LOCKED", 23, 20+(i-selectnumb)*20, 640, 150, 255, 255, 255, 1, 1, 1, 0);
				}
				if(GetCommonData("BLUEPRINTS")[i][0]==0.5){
					DrawTextCustom(blueprintslist[i][0]~"   (Researching)", 23, 20+(i-selectnumb)*20, 640, 205, 255, 255, 255, 1, 1, 1, 0);
				}
			}
			if(GetCommonData("BLUEPRINTS")[selectnum+selectnumb][0]==1){
				DrawTextCustom(blueprintslist[selectnum+selectnumb][1], 20, 260, 620, 255, 255, 255, 255, 1, 1, 1, 0);
				SetBlueprintWeapon;
				drawstats;
			}
			if(GetCommonData("BLUEPRINTS")[selectnum+selectnumb][0]==0 && GetCommonData("BLUEPRINTS")[selectnum+selectnumb][1]==1){
				if(GetCommonData("MONEY")>=GetCommonData("BLUEPRINTS")[selectnum+selectnumb][2]){
					DrawTextCustom("Research Cost: "~NumberToString(GetCommonData("BLUEPRINTS")[selectnum+selectnumb][2]), 20, 260, 590, 255, 255, 255, 255, 1, 1, 1, 0);
				}else{
					DrawTextCustom("Research Cost: "~NumberToString(GetCommonData("BLUEPRINTS")[selectnum+selectnumb][2]), 20, 260, 590, 255, 255, 64, 64, 1, 1, 1, 0);
				}
			}
		}
		ForbidBomb(true);
		ForbidShot(true);
		if(GetKeyState(VK_SHOT)==KEY_PUSH){
			if(GetCommonData("BLUEPRINTS")[selectnum+selectnumb][0]==0 && GetCommonData("BLUEPRINTS")[selectnum+selectnumb][1]==1){
				if(GetCommonData("MONEY")>=GetCommonData("BLUEPRINTS")[selectnum+selectnumb][2]){
					PlaySE(GCSD~"select.wav");
					SetCommonData("MONEY", GetCommonData("MONEY")-GetCommonData("BLUEPRINTS")[selectnum+selectnumb][2]);
					temparray=GetCommonData("BLUEPRINTS");
					temparrayb=temparray[selectnum+selectnumb];
					temparrayb[0]=0.5;
					temparray[selectnum+selectnumb]=temparrayb;
					SetCommonData("BLUEPRINTS", temparray);
					SaveCommonData;
				}else{
					PlaySE(GCSD~"error.wav");
				}
			}else{
				PlaySE(GCSD~"error.wav");
			}
			DrawTextCustom("COINS: "~NumberToString(GetCommonData("MONEY")), 20, 450, 640, 255, 255, 255, 255, 1, 1, 0, 0);
			ascent(i in selectnumb..selectnumb+10){
				if(GetCommonData("BLUEPRINTS")[i][0]==1){
					DrawTextCustom(blueprintslist[i][0], 23, 20+(i-selectnumb)*20, 640, 255, 255, 255, 255, 1, 1, 1, 0);
				}
				if(GetCommonData("BLUEPRINTS")[i][0]==0 && GetCommonData("BLUEPRINTS")[i][1]==1){
					DrawTextCustom(blueprintslist[i][0], 23, 20+(i-selectnumb)*20, 640, 150, 255, 255, 255, 1, 1, 1, 0);
				}
				if(GetCommonData("BLUEPRINTS")[i][1]==0){
					DrawTextCustom("LOCKED", 23, 20+(i-selectnumb)*20, 640, 150, 255, 255, 255, 1, 1, 1, 0);
				}
				if(GetCommonData("BLUEPRINTS")[i][0]==0.5){
					DrawTextCustom(blueprintslist[i][0]~"   (Researching)", 23, 20+(i-selectnumb)*20, 640, 205, 255, 255, 255, 1, 1, 1, 0);
				}
			}
			if(GetCommonData("BLUEPRINTS")[selectnum+selectnumb][0]==1){
				DrawTextCustom(blueprintslist[selectnum+selectnumb][1], 20, 260, 620, 255, 255, 255, 255, 1, 1, 1, 0);
				SetBlueprintWeapon;
				drawstats;
			}
			if(GetCommonData("BLUEPRINTS")[selectnum+selectnumb][0]==0 && GetCommonData("BLUEPRINTS")[selectnum+selectnumb][1]==1){
				if(GetCommonData("MONEY")>=GetCommonData("BLUEPRINTS")[selectnum+selectnumb][2]){
					DrawTextCustom("Research Cost: "~NumberToString(GetCommonData("BLUEPRINTS")[selectnum+selectnumb][2]), 50, 260, 590, 255, 255, 255, 255, 1, 1, 1, 0);
				}else{
					DrawTextCustom("Research Cost: "~NumberToString(GetCommonData("BLUEPRINTS")[selectnum+selectnumb][2]), 50, 260, 590, 255, 255, 64, 64, 1, 1, 1, 0);
				}
			}
		}
		if(GetKeyState(VK_BOMB)==KEY_PUSH){
			PlaySE(GCSD~"cancel.wav");
			RGarage;
			Obj_Delete(back);
			Obj_Delete(selection);
		}
		yield;
	}
	ForbidBomb(false);
	ForbidShot(false);
	
	function drawstats{
		if(weapon[1]=="GUN"){
			DrawTextCustom("TYPE: "~weapon[1], 415, 20, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("BULLETS: "~weapon[2], 415, 40, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("POWER: "~weapon[3], 415, 60, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("PENETRATION: "~weapon[4], 415, 80, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("SPEED: "~weapon[5], 415, 100, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("RECHARGE: "~weapon[6], 415, 120, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("SPECIAL: "~weapon[7], 415, 140, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("WEIGHT: "~weapon[8], 415, 160, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("ENERGY: "~weapon[9], 415, 180, 640, 255, 255, 255, 255, 1, 1, 1, 0);
		}
		if(weapon[1]=="CANNON"){
			DrawTextCustom("TYPE: "~weapon[1], 415, 20, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("BULLETS: "~weapon[2], 415, 40, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("POWER: "~weapon[3], 415, 60, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("PENETRATION: "~weapon[4], 415, 80, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("SPEED RANGE: "~weapon[5], 415, 100, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("RECHARGE: "~weapon[6], 415, 120, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("SPECIAL: "~weapon[7], 415, 140, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("WEIGHT: "~weapon[8], 415, 160, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("ENERGY: "~weapon[9], 415, 180, 640, 255, 255, 255, 255, 1, 1, 1, 0);
		}
	}
	
	function SetBlueprintWeapon{
		if(selectnum+selectnumb==0){weapon=weaponlist[0];}
		if(selectnum+selectnumb==1){weapon=weaponlist[1];}
	}

}

task VehicleMenu{
	let selectnum=0;
	let selectnumb=0;
	let state=0;
	let placementx=0;
	let placementy=0;
	let restart=0;
	let weapons=[];
	let weaponsb=[];
	let temparray=[];
	let temparrayb=[];
	let tempval=0;
	let tempvalb=0;
	let back=CreateRObjEffect(holebackimgb, 8);
	Obj_SetPosition(back, 0, 0);
	ObjEffect_SetUVRect(back, 0, 0, 640, 480);
	ObjEffect_SetXYRect(back, 0, 0, 640, 480);
	let selection=CreateRObjEffect(mapleimg, 8);
	ObjEffect_SetUVRect(selection, 0, 0, 32, 32);
	ObjEffect_SetXYRect(selection, -8, -8, 8, 8);
	let weightbar=CreateRObjEffect(Cbar, 8);
	ObjEffect_SetUVRect(weightbar, 0, 0, 200, 30);
	ObjEffect_SetXYRect(weightbar, 100, 415, 550, 435);
	ObjEffect_SetColor(weightbar, 4, 255, 255, 64, 64);
	let energybar=CreateRObjEffect(Cbar, 8);
	ObjEffect_SetUVRect(energybar, 0, 0, 200, 30);
	ObjEffect_SetXYRect(energybar, 100, 445, 550, 465);
	ObjEffect_SetColor(energybar, 4, 255, 64, 64, 255);
	let weightbarb=CreateRObjEffect(Cbarb, 8);
	ObjEffect_SetUVRect(weightbarb, 0, 0, 200, 30);
	ObjEffect_SetXYRect(weightbarb, 100, 415, 100, 435);
	ObjEffect_SetColor(weightbarb, 4, 255, 255, 64, 64);
	let energybarb=CreateRObjEffect(Cbarb, 8);
	ObjEffect_SetUVRect(energybarb, 0, 0, 200, 30);
	ObjEffect_SetXYRect(energybarb, 100, 445, 100, 465);
	ObjEffect_SetColor(energybarb, 4, 255, 64, 64, 255);
	let weightbarc=CreateRObjEffect(Cbarb, 8);
	ObjEffect_SetUVRect(weightbarc, 0, 0, 200, 30);
	ObjEffect_SetXYRect(weightbarc, 100, 415, 100, 435);
	ObjEffect_SetColor(weightbarc, 4, 150, 255, 128, 128);
	let energybarc=CreateRObjEffect(Cbarb, 8);
	ObjEffect_SetUVRect(energybarc, 0, 0, 200, 30);
	ObjEffect_SetXYRect(energybarc, 100, 445, 100, 465);
	ObjEffect_SetColor(energybarc, 4, 150, 128, 128, 255);
	ascent(i in 0..length(vehiclelist)){
		if(GetCommonData("VEHICLES")[i][0][0]>=1){
			DrawImageCustom(vehicleimg[i], 0, 0, 90, 30, 53.5+i*90, 30, 255, 255, 255, 255, 0, 1, 0, 0);
		}else{
			DrawTextCustom("LOCKED", 8.5+i*89, 25, 120+i*89, 150, 255, 255, 255, 0, 1, 0, 0);
		}
	}
	let weighttext=DrawTextReturn("Weight:", 10, 420, 100, 255, 255, 255, 255);
	let energytext=DrawTextReturn("Energy:", 10, 450, 100, 255, 255, 255, 255);
	DrawTextCustom(NumberToString(tempval)~"/"~NumberToString(GetCommonData("VEHICLES")[selectnum][1][0]), 540, 420, 640, 255, 255, 255, 255, 1, 1, 0, 1);
	DrawTextCustom(NumberToString(tempvalb)~"/"~NumberToString(GetCommonData("VEHICLES")[selectnum][2][0]), 540, 450, 640, 255, 255, 255, 255, 1, 1, 0, 1);
	
	yield;
	while(Obj_BeDeleted(back)==false){
		if(GetCommonData("VEHICLES")[selectnum][0][0]>=1){
			ObjEffect_SetXYRect(weightbarb, 100, 415, 100+450*(tempval/GetCommonData("VEHICLES")[selectnum][1][0]), 435);
			ObjEffect_SetXYRect(energybarb, 100, 445, 100+450*(tempvalb/GetCommonData("VEHICLES")[selectnum][2][0]), 465);
		}else{
			ObjEffect_SetXYRect(weightbarb, 0, 415, 0, 435);
			ObjEffect_SetXYRect(energybarb, 0, 445, 0, 465);
		}
		if(state>=1 && GetCommonData("WEAPONS")[weaponsb[selectnumb]][0]>=1){
			ObjEffect_SetXYRect(weightbarc, 100+450*(tempval/GetCommonData("VEHICLES")[selectnum][1][0]), 415, 100+450*(tempval/GetCommonData("VEHICLES")[selectnum][1][0])+450*(StringToNumber(weapons[selectnumb][8])/GetCommonData("VEHICLES")[selectnum][1][0]), 435);
			ObjEffect_SetXYRect(energybarc, 100+450*(tempvalb/GetCommonData("VEHICLES")[selectnum][2][0]), 445, 100+450*(tempvalb/GetCommonData("VEHICLES")[selectnum][2][0])+450*(StringToNumber(weapons[selectnumb][9])/GetCommonData("VEHICLES")[selectnum][2][0]), 465);
		}else{
			ObjEffect_SetXYRect(weightbarc, 0, 415, 0, 435);
			ObjEffect_SetXYRect(energybarc, 0, 445, 0, 465);
		}
		SetPlayerX(GetClipMaxX-65); SetPlayerY(GetCenterY-90);
		ForbidBomb(true);
		ForbidShot(true);
		if(state==0){
			if(restart==1){restart=0;}
			if(GetKeyState(VK_LEFT)==KEY_PUSH){selectnum--; PlaySE(GCSD~"change.wav");}
			if(GetKeyState(VK_RIGHT)==KEY_PUSH){selectnum++; PlaySE(GCSD~"change.wav");}
			Obj_SetPosition(selection, 53.5+selectnum*90, 60);
			if(selectnum<0){selectnum=length(vehiclelist)-1;}
			if(selectnum>=length(vehiclelist)){selectnum=0;}
			if(GetKeyState(VK_SHOT)==KEY_PUSH){
				if(GetCommonData("VEHICLES")[selectnum][0][0]>=1){
					primarytick=1;
					tempval=0;
					tempvalb=0;
					temparray=[];
					DrawTextCustom(NumberToString(tempval)~"/"~NumberToString(GetCommonData("VEHICLES")[selectnum][1][0]), 540, 420, 640, 255, 255, 255, 255, 1, 1, 0, 1);
					DrawTextCustom(NumberToString(tempvalb)~"/"~NumberToString(GetCommonData("VEHICLES")[selectnum][2][0]), 540, 450, 640, 255, 255, 255, 255, 1, 1, 0, 1);
					PlaySE(GCSD~"select.wav");
						weapons=[];
						weaponsb=[];
					ascent(i in 0..length(GetCommonData("WEAPONS"))){
						if(GetCommonData("WEAPONS")[i][selectnum+1]==1){
							weapons=weapons~[ weaponlist[i] ];
							weaponsb=weaponsb~[ i ];
							temparray=temparray~[ [i, 0] ];
						}
					}
					ascent(i in 0..length(weapons)){
						if(GetCommonData("WEAPONS")[weaponsb[i]][0]>=1){
							DrawTextCustom(NumberToString(GetCommonData("WEAPONS")[weaponsb[i]][0])~"x "~weapons[i][0], 20, 90+i*20, 640, 255, 255, 255, 255, 0, 1, 0, 0);
						}else{
							DrawTextCustom("LOCKED", 20, 90+i*20, 640, 150, 255, 255, 255, 0, 1, 0, 0);
						}
					}
					state=0.9;
					yield;
				}else{
					PlaySE(GCSD~"error.wav");
					DrawTextCustom("0/0", 540, 420, 640, 255, 255, 255, 255, 1, 1, 0, 1);
					DrawTextCustom("0/0", 540, 450, 640, 255, 255, 255, 255, 1, 1, 0, 1);
				}
			}
			SetCommonData("VEHICLE", vehiclelist[selectnum]);
			if(GetKeyState(VK_BOMB)==KEY_PUSH){
				PlaySE(GCSD~"cancel.wav");
				mainmenu;
				Obj_Delete(back);
				Obj_Delete(selection);
				Obj_Delete(weightbar);
				Obj_Delete(energybar);
				Obj_Delete(weightbarb);
				Obj_Delete(energybarb);
				ascent(i in 0..length(weighttext)){Obj_Delete(weighttext[i]);}
				ascent(i in 0..length(energytext)){Obj_Delete(energytext[i]);}
			}
		}
		if(state==0.9){
			if(GetCommonData("WEAPONS")[weaponsb[0]][0]>=1){drawstats;}
			state=1;
		}
		if(state==1){
			if(restart==0){
				SetCommonData("WEAPONPLACEMENT", []);
				SetCommonData("RESTARTPLACEMENT", "TRUE");
				temparrayb=[];
				restart=1;
			}
			if(GetKeyState(VK_UP)==KEY_PUSH){
				selectnumb--;
				PlaySE(GCSD~"change.wav");
			}
			if(GetKeyState(VK_DOWN)==KEY_PUSH){
				selectnumb++;
				PlaySE(GCSD~"change.wav");
			}
			Obj_SetPosition(selection, 20, 95+selectnumb*20);
			if(GetKeyState(VK_BOMB)==KEY_PUSH){state=0; PlaySE(GCSD~"cancel.wav");}
			if(selectnumb<0){selectnumb=length(weapons)-1;}
			if(selectnumb>=length(weapons)){selectnumb=0;}
			if(GetKeyState(VK_UP)==KEY_PUSH || GetKeyState(VK_DOWN)==KEY_PUSH){
				if(GetCommonData("WEAPONS")[weaponsb[selectnumb]][0]>=1){drawstats;}
			}
			if(GetKeyState(VK_BOMB)==KEY_PUSH){
				DrawTextCustom(NumberToString(tempval)~"/"~NumberToString(GetCommonData("VEHICLES")[selectnum][1][0]), 540, 420, 640, 255, 255, 255, 255, 1, 1, 0, 1);
				DrawTextCustom(NumberToString(tempvalb)~"/"~NumberToString(GetCommonData("VEHICLES")[selectnum][2][0]), 540, 450, 640, 255, 255, 255, 255, 1, 1, 0, 1);
				ascent(i in 0..length(vehiclelist)){
					if(GetCommonData("VEHICLES")[i][0][0]>=1){
						DrawImageCustom(vehicleimg[i], 0, 0, 90, 30, 53.5+i*90, 30, 255, 255, 255, 255, 0, 1, 0, 0);
					}else{
						DrawTextCustom("LOCKED", 8.5+i*89, 25, 120+i*89, 150, 255, 255, 255, 0, 1, 0, 0);
					}
				}
			}
			if(GetKeyState(VK_SHOT)==KEY_PUSH){
				DrawTextCustom(NumberToString(tempval)~"/"~NumberToString(GetCommonData("VEHICLES")[selectnum][1][0]), 540, 420, 640, 255, 255, 255, 255, 1, 1, 0, 1);
				DrawTextCustom(NumberToString(tempvalb)~"/"~NumberToString(GetCommonData("VEHICLES")[selectnum][2][0]), 540, 450, 640, 255, 255, 255, 255, 1, 1, 0, 1);
				if(GetCommonData("WEAPONS")[weaponsb[selectnumb]][0]>=1 &&
				   tempval+StringToNumber(weapons[selectnumb][8])<=GetCommonData("VEHICLES")[selectnum][1][0] &&
				   tempvalb+StringToNumber(weapons[selectnumb][9])<=GetCommonData("VEHICLES")[selectnum][2][0] &&
				   temparray[selectnumb][1]<GetCommonData("WEAPONS")[weaponsb[selectnumb]][0]){
					PlaySE(GCSD~"select.wav");
					SetCommonData("PLACEMENT", [1, weaponsb[selectnumb]]);
					SetCommonData("PLACEMENTB", [0, 0, 0]);
					state=2;
					yield;
				}else{
					if(GetCommonData("WEAPONS")[weaponsb[selectnumb]][0]>=1){
						drawstats;
					}
					PlaySE(GCSD~"error.wav");
				}
			}
		}
		if(state==2){
			if(GetKeyState(VK_BOMB)==KEY_PUSH){
				DrawTextCustom(NumberToString(tempval)~"/"~NumberToString(GetCommonData("VEHICLES")[selectnum][1][0]), 540, 420, 640, 255, 255, 255, 255, 1, 1, 0, 1);
				DrawTextCustom(NumberToString(tempvalb)~"/"~NumberToString(GetCommonData("VEHICLES")[selectnum][2][0]), 540, 450, 640, 255, 255, 255, 255, 1, 1, 0, 1);
				PlaySE(GCSD~"cancel.wav");
					weapons=[];
					weaponsb=[];
				ascent(i in 0..length(GetCommonData("WEAPONS"))){
					if(GetCommonData("WEAPONS")[i][selectnum+1]==1){
						weapons=weapons~[ weaponlist[i] ];
						weaponsb=weaponsb~[ i ];
					}
				}
				ascent(i in 0..length(weapons)){
					if(GetCommonData("WEAPONS")[weaponsb[i]][0]>=1){
						DrawTextCustom(NumberToString(GetCommonData("WEAPONS")[weaponsb[i]][0])~"x "~weapons[i][0], 20, 90+i*20, 640, 255, 255, 255, 255, 0, 1, 0, 0);
					}else{
						DrawTextCustom("LOCKED", 20, 90+i*20, 640, 150, 255, 255, 255, 0, 1, 0, 0);
					}
				}
				ascent(i in 0..length(vehiclelist)){
					if(GetCommonData("VEHICLES")[i][0][0]>=1){
						DrawImageCustom(vehicleimg[i], 0, 0, 90, 30, 53.5+i*90, 30, 255, 255, 255, 255, 0, 1, 0, 0);
					}else{
						DrawTextCustom("LOCKED", 8.5+i*89, 25, 120+i*89, 150, 255, 255, 255, 0, 1, 0, 0);
					}
				}
				state=1;
				if(GetCommonData("WEAPONS")[weaponsb[selectnumb]][0]>=1){drawstats;}
				yield;
			}
			if(GetCommonData("PLACEMENT")[0]==0){
				PlaySE(GCSD~"select.wav");
				state=1;
				ascent(i in 0..length(temparray)){
					if(weaponsb[selectnumb]==temparray[i][0]){
						temparrayb=temparray[i];
						temparrayb[1]=temparrayb[1]+1;
						temparray[i]=temparrayb;
					}
				}
				tempval+=StringToNumber(weapons[selectnumb][8]);
				tempvalb+=StringToNumber(weapons[selectnumb][9]);
				DrawTextCustom(NumberToString(tempval)~"/"~NumberToString(GetCommonData("VEHICLES")[selectnum][1][0]), 540, 420, 640, 255, 255, 255, 255, 1, 1, 0, 1);
				DrawTextCustom(NumberToString(tempvalb)~"/"~NumberToString(GetCommonData("VEHICLES")[selectnum][2][0]), 540, 450, 640, 255, 255, 255, 255, 1, 1, 0, 1);
				if(GetCommonData("WEAPONS")[weaponsb[selectnumb]][0]>=1){drawstats;}
				yield;
			}
		}
		if(GetKeyState(VK_LEFT)==KEY_PUSH || GetKeyState(VK_RIGHT)==KEY_PUSH){
			if(GetCommonData("VEHICLES")[selectnum][0][0]>=1){
				DrawTextCustom(NumberToString(tempval)~"/"~NumberToString(GetCommonData("VEHICLES")[selectnum][1][0]), 540, 420, 640, 255, 255, 255, 255, 1, 1, 0, 1);
				DrawTextCustom(NumberToString(tempvalb)~"/"~NumberToString(GetCommonData("VEHICLES")[selectnum][2][0]), 540, 450, 640, 255, 255, 255, 255, 1, 1, 0, 1);
			}else{
				DrawTextCustom("0/0", 540, 420, 640, 255, 255, 255, 255, 1, 1, 0, 1);
				DrawTextCustom("0/0", 540, 450, 640, 255, 255, 255, 255, 1, 1, 0, 1);
			}
		}
		yield;
	}
	ForbidBomb(false);
	ForbidShot(false);
	
	function drawstats{
		if(weapons[selectnumb][1]=="GUN"){
			DrawTextCustom("TYPE: "~weapons[selectnumb][1], 450, 90, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("BULLETS: "~weapons[selectnumb][2], 450, 110, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("POWER: "~weapons[selectnumb][3], 450, 130, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("PENETRATION: "~weapons[selectnumb][4], 450, 150, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("SPEED: "~weapons[selectnumb][5], 450, 170, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("RECHARGE: "~weapons[selectnumb][6], 450, 190, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("SPECIAL: "~weapons[selectnumb][7], 450, 210, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("WEIGHT: "~weapons[selectnumb][8], 450, 230, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("ENERGY: "~weapons[selectnumb][9], 450, 250, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom(weapons[selectnumb][10], 20, 310, 630, 255, 255, 255, 255, 1, 1, 1, 0);
			if(temparray[selectnumb][1]<GetCommonData("WEAPONS")[weaponsb[selectnumb]][0]){
				DrawTextCustom("IN PLACE: "~NumberToString(temparray[selectnumb][1]), 450, 270, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			}else{
				DrawTextCustom("IN PLACE: "~NumberToString(temparray[selectnumb][1]), 450, 270, 640, 255, 255, 64, 64, 1, 1, 1, 0);
			}
		}
		if(weapons[selectnumb][1]=="CANNON"){
			DrawTextCustom("TYPE: "~weapons[selectnumb][1], 450, 90, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("BULLETS: "~weapons[selectnumb][2], 450, 110, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("POWER: "~weapons[selectnumb][3], 450, 130, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("PENETRATION: "~weapons[selectnumb][4], 450, 150, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("SPEED RANGE: "~weapons[selectnumb][5], 450, 170, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("RECHARGE: "~weapons[selectnumb][6], 450, 190, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("SPECIAL: "~weapons[selectnumb][7], 450, 210, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("WEIGHT: "~weapons[selectnumb][8], 450, 230, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom("ENERGY: "~weapons[selectnumb][9], 450, 250, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			DrawTextCustom(weapons[selectnumb][10], 20, 310, 630, 255, 255, 255, 255, 1, 1, 1, 0);
			if(temparray[selectnumb][1]<GetCommonData("WEAPONS")[weaponsb[selectnumb]][0]){
				DrawTextCustom("IN PLACE: "~NumberToString(temparray[selectnumb][1]), 450, 270, 640, 255, 255, 255, 255, 1, 1, 1, 0);
			}else{
				DrawTextCustom("IN PLACE: "~NumberToString(temparray[selectnumb][1]), 450, 270, 640, 255, 255, 64, 64, 1, 1, 1, 0);
			}
		}
	}
}

task WeaponList{
	let selectnum=0;
	let selectnumb=0;
	let weapon=[];
	let back=CreateRObjEffect(weaponlistbackimg, 8);
	Obj_SetPosition(back, 0, 0);
	ObjEffect_SetUVRect(back, 0, 0, 640, 480);
	ObjEffect_SetXYRect(back, 0, 0, 640, 480);
	let selection=CreateRObjEffect(mapleimg, 8);
	ObjEffect_SetUVRect(selection, 0, 0, 32, 32);
	ObjEffect_SetXYRect(selection, -8, -8, 8, 8);
	ascent(i in 0..10){
		if(GetCommonData("WEAPONS")[i][0]>=1){
			DrawTextCustom(NumberToString(i+1)~". "~NumberToString(GetCommonData("WEAPONS")[i][0])~"x "~weaponlist[i][0], 23, 30+i*20, 640, 255, 255, 255, 255, 0, 1, 1, 0);
		}else{
			DrawTextCustom(NumberToString(i+1)~". "~"LOCKED", 23, 30+i*20, 640, 150, 255, 255, 255, 0, 1, 1, 0);
		}
	}
	weapon=weaponlist[0];
	if(GetCommonData("WEAPONS")[0][0]>=1){
		drawstats;
	}
	
	yield;
	while(Obj_BeDeleted(back)==false){
		Obj_SetPosition(selection, 20, 35+selectnum*20);
		if(GetKeyState(VK_UP)==KEY_PUSH){selectnum--; PlaySE(GCSD~"change.wav");}
		if(GetKeyState(VK_DOWN)==KEY_PUSH){selectnum++; PlaySE(GCSD~"change.wav");}
		if(selectnum<0){
			if(selectnumb>0){
				selectnum=0;
				selectnumb--;
			}else{
				selectnum=9;
				selectnumb=length(GetCommonData("WEAPONS"))-10;
			}
		}
		if(selectnum>9){
			if(selectnumb<=length(GetCommonData("WEAPONS"))-11){
				selectnum=9;
				selectnumb++;
			}else{
				selectnum=0;
				selectnumb=0;
			}
		}
		if(GetKeyState(VK_UP)==KEY_PUSH || GetKeyState(VK_DOWN)==KEY_PUSH){
			ascent(i in selectnumb..selectnumb+10){
				if(GetCommonData("WEAPONS")[i][0]>=1){
					DrawTextCustom(NumberToString(i+1)~". "~NumberToString(GetCommonData("WEAPONS")[i][0])~"x "~weaponlist[i][0], 23, 30+(i-selectnumb)*20, 640, 255, 255, 255, 255, 0, 1, 1, 0);
				}else{
					DrawTextCustom(NumberToString(i+1)~". "~"LOCKED", 23, 30+(i-selectnumb)*20, 640, 150, 255, 255, 255, 0, 1, 1, 0);
				}
			}	
			if(GetCommonData("WEAPONS")[selectnum+selectnumb][0]>=1){
				weapon=weaponlist[selectnum+selectnumb];
				drawstats;
			}
		}
		ForbidBomb(true);
		ForbidShot(true);
		if(GetKeyState(VK_BOMB)==KEY_PUSH){
			PlaySE(GCSD~"cancel.wav");
			mainmenu;
			Obj_Delete(back);
			Obj_Delete(selection);
		}
		yield;
	}
	ForbidBomb(false);
	ForbidShot(false);
	
	function drawstats{
		if(weapon[1]=="GUN"){
			DrawTextCustom("TYPE: "~weapon[1], 20, 260, 640, 255, 255, 255, 255, 0, 1, 1, 0);
			DrawTextCustom("BULLETS: "~weapon[2], 20, 280, 640, 255, 255, 255, 255, 0, 1, 1, 0);
			DrawTextCustom("POWER: "~weapon[3], 20, 300, 640, 255, 255, 255, 255, 0, 1, 1, 0);
			DrawTextCustom("PENETRATION: "~weapon[4], 20, 320, 640, 255, 255, 255, 255, 0, 1, 1, 0);
			DrawTextCustom("SPEED: "~weapon[5], 20, 340, 640, 255, 255, 255, 255, 0, 1, 1, 0);
			DrawTextCustom("RECHARGE: "~weapon[6], 20, 360, 640, 255, 255, 255, 255, 0, 1, 1, 0);
			DrawTextCustom("SPECIAL: "~weapon[7], 20, 380, 640, 255, 255, 255, 255, 0, 1, 1, 0);
			DrawTextCustom("WEIGHT: "~weapon[8], 20, 400, 640, 255, 255, 255, 255, 0, 1, 1, 0);
			DrawTextCustom("ENERGY: "~weapon[9], 20, 420, 640, 255, 255, 255, 255, 0, 1, 1, 0);
			DrawTextCustom(weapon[10], 190, 260, 630, 255, 255, 255, 255, 0, 1, 1, 0);
		}
		if(weapon[1]=="CANNON"){
			DrawTextCustom("TYPE: "~weapon[1], 20, 260, 640, 255, 255, 255, 255, 0, 1, 1, 0);
			DrawTextCustom("BULLETS: "~weapon[2], 20, 280, 640, 255, 255, 255, 255, 0, 1, 1, 0);
			DrawTextCustom("POWER: "~weapon[3], 20, 300, 640, 255, 255, 255, 255, 0, 1, 1, 0);
			DrawTextCustom("PENETRATION: "~weapon[4], 20, 320, 640, 255, 255, 255, 255, 0, 1, 1, 0);
			DrawTextCustom("SPEED RANGE: "~weapon[5], 20, 340, 640, 255, 255, 255, 255, 0, 1, 1, 0);
			DrawTextCustom("RECHARGE: "~weapon[6], 20, 360, 640, 255, 255, 255, 255, 0, 1, 1, 0);
			DrawTextCustom("SPECIAL: "~weapon[7], 20, 380, 640, 255, 255, 255, 255, 0, 1, 1, 0);
			DrawTextCustom("WEIGHT: "~weapon[8], 20, 400, 640, 255, 255, 255, 255, 0, 1, 1, 0);
			DrawTextCustom("ENERGY: "~weapon[9], 20, 420, 640, 255, 255, 255, 255, 0, 1, 1, 0);
			DrawTextCustom(weapon[10], 190, 260, 630, 255, 255, 255, 255, 0, 1, 1, 0);
		}
	}
}

task MusicMenu{
	let selectnum=0;
	let selectnumb=0;
	let back=CreateRObjEffect(blackimg, 8);
	Obj_SetPosition(back, 320, 240);
	ObjEffect_SetUVRect(back, 0, 0, 1000, 1000);
	ObjEffect_SetXYRect(back, -500, -500, 500, 500);
	let selection=CreateRObjEffect(mapleimg, 8);
	ObjEffect_SetUVRect(selection, 0, 0, 32, 32);
	ObjEffect_SetXYRect(selection, -8, -8, 8, 8);
	ascent(i in 0..8){
		DrawTextCustom(musicarray[i][1], 23, 20+i*20, 640, 255, 255, 255, 255, 0, 1, 1, 0);
	}
	
	yield;
	while(Obj_BeDeleted(back)==false){
		Obj_SetPosition(selection, 20, 25+selectnum*20);
		if(GetKeyState(VK_UP)==KEY_PUSH){selectnum--; PlaySE(GCSD~"change.wav");}
		if(GetKeyState(VK_DOWN)==KEY_PUSH){selectnum++; PlaySE(GCSD~"change.wav");}
		if(selectnum<0){
			if(selectnumb>0){
				selectnum=0;
				selectnumb--;
			}else{
				selectnum=7;
				selectnumb=length(musicarray)-8;
			}
		}
		if(selectnum>7){
			if(selectnumb<=length(musicarray)-9){
				selectnum=7;
				selectnumb++;
			}else{
				selectnum=0;
				selectnumb=0;
			}
		}
		if(GetKeyState(VK_UP)==KEY_PUSH || GetKeyState(VK_DOWN)==KEY_PUSH){
			ascent(i in selectnumb..selectnumb+8){
				DrawTextCustom(musicarray[i][1], 23, 20+(i-selectnumb)*20, 640, 255, 255, 255, 255, 0, 1, 1, 0);
			}	
		}
		ForbidBomb(true);
		ForbidShot(true);
		if(GetKeyState(VK_SHOT)==KEY_PUSH){
			PlaySE(GCSD~"select.wav");
			PlayMusic(musicarray[selectnumb+selectnum][0]);
		}
		if(GetKeyState(VK_BOMB)==KEY_PUSH){
			PlaySE(GCSD~"cancel.wav");
			mainmenu;
			Obj_Delete(back);
			Obj_Delete(selection);
		}
		yield;
	}
	ForbidBomb(false);
	ForbidShot(false);
}

task OptionsMenu{
	let selectnum=0;
	let diffplace=0;
	let diffarr=["EASY", "NORMAL", "HARD", "LUNATIC"];
	ascent(i in 0..length(diffarr)){
		if(diffarr[i]==GetCommonData("DIFFICULTY")){diffplace=i;}
	}
	let handiplace=0;
	let handiarr=[50, 75, 100, 150, 200];
	ascent(i in 0..length(handiarr)){
		if(handiarr[i]==GetCommonData("HANDICAP")){handiplace=i;}
	}
	let back=CreateRObjEffect(blackimg, 8);
	Obj_SetPosition(back, 320, 240);
	ObjEffect_SetUVRect(back, 0, 0, 1000, 1000);
	ObjEffect_SetXYRect(back, -500, -500, 500, 500);
	let selection=CreateRObjEffect(mapleimg, 8);
	ObjEffect_SetUVRect(selection, 0, 0, 32, 32);
	ObjEffect_SetXYRect(selection, -8, -8, 8, 8);
	DrawTextCustom("DIFFICULTY", 63, 75, 640, 255, 255, 255, 255, 0, 1, 0, 0);
	DrawTextCustom("HANDICAP", 63, 105, 640, 255, 255, 255, 255, 0, 1, 0, 0);
	DrawTextCustom("MULTIPLIER", 63, 135, 640, 255, 255, 255, 255, 0, 1, 0, 0);
	DrawTextCustom(GetCommonData("DIFFICULTY"), 253, 75, 640, 255, 255, 255, 255, 0, 1, 0, 1);
	DrawTextCustom(NumberToString(GetCommonData("HANDICAP"))~"%", 253, 105, 640, 255, 255, 255, 255, 0, 1, 0, 1);
	DrawTextCustom(NumberToString(GetCommonData("MULTIPLIER"))~"%", 253, 135, 640, 255, 255, 255, 255, 0, 1, 0, 1);
	
	yield;
	while(Obj_BeDeleted(back)==false){
		Obj_SetPosition(selection, 60, 75+selectnum*30);
		if(GetKeyState(VK_UP)==KEY_PUSH){selectnum--; PlaySE(GCSD~"change.wav");}
		if(GetKeyState(VK_DOWN)==KEY_PUSH){selectnum++; PlaySE(GCSD~"change.wav");}
		if(selectnum<0){
			selectnum=1;
		}
		if(selectnum>1){
			selectnum=0;
		}
		ForbidBomb(true);
		ForbidShot(true);
		if(GetKeyState(VK_BOMB)==KEY_PUSH){
			PlaySE(GCSD~"cancel.wav");
			mainmenu;
			Obj_Delete(back);
			Obj_Delete(selection);
			SaveCommonData;
		}
		if(GetKeyState(VK_LEFT)==KEY_PUSH || GetKeyState(VK_RIGHT)==KEY_PUSH){
			if(selectnum==0){
				if(GetKeyState(VK_LEFT)==KEY_PUSH){diffplace--;}
				if(GetKeyState(VK_RIGHT)==KEY_PUSH){diffplace++;}
				if(diffplace<0){diffplace=3;}else if(diffplace>3){diffplace=0;}
				SetCommonData("DIFFICULTY", diffarr[diffplace]);
			}
			if(selectnum==1){
				if(GetKeyState(VK_LEFT)==KEY_PUSH){handiplace--;}
				if(GetKeyState(VK_RIGHT)==KEY_PUSH){handiplace++;}
				if(handiplace<0){handiplace=4;}else if(handiplace>4){handiplace=0;}
				SetCommonData("HANDICAP", handiarr[handiplace]);
			}
			DrawTextCustom(diffarr[diffplace], 253, 75, 640, 255, 255, 255, 255, 0, 1, 0, 1);
			DrawTextCustom(NumberToString(handiarr[handiplace])~"%", 253, 105, 640, 255, 255, 255, 255, 0, 1, 0, 1);
			DrawTextCustom(NumberToString((diffplace+1)*0.5*handiarr[handiplace])~"%", 253, 135, 640, 255, 255, 255, 255, 0, 1, 0, 1);
			SetCommonData("MULTIPLIER", (diffplace+1)*0.5*handiarr[handiplace]);
		}
		yield;
	}
	ForbidBomb(false);
	ForbidShot(false);
}

task Hmenu(area, stage){
	let selectnum=0;
	let selectnumb=0;
	let temppicarr=[];
	let back=CreateRObjEffect(blackimg, 8);
	Obj_SetPosition(back, 320, 240);
	ObjEffect_SetUVRect(back, 0, 0, 1000, 1000);
	ObjEffect_SetXYRect(back, -500, -500, 500, 500);
	let selection=CreateRObjEffect(mapleimg, 8);
	ObjEffect_SetUVRect(selection, 0, 0, 32, 32);
	ObjEffect_SetXYRect(selection, -8, -8, 8, 8);
	ascent(i in 0..length(GetCommonData("HELPERS"))){
		temppicarr=[];
		if(floor(i/4)==0){temppicarr=[i*64, 0, i*64+64, 64];}else
		if(floor(i/4)==1){temppicarr=[(i-4)*64, 64, (i-4)*64+64, 128];}else
		if(floor(i/4)==2){temppicarr=[(i-8)*64, 128, (i-8)*64+64, 192];}else
		if(floor(i/4)==3){temppicarr=[(i-12)*64, 192, (i-12)*64+64, 256];}
		if(floor(i/5)==0){temppicarr=temppicarr~[172+i*74, 70];}else
		if(floor(i/5)==1){temppicarr=temppicarr~[172+(i-5)*74, 140];}else
		if(floor(i/5)==2){temppicarr=temppicarr~[172+(i-10)*74, 210];}
		DrawImageCustom(helperimg, temppicarr[0], temppicarr[1], temppicarr[2], temppicarr[3], temppicarr[4],
						temppicarr[5], 255, 255, 255, 255, 1, 1, 0, 0);
	}
	DrawTextCustom(helperlist[0][0]~"    "~helperlist[0][1], 20, 400, 620, 255, 255, 255, 255, 1, 1, 1, 1);
	
	yield;
	while(Obj_BeDeleted(back)==false){
		Obj_SetPosition(selection, 172+selectnum*74, 110+selectnumb*70);
		if(GetKeyState(VK_LEFT)==KEY_PUSH){selectnum--; PlaySE(GCSD~"change.wav");}
		if(GetKeyState(VK_RIGHT)==KEY_PUSH){selectnum++; PlaySE(GCSD~"change.wav");}
		if(GetKeyState(VK_UP)==KEY_PUSH){selectnumb--; PlaySE(GCSD~"change.wav");}
		if(GetKeyState(VK_DOWN)==KEY_PUSH){selectnumb++; PlaySE(GCSD~"change.wav");}
		if(selectnum<0){selectnum=4;}
		if(selectnum>4){selectnum=0;}
		if(selectnumb<0){selectnumb=2;}
		if(selectnumb>2){selectnumb=0;}
		if(GetKeyState(VK_LEFT)==KEY_PUSH || GetKeyState(VK_RIGHT)==KEY_PUSH ||
		   GetKeyState(VK_DOWN)==KEY_PUSH || GetKeyState(VK_UP)==KEY_PUSH){
			if(GetCommonData("HELPERS")[selectnumb*5+selectnum]==1){
				DrawTextCustom(helperlist[selectnumb*5+selectnum][0]~"    "~helperlist[selectnumb*5+selectnum][1], 20, 400, 620, 255, 255, 255, 255, 1, 1, 1, 1);
			}else{
				DrawTextCustom("LOCKED", 20, 400, 620, 255, 255, 255, 255, 1, 1, 1, 1);
			}
		}
		ForbidBomb(true);
		ForbidShot(true);
		if(GetKeyState(VK_SHOT)==KEY_PUSH){
			PlaySE(GCSD~"select.wav");
			Obj_Delete(back);
			Obj_Delete(selection);
			SetCommonData("HELPER", helperlist[selectnumb*5+selectnum][0]);
			MenuStageBegin(area, stage);
		}
		if(GetKeyState(VK_BOMB)==KEY_PUSH){
			PlaySE(GCSD~"cancel.wav");
			StageMenu;
			Obj_Delete(back);
			Obj_Delete(selection);
		}
		yield;
	}
	ForbidBomb(false);
	ForbidShot(false);
}

task StatusScreen{
	let back=CreateRObjEffect(blackimg, 7);
	let counter=0;
	let tick=0;
	let sdist=1;
	Obj_SetPosition(back, 320, 240);
	ObjEffect_SetUVRect(back, 0, 0, 1000, 1000);
	ObjEffect_SetXYRect(back, -500, -500, 500, 500);
	ObjEffect_SetColor(back, 4, 150, 255, 255, 255);
	DrawTextCustom("Clear", GetCenterX-40, GetClipMinY+50, GetClipMaxX, 255, 255, 255, 255, 1, 0, 0, 0);
	
	yield;
	while(Obj_BeDeleted(back)==false){
		if(tick==0){
			counter++;
			if(counter==45){
				DrawTextCustom("Coins: ", GetCenterX-100, GetClipMinY+100, GetClipMaxX, 255, 255, 255, 255, 1, 0, 0, 0);
			}
			if(counter==90){
				DrawTextCustom(NumberToString(GetCommonData("MONEYGET")), GetCenterX+50, GetClipMinY+100, GetClipMaxX, 255, 255, 255, 255, 1, 0, 0, 0);
			}
			if(counter==135){
				DrawTextCustom("Damages: ", GetCenterX-100, GetClipMinY+150, GetClipMaxX, 255, 255, 255, 255, 1, 0, 0, 0);
			}
			if(counter==180){
				DrawTextCustom(NumberToString(GetCommonData("DAMAGE")), GetCenterX+50, GetClipMinY+150, GetClipMaxX, 255, 255, 255, 255, 1, 0, 0, 0);
			}
			if(counter==225){
				DrawTextCustom("Maintenance: ", GetCenterX-100, GetClipMinY+200, GetClipMaxX, 255, 255, 255, 255, 1, 0, 0, 0);
			}
			if(counter==270){
				DrawTextCustom(NumberToString(GetCommonData("DAMAGE")*5), GetCenterX+50, GetClipMinY+200, GetClipMaxX, 255, 255, 255, 255, 1, 0, 0, 0);
			}
			if(counter==315){
				DrawTextCustom("Total Earnings: ", GetCenterX-100, GetClipMinY+250, GetClipMaxX, 255, 255, 255, 255, 1, 0, 0, 0);
			}
			if(counter==360){
				if(GetCommonData("MONEYGET")-(GetCommonData("DAMAGE")*5)<0){
					DrawTextCustom(NumberToString(absolute(GetCommonData("MONEYGET")-(GetCommonData("DAMAGE")*5))), GetCenterX+50, GetClipMinY+250, GetClipMaxX, 255, 255, 64, 64, 1, 0, 0, 0);
				}else{
					DrawTextCustom(NumberToString(absolute(GetCommonData("MONEYGET")-(GetCommonData("DAMAGE")*5))), GetCenterX+50, GetClipMinY+250, GetClipMaxX, 255, 255, 255, 255, 1, 0, 0, 0);
				}
			}
			if(counter==405){
				DrawTextCustom("Multiplier: ", GetCenterX-100, GetClipMinY+300, GetClipMaxX, 255, 255, 255, 255, 1, 0, 0, 0);
			}
			if(counter==450){
				DrawTextCustom(NumberToString(GetCommonData("MULTIPLIER"))~"%", GetCenterX+50, GetClipMinY+300, GetClipMaxX, 255, 255, 255, 255, 1, 0, 0, 0);
			}
			if(counter==495){
				DrawTextCustom("Total Coins: ", GetCenterX-100, GetClipMinY+350, GetClipMaxX, 255, 255, 255, 255, 1, 0, 0, 0);
			}
			if(counter==540){
				DrawTextCustom(NumberToString(GetCommonData("MONEY")+floor((GetCommonData("MONEYGET")-(GetCommonData("DAMAGE")*5))*GetCommonData("MULTIPLIER")/100)), GetCenterX+50, GetClipMinY+350, GetClipMaxX, 255, 255, 255, 255, 1, 0, 0, 0);
			}
		}
		if(GetKeyState(VK_SHOT)==KEY_PUSH && tick==0){tick=1; yield;}
		if(tick==1){
			DrawTextCustom("Clear Bonus", GetCenterX-55, GetClipMinY+50, GetClipMaxX, 255, 255, 255, 255, 1, 0, 0, 0);
			ShowClearBonus;
			tick=1.1;
			yield;
		}
		if(GetKeyState(VK_SHOT)==KEY_PUSH && tick==1.1){tick=2; yield;}
		if(tick==2){
			sdist=2;
			DrawTextCustom("Completed Researches", GetCenterX-100, GetClipMinY+50, GetClipMaxX, 255, 255, 255, 255, 1, 0, 0, 0);
			let temparray=[];
			let temparrayb=[];
			ascent(i in 0..length(GetCommonData("BLUEPRINTS"))){
				if(GetCommonData("BLUEPRINTS")[i][0]==0.5){
					temparray=GetCommonData("BLUEPRINTS");
					temparrayb=temparray[i];
					temparrayb[0]=1;
					temparray[i]=temparrayb;
					SetCommonData("BLUEPRINTS", temparray);
					DrawTextCustom(blueprintslist[i][0], GetCenterX-130, GetClipMinY+50*sdist, GetClipMaxX, 255, 255, 255, 255, 1, 0, 0, 0);
					sdist++;
				}
			}
			if(length(temparray)==0){
				DrawTextCustom("none", GetCenterX-100, GetClipMinY+50*sdist, GetClipMaxX, 255, 255, 255, 255, 1, 0, 0, 0);
			}
			SaveCommonData;
			tick=2.1;
			yield;
		}
		if(GetKeyState(VK_SHOT)==KEY_PUSH && tick==2.1){
			SetCommonData("MONEY", GetCommonData("MONEY")+floor((GetCommonData("MONEYGET")-(GetCommonData("DAMAGE")*5))*GetCommonData("MULTIPLIER")/100));
			SaveCommonData;
			PlaySE(GCSD~"select.wav");
			StageMenu;
			Obj_Delete(back);
		}
		yield;
	}
	PlayMusic(menubgm);
	currentstage=[-1, 0];
	CamX = 0;
	CamY = 0;
	CamZ = 0;
	CamDist = 200;
	CamRot = 90;
	CamLift = 0;
	FogColor = [0, 0, 0];
	FogMin = 500;
	FogMax = 1000;
	bgmovX=0;
	bgmovY=0;
	BackdropColor = [255, 255, 255];
}

function MenuStageBegin(area, stage){
	PlayMusic(blankbgm);
	currentstage=[area, stage];
	if(area==0){
		Prologue;
	}
	if(area==1){
		if(stage==1){Area1Stage1;}
		if(stage==2){Area1Stage2;}
	}
}