//@unloadnpc Miu
//@loadnpc npc/valhalla/freebies.txt

new_1-1,58,115,4	script	Miu	4_F_SON,{
function recheck;
	cutin("son", 2);
	mes "[ Miu ]";
	mes "Hey there, ^28bf00"+strcharinfo(0)+"^000000! I represent the world's most adorable official event; Miu";
	next;
	switch(select(
	  ((getgmlevel() < .GMAccess)?":":"^FF0000GM Menu^000000:")+
	  ((gpack)?":":"[ Claim ^B75F12Growth Pack^000000 ]:")+
	  (((evt_free) == 2)?":":"[ Claim ^0E8CECDaily Supplies^000000 ]:")+
	  ((#LOYALTY )      ?":":"[ Claim ^33EC0ELoyalty Bonus^000000 ] :")+
	  "^B75F12Premium Services^000000:"+
	  ((!#RESET && .allowreset )?"[ Reset ^33EC0EStat & Skill^000000 ]:":":")+
	  "[ ^FF0000Guild Supply^000000 ]:"+	
	  ((strcharinfo(PC_NAME) == getguildmaster(getcharid(CHAR_ID_GUILD)))?"[ ^FF0000Guild Storage^000000 ]:":":")+
	  "^28bf00Delete Bound Items^000000:"+
	  "^777777Who are you?^000000:"+
	  "^777777Need to Find GM^000000:"+
	  "^777777Close^000000"
	)) {
	case 1:
		mes "[ GM Menu ]";
		switch(select(
			"Allow Reset [ "+((.allowreset) ? "^28bf00Yes^000000" : "^ff0000No^000000")+" ]:"+
			"Item Shower [ "+((.shower) ? "^28bf00Yes^000000" : "^ff0000No^000000")+" ]:"+
			"^777777Close^000000"
		)) {

		case 1:	
			if(.allowreset){
				.allowreset = 0;
			} else {
				.allowreset = 1;
				.@rid = playerattached();
				query_sql( "SELECT COUNT(`char_id`) FROM `char` WHERE `online` = 1 ", .@total );
				while( .@count < .@total ){
					query_sql( "SELECT `account_id`,`char_id`,`name` FROM `char` WHERE `online` = 1 ORDER BY `char_id` LIMIT 128 OFFSET "+.@offset, .@aid,.@cid,.@name$ );
					set .@i,0;
					set .@size,getarraysize( .@cid );
					freeloop(true);
 					while( .@i < .@size ){
 						if (isloggedin(.@aid[.@i], .@cid[.@i])) {
							attachrid(.@aid[.@i]);
							#RESET = 0;
						}
						set .@count,.@count + 1;
						set .@i,.@i + 1;
					}
					set .@offset,.@offset + .@size;
					deletearray .@cid,.@size;
					deletearray .@name$,.@size;
				}
				query_sql("UPDATE `acc_reg_num_db` SET `value`= 0 WHERE `key` = '#RESET'");
				freeloop(false);
 				if ( .@rid )
        				attachrid(.@rid);
   				else
        				detachrid;						
			}
			close2;
			cutin("", 255);
			end;

		case 2:	if(.shower) {
				.shower = 0; 
			} else { 
				.shower = 1;
			} 
			close2;
			cutin("", 255);
			end;
		default:
			close2;
			cutin("", 255);
			end;
		}
		cutin("", 255);
		end;		
	case 2:
		mes "[ Miu ]";
		mes "^B75F12Growth Packs^000000? Yes sure!.";
		while(1){
			next;
			switch(select(
			"What is Growth Pack?:"+
				"^FF0000Claim Growth Pack^000000:"+
				"^777777Close^000000"
			)) {
			case 1:
				mes "[ Miu ]";
				mes "Growth Pack will aid you in your adventure.  Every 10 LvL you can open your growth pack to get special costumes, supplies and many more.";
				mes "It also includes ^FF0000Stat & Skill Reset^000000 when you reach Lvl 30 and 40. Visit our website For detailed information on what Growth Pack contains.";
				break;
			case 2:
				gpack = 1;
				getitem Growth_Pack_1,1;
				getitembound Saint_Shield,1,4;
				getitembound Saint_Boots,1,4;
				getitembound Saint_Manteau,1,4;
				getitembound Saint_Necklace,1,4;
				getitembound Saint_Ring,1,4;
				getitembound Saint_Armor,1,4;
				next;
				mes "[Miu]";
				mes "Now please select your weapon that is suitable for you.";
				next;
				switch(select(
				  " > ^777777"+getitemname(Saint_Dagger)+"^000000:"+
				  " > ^777777"+getitemname(Saint_Katar)+"^000000:"+
				  " > ^777777"+getitemname(Saint_Two_Handed_Axe)+"^000000:"+
				  " > ^777777"+getitemname(Saint_Sphere)+"^000000:"+
				  " > ^777777"+getitemname(Saint_Staff)+"^000000:"+
				  " > ^777777"+getitemname(Saint_Bow)+"^000000:"+
				  " > ^777777"+getitemname(Saint_Knuckle)+"^000000:"+
				  " > ^777777"+getitemname(Saint_Mace)+"^000000:"+
				  " > ^777777Close^000000"
				)) {
				case 1: getitembound Saint_Dagger,1,4; break;
				case 2: getitembound Saint_Katar,1,4; break;
				case 3: getitembound Saint_Two_Handed_Axe,1,4; break;
				case 4: getitembound Saint_Sphere,1,4; break;
				case 5: getitembound Saint_Staff,1,4; break;
				case 6: getitembound Saint_Bow,1,4; break;
				case 7: getitembound Saint_Knuckle,1,4; break;
				case 8: getitembound Saint_Mace,1,4; break;
				default: getitembound Saint_Dagger,1,4; break;
				}		

				close2;
				cutin("", 255);
				end;
			default:
				close2;
				cutin("", 255);
				end;
			}
		}
		break;
	case 3:
		if(evt_free < 2){
			mes "[ Miu ]";
			mes "You are allowed a daily maximum stack of";
			mes "^FF0000400^000000 x "+Itemlink(Light_White_Pot_V);
			mes "^FF0000200^000000 x "+Itemlink(Light_Blue_Pot_V);
			mes "^FF0000    2^000000 x "+Itemlink(Thick_Manual50_V);
			mes "^FF0000    2^000000 x "+Itemlink(Bubble_Gum_V);
			mes "Make sure to use all the supplies before claiming again.";
			next;
			mes "[ Miu ]";
			mes "For today you will receive the following supplies:";
			mes (countitem(30028) >= 400)? 	"0x "+Itemlink(Light_White_Pot_V)	:400-(countitem(30028))+" x "+Itemlink(Light_White_Pot_V);
			mes (countitem(30029) >= 200)? 	"0x "+Itemlink(Light_Blue_Pot_V)	:200-(countitem(30029))+" x "+Itemlink(Light_Blue_Pot_V);
			mes (countitem(30031) >= 2)? 	"0x "+Itemlink(Thick_Manual50_V)	:  2-(countitem(30031))+" x "+Itemlink(Thick_Manual50_V);
			mes (countitem(30030) >= 2)? 	"0x "+Itemlink(Bubble_Gum_V)		:  2-(countitem(30030))+" x "+Itemlink(Bubble_Gum_V);
			mes "Do you want to collect now?^000000";
			next;
			switch(select("No, I will collect later:Yes, I'm ready to collect now.")) {
			case 1:
				mes "[ Miu ]";
				mes "Okay, come back when you are ready!!!";
				close2;
				cutin("", 255);
				end;
			case 2:
				mes "[ Miu ]";
				mes "There you go!!! See you next time.";
				set evt_free, 2;
				getitembound 30028,400-(countitem(Light_White_Pot_V)),4; // White Potion
				getitembound 30029,200-(countitem(Light_Blue_Pot_V)),4; // Blue Potion
				getitembound 30031,2-(countitem(Thick_Manual50_V)),4; // Battle manual
				getitembound 30030,2-(countitem(Bubble_Gum_V)),4; // Bubble Gum
				close2;
				cutin("", 255);
				end;
			}
		} else {

			mes "[ Miu ]";
			mes "No available Supplies at this time. We will process re-supply every 6AM and 6PM.";
			close2;
			cutin("", 255);
			end;
		}
/*
	case 4:
		mes "[ Miu ]";
		mes "Wow! You made it to the max level!. Here is some token for your endurance.";
		getitem 30249,1;
		transfree = 1;
		close;	
*/
	case 4:
		mes "[ Miu ]";
		mes "Your total playing hours: [ ^B75F12"+#PLAYTIME+"^000000 ]";
		mes "Target:";
		mes "^FF0000100^000000 : "+(#LOYALTY1 ? "[ ^B75F12x^000000 ]" : "[ ^33EC0E+^000000 ]")+" "+Itemlink(Buff_Scroll_A);
		mes "^FF0000200^000000 : "+(#LOYALTY2 ? "[ ^B75F12x^000000 ]" : "[ ^33EC0E+^000000 ]")+" "+Itemlink(C_Red_Strong_Hair);
		mes "^FF0000300^000000 : "+(#LOYALTY3 ? "[ ^B75F12x^000000 ]" : "[ ^33EC0E+^000000 ]")+" "+Itemlink(Flying_Angel);
		mes "^FF0000400^000000 : "+(#LOYALTY4 ? "[ ^B75F12x^000000 ]" : "[ ^33EC0E+^000000 ]")+" Valkyrian Set";
		mes "^FF0000500^000000 : "+(#LOYALTY5 ? "[ ^B75F12x^000000 ]" : "[ ^33EC0E+^000000 ]")+" "+Itemlink(Orleans_Glove);
		mes "^FF0000600^000000 : "+(#LOYALTY6 ? "[ ^B75F12x^000000 ]" : "[ ^33EC0E+^000000 ]")+" "+Itemlink(Orleans_Glove);
		mes "^FF0000700^000000 : "+(#LOYALTY7 ? "[ ^B75F12x^000000 ]" : "[ ^33EC0E+^000000 ]")+" "+Itemlink(Navy_Beret);
		mes "^FF0000800^000000 : "+(#LOYALTY8 ? "[ ^B75F12x^000000 ]" : "[ ^33EC0E+^000000 ]")+" Diabolus Set";
		mes "^FF0000900^000000 : "+(#LOYALTY9 ? "[ ^B75F12x^000000 ]" : "[ ^33EC0E+^000000 ]")+" "+Itemlink(Max_Weight_Up_Box);
		mes "^FF0000 1K^000000  : "+(#LOYALTY10 ? "[ ^B75F12x^000000 ]" : "[ ^33EC0E+^000000 ]")+" "+Itemlink(Sunglasses_);
		next;
		while(1){
			switch(select(
				((!#LOYALTY1 && #PLAYTIME > 99 )?"[ ^B75F12100^000000 pts. ] Collect ^33EC0E"+getitemname(Buff_Scroll_A)+"^000000:":":")+
				((!#LOYALTY2 && #PLAYTIME > 199 )?"[ ^B75F12200^000000 pts. ] Collect ^33EC0E"+getitemname(C_Red_Strong_Hair)+"^000000:":":")+
				((!#LOYALTY3 && #PLAYTIME > 299 )?"[ ^B75F12300^000000 pts. ] Collect ^33EC0E"+getitemname(Flying_Angel)+"^000000:":":")+
				((!#LOYALTY4 && #PLAYTIME > 399 )?"[ ^B75F12400^000000 pts. ] Collect ^33EC0EValkyrian Set^000000:":":")+
				((!#LOYALTY5 && #PLAYTIME > 499 )?"[ ^B75F12500^000000 pts. ] Collect ^33EC0E"+getitemname(Orleans_Glove)+"^000000:":":")+
				((!#LOYALTY6 && #PLAYTIME > 599 )?"[ ^B75F12600^000000 pts. ] Collect ^33EC0E"+getitemname(Orleans_Glove)+"^000000:":":")+
				((!#LOYALTY7 && #PLAYTIME > 699 )?"[ ^B75F12700^000000 pts. ] Collect ^33EC0E"+getitemname(Navy_Beret)+"^000000:":":")+
				((!#LOYALTY8 && #PLAYTIME > 799 )?"[ ^B75F12800^000000 pts. ] Collect ^33EC0EDiabolus Set^000000:":":")+
				((!#LOYALTY9 && #PLAYTIME > 899 )?"[ ^B75F12900^000000 pts. ] Collect ^33EC0E"+getitemname(Max_Weight_Up_Box)+"^000000:":":")+
				((!#LOYALTY0 && #PLAYTIME > 999 )?"[  ^B75F121k^000000 pts.  ] Collect ^33EC0E"+getitemname(Sunglasses_)+"^000000:":":")+
				"^777777Close^000000"
			)) {
			case 1: #LOYALTY1 = 1;
				getitembound Buff_Scroll_A,1,1;
				getitem Online_Coin,10;
				break;
			case 2: #LOYALTY2 = 1;
				getitembound C_Red_Strong_Hair,1,1;
				getitem Online_Coin,10;
				break;
			case 3: #LOYALTY3 = 1;
				getitembound Flying_Angel,1,1;
				getitem Online_Coin,10;
				break;
			case 4: #LOYALTY4 = 1; 
				getitembound Valkyrie_Shoes,1,1;
				getitembound Valkyrie_Manteau,1,1;
				getitembound Valkyrie_Armor,1,1;
				getitembound Valkyrjas_Shield,1,1;
				getitem Online_Coin,10;
				break;
			case 5: #LOYALTY5 = 1;
				getitembound Orleans_Glove,1,1;
				getitem Online_Coin,10;
				break;
			case 6: #LOYALTY6 = 1;
				getitembound Orleans_Glove,1,1;
				getitem Online_Coin,10;
				break;
			case 7: #LOYALTY7 = 1;
				getitembound Navy_Beret,1,1;
				getitem Online_Coin,10;
				break;
			case 8: #LOYALTY8 = 1; 
				getitembound Diabolus_Robe,1,1;
				getitembound Diabolus_Armor,1,1;
				getitembound Diabolus_Boots,1,1;
				getitembound Diabolus_Manteau,1,1;
				getitem Online_Coin,10;
				break;
			case 9:  #LOYALTY9 = 1; 
				getitembound Max_Weight_Up_Box,1,1;
				getitem Online_Coin,10;
				break;
			case 10: #LOYALTY0 = 1; 
				getitembound Sunglasses_,1,1; 
				getitem Online_Coin,10;
				break;
			default:
				close2;
				cutin("", 255);
				end;	
			}
		}
	
	case 5: // Premium Services
		mes "[ Miu ]";
		if(#VIP){
			mes "You are currently have ^B75F12Premium Service^000000 enabled.";
			cutin("", 255);
			close;
		}
		mes "You can avail this service for only ^B75F123,000,000^000000 z valid for 7 days. It will also affect all characters in your account.";
		mes "Services includes:";
 		mes "[ ^01DF01+^000000 ] ^B75F12Agi / Bless Buff^000000";
 		mes "[ ^01DF01+^000000 ] ^B75F12Full HP / SP from Ariel (Healer)^000000 ";
 		mes "[ ^01DF01+^000000 ] ^B75F12Use of @aloot^000000";
		mes "Do you wish to avail this service?";
		next;
		if(select("No","Yes") == 2 ) {	
			if(Zeny > 2999999){
				Zeny -= 3000000;
				close2;
				callfunc "F_GetBuff",1;	
				cutin("", 255);	
				close;		
			} else {
				mes "[ Miu ]";
				mes "Sorry, you do not have enough zeny.";
				cutin("", 255);
				close;
			}	
		}
		mes "[ Miu ]";
		mes "Okay, just come to me if you need ^B75F12Premium Service^000000.";
		close2;
		cutin("", 255);
		end;
	case 6: 
		mes "[ Miu ]";
		mes "Okay, I can give you FREE stat & skills reset on one (1) of your character.";
		mes "Do you want to RESET this character?";
		next;
		if(select("NO! Not this character","Yes") == 2) {
			#RESET = 1;
			mes "[ Miu ]";
			sc_end SC_ALL;
			resetskill;
			resetstatus;
			mes "There you go!";
			close2;
			cutin("", 255);
			end;
		}
		mes "[ Miu ]";
		mes "Okay just come back when you are ready.";
		close2;
		cutin("", 255);
		end;		
	case 7: 
		while(1){
			next;
			mes "[ Miu ]";
			mes("Hello Guild Master ^ff0000"+strcharinfo(PC_NAME)+"^000000!");
			mes "We encourage everyone to particate and be active on a guild to receive this 1 time supplies.";  
			next;
			switch(select(
				( countitem(7558)?" > ^FF0000Validate my Guild^000000:":":")+
		 		" > How to Claim:"+
		 		" > Guild Master:"+
		 		" > Guild Members:"+
		 		" > ^FF0000Restrictions^000000:"+
				" > ^777777Close^000000"
			)) {		
			case 1:
				mes "[ Miu ]";
				mes("Validating ...");
				// Check min guild requirements
				// get the charID and accountID of character's guild members
				getguildmember getcharid(CHAR_ID_GUILD), 1;	
				getguildmember getcharid(CHAR_ID_GUILD), 2;	
				if ( $@guildmembercount < .guild_min ) {
					mes(" - Guild Member Size: ^ff0000Failed^000000");
					dispbottom ("Guild member size must be atleast "+.guild_min+" members.");
					break;
				}
				mes(" - Guild Member Size: ^28bf00Passed^000000");
	
				// Check if all members are online.
				.@count_online = 0; .@mobilecount = 0; .@registered = 0; .@dual = 0; .@tmp$ = "";

				.@origin = getcharid(CHAR_ID_ACCOUNT);

				for ( .@i = 0; .@i < $@guildmembercount; .@i++ ) {
	
					if ( isloggedin( $@guildmemberaid[.@i], $@guildmembercid[.@i] ) ) {

						query_sql "SELECT `name` FROM `char` WHERE `char_id` = "+$@guildmembercid[.@i],.@name$;
						.@count_online++;
	
						query_sql "SELECT `last_ip`, `last_unique_id` FROM login WHERE `account_id` = "+ $@guildmemberaid[.@i], .@last_ip$,.@unique$;
	
						if(!.allowdual) {
							if(compare(.@tmp$,.@unique$)){
								 dispbottom "[ "+.@name$+" ] is has dual account in the guild";
								 .@dual++;
	
							}
							set .@tmp$ ,.@tmp$+.@unique$+",";
						}
						// Check if Mobile
						if( .pconly && .@last_ip$ == .ismobile$){
							 dispbottom "[ "+.@name$+" ] is using a mobile client.";
							 .@mobilecount++;
						}
	
						// Check If has Machine has claimed already.
						if(query_sql("SELECT count(`last_unique_id`) FROM `guildpack` WHERE `last_unique_id` = "+.@unique$,.@c_unique_id)){
							if(.@c_unique_id) {
								 dispbottom "[ "+.@name$+" ] is using a machineID: "+.@unique$+" and was already used to claim before..";
								.@registered++;
							}
						}
						
						// Check If account has claimed already.
						if(query_sql("SELECT count(`account_id`) FROM `guildpack` WHERE `account_id` = "+$@guildmemberaid[.@i],.@c_account_id)){
							if(.@c_account_id) {
								 dispbottom "[ "+.@name$+" ] with AccountID: "+$@guildmemberaid[.@i]+" has already claimed this package.";
								.@registered++;
							}						
						}

					}
				}	
				// Check if all is online
				if ( .@count_online != $@guildmembercount ) {
					mes(" - Member's Online: ^ff0000Failed^000000");
					dispbottom("There are "+.@count_online+" out of "+$@guildmembercount+" members online.");
					break;
				}
				mes(" - Member's Online: ^28bf00Passed^000000");
	
				// Check if using mobile
				if(.pconly){
					if (.@mobilecount) {
						mes(" - All using PC: ^ff0000Failed^000000");
						//dispbottom("There are "+.@mobilecount+" member in the guild is using Android client.");	
						break;
					}
					mes(" - All using PC: ^28bf00Passed^000000");
				}
				// Check if dual
				if(!.allowdual && .@dual ){
					mes(" - No Dual Account: ^ff0000Failed^000000");
					//dispbottom("There are "+.@dual+" member in your guild that is using a DUAL login.");	
					break;
				}
				mes(" - No Dual Account: ^28bf00Passed^000000");
	
				// Check if already claimed
				if(.@registered){
					mes(" - Claim Record: ^ff0000Failed^000000");
					//dispbottom("There are "+.@claimed+" member in your guild that has claimed before.");	
					break;
				}				
				mes(" - Claim Record: ^28bf00Passed^000000");
	
				mes("All checks has passed. Do you wish to proceed now?"); 
				next;
				if (select("No, we are not ready.", "Yes Please.") == 1) {
					mes "[ Miu ]";
					mes ("Okay, let me know when you are ready.");
					break;		
				}
				if (!recheck()){
					mes "[ Miu ]";	
					mes("Ohhh!!! System has detected some changes on your guild.");
					mes("Please try again.");	
					break;
				}		
				if(.gpackitem) delitem(.gpackitem,1);
				getguildmember getcharid(CHAR_ID_GUILD), 1;	
				announce("Congratulations! Guild [ "+getguildname(getcharid(CHAR_ID_GUILD))+" ] headed by [ "+strcharinfo(PC_NAME)+" ] together with his "+$@guildmembercount+" strong army has just claimed their guild Supplies.", bc_all);
				set .@guildmembercount, $@guildmembercount;
				copyarray .@guildmemberaid[0], $@guildmemberaid[0], .@guildmembercount;
				for ( .@i = 0; .@i < .@guildmembercount; .@i ++) {
					if (attachrid(.@guildmemberaid[.@i])) {
						query_sql "SELECT `last_unique_id` FROM login WHERE account_id = "+.@guildmemberaid[.@i],.@last_unique_id$;
						query_sql "INSERT INTO `guildpack` (`timestamp`,`account_id`,`char_id`,`last_unique_id`) VALUES ('"+gettimestr("%Y-%m-%d %H:%M:%S",21)+"',"+getcharid(CHAR_ID_ACCOUNT)+","+getcharid(CHAR_ID_CHAR)+","+escape_sql(.@last_unique_id$)+")";
						if (strcharinfo(PC_NAME) == getguildmaster(getcharid(CHAR_ID_GUILD))) {	
							specialeffect(EF_PRIMECHARGE4, AREA, playerattached());	
	
getitembound 30383,2,2;
getitembound 12622,1,2;
getitembound 14545,20,2;
getitembound 12210,20,2;
getitembound 30368,20,2;
getitembound 30386,50,2;
getitembound 30398,900,2; // Guild Coin
getitembound 30393,30,2;
getitembound 30394,30,2; 
getitembound 30395,50,2;
							
						} else {
							specialeffect(EF_PRIMECHARGE4, AREA, playerattached());
getitembound 30383,2,2;
getitembound 12622,1,2;
getitembound 14545,20,2;
getitembound 12210,20,2;
getitembound 30386,50,2;
getitembound 30398,900,2; // Guild Coin

						}
					}
				}
				attachrid .@origin;
				break;
			case 2: 
				mes "[ Miu ]";
				mes "[ ^ff0000Requirements^000000 ]";
				mes "1. ^ff0000"+.guild_min+"^000000 members minimum";
				mes "2. Only ^ff0000GUILD MASTER^000000 can initiate the claim for the guild";
				mes "3. Guild Leader must contact GM Team for validation of the giuld.";
				mes "4. GM Team will issue Invitation Letter and Guild Leader can start claiming by selecting ^ff0000Validate my Guild^000000 from the menu.";
				mes "5. No ^ff0000DUAL^000000 or extra account in the guild and all member ^ff0000MUST BE^000000 online during the claim.";
				mes "6. Each PC or Mobile unit may only claim ^ff0000one (1) time^000000 regardless of many accounts created.";
				next;
				mes "[ Miu ]";
				mes "[ ^ff0000Important Notice^000000 ]";
				mes "- ^ff0000We encourage every member to be dedicated and active on your guild to avoid getting kicked from the guild.^000000";
				mes "- ^ff0000If member leave or kicked from the guild, all guild supply items will be moved to guild storage.^000000";
				mes "- ^ff0000If guild disbaned, all guild supply will be deleted.^000000";
				break;
			case 3:
				mes "[ Miu ]";
				mes "[ ^ff0000Guild Leader Supplies^000000 ]";
				for(.@i = 0; .@i < getarraysize(.rewardGM); .@i = .@i+2)
					mes "^ff0000"+.rewardGM[.@i+1]+"^000000x "+getitemname(.rewardGM[.@i]);
				break;
			case 4: 
				mes "[ Miu ]";
				mes "[ ^ff0000Guild Member Supplies^000000 ]";
				for(.@i = 0; .@i < getarraysize(.rewardME); .@i = .@i+2)
					mes "^ff0000"+.rewardME[.@i+1]+"^000000x "+getitemname(.rewardME[.@i]);
				break;	
			case 5:
				mes "[ Miu ]";	
				mes "[ ^ff0000Important Notice^000000 ]";
				mes "- ^ff0000We encourage every member to be dedicated and active on your guild to avoid getting kicked from the guild.^000000";
				mes "- ^ff0000If member leave or kicked from the guild, all guild supply items will be moved to guild storage.^000000";
				mes "- ^ff0000If guild disbaned, all guild supply will be deleted.^000000";	
				break;	
			default:
				close2;
				cutin("", 255);
				end;
			}
		}
	case 8:
		close2;
		cutin("", 255);
		guildopenstorage();
		end;
	case 9:
		mes "[ Miu ]";
		mes("Please select bound items to delete:");
		next;
		setarray .@position$[1], "Head","Body","Left hand","Right hand","Robe","Shoes","Accessory 1","Accessory 2","Head 2","Head 3","Costume Low","Costume Mid","Costume Top","Costume Garment";
		set .@menu$,"";
		for( set .@i,1; .@i <= 14; set .@i,.@i+1 )
		{
			if( getequipisequiped(.@i) ) {
				set .@menu$, .@menu$ + .@position$[.@i] + " - " + "[" + getequipname(.@i) + "] "+(checkbound( getequipid(.@i) )  ? "-> ^28bf00bound^000000":"");
			}	
			set .@menu$, .@menu$ + ":";
		}
		set .@part,select(.@menu$);

		if(!checkbound(getequipid(.@part))) {
			dispbottom "I can only delete bound items ..";
			close2;
			cutin("", 255);
			end;
		}

		mes "[ Miu ]";
		mes "Are you sure you want to delete "+ getequipname(.@part)+"?";
		next;
		if(select("No","Yes") == 2){
			failedrefitem(.@part);
		}
		close2;
		cutin("", 255);
		end;	
	case 10:
		mes "[ Miu ]";
		mes "hmm... You don't even know who I am. I should ignore you!.";
		next;
		mes "[ Miu ]";
		mes "Remember this! My name is Miu! I am an amazing, beatiful young woman! Come to me to find sone new activities!";
		close2;
		cutin("", 255);
		end;
	case 11:
		mes "[ Miu ]";
		mes "Want to have a chat with a GM? Try the following ways!";
		mes " - type @request < your message >";
		mes " - find GM at Discord";
		mes " - send PM at our Facebook Page";
		close2;
		cutin("", 255);
		end;
	default:
		close2;
		cutin("", 255);
		end;
	}
	close2;
	cutin("", 255);
	end;

OnReset:
OnClock0600:
OnClock1800:
	
	query_sql( "SELECT COUNT(`char_id`) FROM `char` WHERE `online` = 1 ", .@total );
	while( .@count < .@total ){
		query_sql( "SELECT `account_id`,`char_id`,`name` FROM `char` WHERE `online` = 1 ORDER BY `char_id` LIMIT 128 OFFSET "+.@offset, .@aid,.@cid,.@name$ );
		set .@i,0;
		set .@size,getarraysize( .@cid );

		freeloop(true);
 		while( .@i < .@size ){
 			if (isloggedin(.@aid[.@i], .@cid[.@i])) {
				attachrid(.@aid[.@i]);
				evt_free = 1;
			}
			set .@count,.@count + 1;
			set .@i,.@i + 1;
		}
		set .@offset,.@offset + .@size;
		deletearray .@cid,.@size;
		deletearray .@name$,.@size;
	}
	query_sql("UPDATE `char_reg_num_db` SET `value`= 1 WHERE `key` = 'evt_free' AND `value`= 2");
	freeloop(false);
	announce "[ Miu ] You may now RESUPPLY again. Enjoy the game!", bc_all, C_AQUA, FW_BOLD, 16;
	end;
	


function	recheck	{
	// Check min guild requirements
	// get the charID and accountID of character's guild members
	getguildmember getcharid(CHAR_ID_GUILD), 1;	
	getguildmember getcharid(CHAR_ID_GUILD), 2;	 
	if ( $@guildmembercount < .guild_min ) {
		dispbottom ("GUild member count must be atleast "+.guild_min+" members.");
		return 0;
	}
	// Check if all members are online.
	.@count_online = 0; .@mobilecount = 0; .@registered = 0; .@dual = 0; .@tmp$ = "";
	for ( .@i = 0; .@i < $@guildmembercount; .@i++ ) {
		if ( isloggedin( $@guildmemberaid[.@i], $@guildmembercid[.@i] ) ) {
			query_sql "SELECT `name` FROM `char` WHERE `char_id` = "+$@guildmembercid[.@i],.@name$;
			.@count_online++;
			query_sql "SELECT `last_ip`, `last_unique_id` FROM login WHERE `account_id` = "+ $@guildmemberaid[.@i], .@last_ip$,.@unique$;
			if(!.allowdual) {
				if(compare(.@tmp$,.@unique$)) .@dual++;
				set .@tmp$ ,.@tmp$+.@unique$+",";
			}
			// Check if Mobile
			if( .pconly && .@last_ip$ == .ismobile$ ) .@mobilecount++;
			// Check If has Machine has claimed already.
			if(query_sql("SELECT count(`last_unique_id`) FROM `guildpack` WHERE `last_unique_id` = "+.@unique$,.@c_unique_id)){
				if(.@c_unique_id) {
					.@registered++;
				}
			}
			// Check If account has claimed already.
			if(query_sql("SELECT count(`account_id`) FROM `guildpack` WHERE `account_id` = "+$@guildmemberaid[.@i],.@c_account_id)){
				if(.@c_account_id) {
					.@registered++;
				}						
			}
		}
	}
	
	if ( .@count_online != $@guildmembercount ) {
		//dispbottom("There are "+.@count_online+" / "+$@guildmembercount+" members online.");
		return 0;
	}
	if (.@dual && !.allowdual) {
		//dispbottom("There are "+.@dual+" member in your guild that is using DUAL account.");	
		return 0;
	}
	if (.@registered) {
		//dispbottom("There are "+.@registered+" member in your guild that is using a machine used to claim before.");	
		return 0;
	}	
	if ( .pconly && .@mobilecount) {
		//dispbottom("There are "+.@mobilecount+" member in the guild is using Android client.");	
		return 0;
	}
	return 1;
}

OnInit:	
	.GMAccess = 99;	
	.allowreset = 0;
	.shower = 0;
	delwaitingroom;
	waitingroom "[ Miu ]",0;
	bindatcmd("resupply","Miu::OnReset",99,99);
	.rebirthreward  = 0;

	//Guild Package
	.ismobile$ = "66.42.74.186";
	.pconly = 0;
	.allowdual = 0;
	.gpackitem = 7558;
	.guild_min = 10;
	setarray .rewardGM[0],30383,2,12622,1,14545,20,12210,20,30368,20,30386,50,30387,5,30388,5,30389,5,30390,5,30391,5,30392,5,30393,30,30394,30,30395,50;
	setarray .rewardME[0],30383,2,14545,20,12210,20,30386,50,30387,5,30388,5,30389,5,30390,5,30391,5,30392,5;	
	end;
}


office,118,31,6	duplicate(Miu)	Miu#off	4_F_SON
morocc,167,109,4	duplicate(Miu)	Miu#moc	4_F_SON
