quest guild_building begin
	state start begin
		when guild_man1.chat.gameforge.guild_manage._10_npcChat or guild_man2.chat.gameforge.guild_manage._10_npcChat or guild_man3.chat.gameforge.guild_manage._10_npcChat with pc.is_gm() begin

			say_title(gameforge.find_squareguard._10_targetVid)
			say(gameforge.guild_manage._20_say)
			local u_name = input()
			local u_vid=find_pc_by_name(u_name)

			if u_vid==0 then 
				say_title(gameforge.guild_manage._30_sayTitle)
				say(u_name)
				return
			end

			local old_vid = pc. select(u_vid , u_vid )
			u_withdrawTime=pc.getqf("new_withdraw_time")
			u_withdrawTime=pc.getqf("new_withdraw_time")
			pc. select(old_vid , old_vid )

			withdrawDelay=game.get_event_flag("guild_withdraw_delay")
			disbandDelay=game.get_event_flag("guild_disband_delay")

			say_title(gameforge.find_squareguard._10_targetVid)
			say(gameforge.guild_manage._40_say)

			if u_withdrawTime>0 then
				say(string.format(gameforge.guild_manage._50_say, time_to_str(u_withdrawTime)..gameforge.guild_manage._55_say.. withdrawDelay))
			end

			if u_disbandTime>0 then
				say(string.format(gameforge.guild_manage._60_say, time_to_str(u_disbandTime)..gameforge.guild_manage._65_say.. disbandDelay))
			end

			local retryTime1 = u_withdrawTime + withdrawDelay*86400
			local retryTime2 = u_withdrawTime + disbandDelay*86400

			local retryTime = 0
			if retryTime1 > retryTime2 then 
				retryTime = retryTime1
			else 
				retryTime = retryTime2 
			end

			local curTime = get_time()
			if curTime < retryTime then
				say(string.format(gameforge.guild_manage._70_say, time_to_str(retryTime)..gameforge.guild_manage._75_say..((retryTime-curTime)/3600)))

				if is_test_server() then
					local s= select(gameforge.guild_manage._80_select, gameforge.arena_manager._200_tableInsert)
					if s==1 then
						local old_vid = pc. select(u_vid , u_vid )
						local curTime=get_time()
						pc.setqf("new_withdraw_time", curTime-withdrawDelay*86400)
						pc.setqf("new_withdraw_time", curTime-disbandDelay*86400)
						pc. select(old_vid , old_vid )
					end
				end
			else
				say(gameforge.guild_manage._90_say)
			end
		end
		when guild_man1.chat.gameforge.guild_manage._100_npcChat or guild_man2.chat.gameforge.guild_manage._100_npcChat or guild_man3.chat.gameforge.guild_manage._100_npcChat with pc.is_gm() begin

			test_chat(string.format(gameforge.guild_manage._110_chat, bool_to_str(pc.has_guild()).." [ENTER]pc.is_guildmaster: "..bool_to_str(pc.isguildmaster()).." [ENTER]pc.empire: "..pc.empire.." [ENTER]npc.empire: "..npc.empire))
		end
		when guild_man1.chat.gameforge.locale.guild.withdraw or guild_man2.chat.gameforge.locale.guild.withdraw or guild_man3.chat.gameforge.locale.guild.withdraw with pc.hasguild() and not pc.isguildmaster() and (pc.is_gm() or npc.empire == pc.empire) begin

			say_title(gameforge.find_squareguard._10_targetVid)
			say(gameforge.guild_manage._120_say)
			local s =  select(gameforge.locale.guild.yes, gameforge.locale.guild.no)
			if s==1 then
				say_title(gameforge.find_squareguard._10_targetVid)
				say(gameforge.guild_manage._130_say)
				pc.remove_from_guild()
				pc.setqf("new_withdraw_time",get_global_time())
			end
		end

		when guild_man1.chat.gameforge.locale.guild.disband or guild_man2.chat.gameforge.locale.guild.disband or guild_man3.chat.gameforge.locale.guild.disband with pc.hasguild() and pc.isguildmaster() and (pc.is_gm() or npc.empire == pc.empire) begin
			say_title(gameforge.find_squareguard._10_targetVid)
			say(gameforge.guild_manage._140_say)
			local s =  select(gameforge.locale.guild.yes, gameforge.locale.guild.no)
			if s==1 then
			say_title(gameforge.find_squareguard._10_targetVid)
			say(gameforge.guild_manage._150_say)
			pc.destroy_guild()
			pc.setqf("new_disband_time", get_global_time())
			pc.setqf("new_withdraw_time", get_global_time())
			end
		end

		when guild_man1.chat.gameforge.guild_manage._160_npcChat or guild_man2.chat.gameforge.guild_manage._170_npcChat or guild_man3.chat.gameforge.guild_manage._170_npcChat begin
			local level_limit;
			local guild_create_item

			level_limit = 40
			guild_create_item = false
																	 
			if pc.hasguild() then
				return
			end
			if game.get_event_flag("guild_withdraw_delay")*86400 > 
				get_global_time() - pc.getqf("new_withdraw_time") then
			say_title(gameforge.find_squareguard._10_targetVid)
			say(gameforge.guild_manage._180_say)
-- say(string.format(gameforge.guild_manage._190_say, game.get_event_flag("guild_withdraw_delay")))
			return
			end

			if game.get_event_flag("guild_disband_delay")*86400 > 
				get_global_time() - pc.getqf("new_withdraw_time") then
			say_title(gameforge.find_squareguard._10_targetVid)
			say(gameforge.guild_manage._200_say)
-- say(string.format(gameforge.guild_manage._190_say, game.get_event_flag("guild_disband_delay")))
			return
			end
			say_title(gameforge.find_squareguard._10_targetVid)
			say(gameforge.guild_manage._210_say)
			local s =  select(gameforge.locale.guild.yes, gameforge.locale.guild.no)
			if s == 2 then
				return
			end

			if pc.level >= 40 then
			if pc.gold >= 200000 then

				if not guild_create_item or pc.countitem(guild_create_item)>0 then
					game.request_make_guild()
				end

				else
				say_title(gameforge.find_squareguard._10_targetVid)
				say(gameforge.guild_manage._220_say)
				return
				end
			else
			say_title(gameforge.find_squareguard._10_targetVid)
			say(gameforge.guild_manage._230_say)
			end
		end
	end
end


