function startBriefingEndFight()
	briefingEndFight = {}
	briefingEndFight.finished = BriefingEndFightFinished
	local page = 0
	page = page + 1
	briefingEndFight[page] = {}
	briefingEndFight[page].title = "Mentor"
	briefingEndFight[page].text = "Wir wurden ausgetrickst! Kerberos hat sich gar nicht in der schwarzen Festung aufgehalten. @cr Euer Falke hat da etwas erspäht."
	briefingEndFight[page].position = GetPosition("dario")
	page = page + 1
	briefingEndFight[page] = {}
	briefingEndFight[page].title = "Mentor"
	briefingEndFight[page].text = "Kerberos besitzt eine zweite Basis, welche sehr schwer befestigt zu sein scheint. @cr Seine stärksten Krieger werden dort stationiert sein und auch diese Türme sehen nicht gerade normal aus, wenn ihr mich fragt."
	briefingEndFight[page].position = GetPosition("EndBossMiddleSpawn")
	briefingEndFight[page].explore = 4500
	--endbossvision = briefingEndFight[page]
	page = page+1
	briefingEndFight[page] = {}
	briefingEndFight[page].title = "Mentor"
	briefingEndFight[page].text = "Und hier scheint ihr auch nicht ohne Weiteres so leicht vorbei zu kommen."
	briefingEndFight[page].position = GetPosition("TruppenMassen")
	briefingEndFight[page].explore = 4500
	--Middlebasevision = briefingEndFight[page]
	page = page+1
	briefingEndFight[page] = {}
	briefingEndFight[page].title = "Mentor"
	briefingEndFight[page].text = "Macht euch für den Finalen Schlag bereit und vertreibt den Schurken ein für alle mal!"
	briefingEndFight[page].position = GetPosition("firstdefense")
	briefingEndFight[page].explore = 2500
	--firstdefensevision = briefingEndFight[page]
	Display.GfxSetSetFogParams(1, 0.0, 1.0, 1, 152,172,182, 5000,29000)
	Display.GfxSetSetFogParams(2, 0.0, 1.0, 1, 102,132,142, 3000,29000)
	Display.GfxSetSetFogParams(3, 0.0, 1.0, 1, 152,172,182, 3000,29000)
	BRIEFING_ZOOMDISTANCE = 10000
	Camera.ZoomSetFactorMax(1.5)
	Camera.ZoomSetFactor(1.5)
	StartBriefing(briefingEndFight)
end

function BriefingEndFightFinished()
	GUI.DestroyMinimapPulse(briefingPrelude[2].position.X,briefingPrelude[2].position.Y)
	GUI.CreateMinimapPulse(GetPosition("FinalBase").X,GetPosition("FinalBase").Y,3)
	Display.GfxSetSetFogParams(1, 0.0, 1.0, 1, 152,172,182, 5000,29000)
	Display.GfxSetSetFogParams(2, 0.0, 1.0, 1, 102,132,142, 3000,29000)
	Display.GfxSetSetFogParams(3, 0.0, 1.0, 1, 152,172,182, 3000,29000)
	Camera.ZoomSetFactorMax(1.5)
	Camera.ZoomSetFactor(1.5)
	--ResolveBriefing(briefingEndFight[2])
	ResolveBriefing(briefingEndFight[3])
	ResolveBriefing(briefingEndFight[4])
	DestroyBuidlings()
	ChangeWalls()
	Logic.SetQuestType(1, 1, MAINQUEST_CLOSED, 1)
	Logic.AddQuest(1,4,MAINQUEST_OPEN, "Der Finale Schlag","Kerberos hat euch hinters Licht geführt und sich in seiner schwer befestigen Basis in den Bergen verschanzt. Es wird nicht einfach sein ihn zu erreichen, zumal massive Verteidungsanlagen vor euch stehen. @cr Schlagt euch bis zu seiner Festung durch und macht sie dem Erdboden gleich auf dass Frieden in diesem Land hersche!",1)
	waffenstillstand = 5400
	PlayerWaterAttackUA:Destroy()
	PlayerLandAttackUA:Destroy()
	StartSimpleJob("TimeForLastFight")
	MapLocal_StartCountDown(waffenstillstand+2)
end

function DestroyBuidlings()
	--Logic.GetAttachedWorkersToBuilding(_id)
	--Logic.PlayerReAttachAllWorker(_player)
	local buildingstable = {
	"part1building1",
	"part1building2",
	"part1building3",
	"part1building4",
	"Reward2",
	"part1building14",
	"part2building1",
	"part2building2",
	"part2building7",
	"part2building9",
	"part3building1",
	"part3building2",
	"part3building3",
	"part4building10",
	"part4building11",
	"part4building12",
	"part4building13",
	"InvisMine",
	"part4building2",
	"part4building5",
	"part4building17",
	"part4building4",
	"part4building8"
	}
	for _key,_iid in ipairs(buildingstable) do
		local workerstable = {Logic.GetAttachedWorkersToBuilding(Logic.GetEntityIDByName(_iid))}
		for workercounter = 1, table.getn(workerstable)-1,1 do
			Logic.DestroyEntity(workerstable[workercounter+1])
		end
		SetHealth(_iid,0)
	end
--[[	
	SetHealth("part1building1",0)
	SetHealth("part1building2",0)
	SetHealth("part1building3",0)
	SetHealth("part1building4",0)
	SetHealth("Reward2",0)
	SetHealth("part1building14",0)
	SetHealth("part2building1",0)
	SetHealth("part2building2",0)
	SetHealth("part2building7",0)
	SetHealth("part2building9",0)
	SetHealth("part3building1",0)
	SetHealth("part3building2",0)
	SetHealth("part3building3",0)
	SetHealth("part4building10",0)
	SetHealth("part4building11",0)
	SetHealth("part4building12",0)
	SetHealth("part4building13",0)
	SetHealth("InvisMine",0)
	SetHealth("part4building2",0)
	SetHealth("part4building5",0)
	SetHealth("part4building17",0)
	SetHealth("part4building4",0)
	SetHealth("part4building8",0)
	]]
end

function ChangeWalls()
	local placeids = {
	{"checkpointtoor1",nil},
	{"checkpointtoor2",4000},
	{"checkpointtoor3",nil},
	{"checkpointtoor4",nil},
	{"checkpointtoor6",nil},
	{"RandomChest6",nil},
	{"innerFestungSpawn2",nil},
	{"innerFestungSpawn3",nil},
	{"defend1",nil},
	{"defend3",nil},
	{"InnerGate8",nil},
	{"InnerGate7",nil},
	{"InnerGate5",nil}
	}
	for i = 1,table.getn(placeids),1 do
		local entitiypos = GetPosition(placeids[i][1])
		local wallnumbers,wallentID = Logic.GetPlayerEntitiesInArea(3,0,entitiypos.X,entitiypos.Y,placeids[i][2] or 3500,1)
		while wallnumbers > 0 do
			Logic.ChangeEntityPlayerID(wallentID, 4)
			wallnumbers,wallentID = Logic.GetPlayerEntitiesInArea(3,0,entitiypos.X,entitiypos.Y,placeids[i][2] or 3500,1)
		end
	end
end

function TimeForLastFight()
	if waffenstillstand <= 0 then
		waffenstillstand = nil
		watertimer = 10
		StartSimpleHiResJob("LowerWater")
		StartLastAttack()
		MapLocal_StopCountDown(0)
		return true
	elseif waffenstillstand == 2 then
		weathertime = 0
		local weatherstate = Logic.GetWeatherState()
		if weatherstate <= 2 then
			Logic.AddWeatherElement(3,1000,0,3,5,10)
		else
			local RainOrClear = math.random(1,2)
			Logic.AddWeatherElement(RainOrClear,1000,0,RainOrClear,5,10)
		end
	elseif waffenstillstand == 200 then
		suddenDeathflag = true
		ChangeWeatherStuff()
		lightingsoundtimer = math.random(7,17)
		BLitzTriggerID = StartSimpleJob("RideTheLightning")
		createLastFightArmy()
	elseif waffenstillstand == 1170 then
		Stream.Start("Voice\\CM01_20_BattleOfEvelance_Txt\\briefingReinforcementArrives[1].text.mp3", 127)
		local SerfSpawnerpos = GetPosition("SerfSpawner")
		GUI.ScriptSignal(SerfSpawnerpos.X, SerfSpawnerpos.Y, 0)
		CreateAllies()
	elseif waffenstillstand == 2400 then
		createBriefingExplain()
		RohStoffTriggerCounter = 60 
		RohStoffTriggerID = Trigger.RequestTrigger(Events.LOGIC_EVENT_EVERY_SECOND,"","GRessources",1)
	end
	waffenstillstand = waffenstillstand - 1
	return false
end

function GRessources() 
	if RohStoffTriggerCounter <= 0 then 
		Tools.GiveResouces(1, 20000, 1000,5000, 6000,10000,5000) 
		RohStoffTriggerCounter = 60 
	else 
		RohStoffTriggerCounter = RohStoffTriggerCounter - 1 
	end 
	return false 
end

function createBriefingExplain()
	MapLocal_CameraPositionBackup()
	BriefingExplain = {}
	BriefingExplain.finished = SetupDocuments
	local page = 0
	page = page + 1
	BriefingExplain[page] = {}
	BriefingExplain[page].title = "Mentor"
	BriefingExplain[page].text = "Meister! Seht doch!"
	BriefingExplain[page].position = MapLocal_CameraPositionBackup()
	page = page + 1
	BriefingExplain[page] = {}
	BriefingExplain[page].title = "Mentor"
	BriefingExplain[page].text = "In den Trümern der zerstörten Festung habe ich einige Dokumente gefunden, welche Informationen über diese unglaublich großen Türme und die Festung selbst liefern"
	BriefingExplain[page].position = GetPosition("defend1")
	page = page + 1
	BriefingExplain[page] = {}
	BriefingExplain[page].title = "Mentor"
	BriefingExplain[page].text = "Ich stelle euch die Dokumente soweit sie erhalten sind in euerm Auftragsmenü zur Verfügung."
	BriefingExplain[page].position = GetPosition("FinalBase")
	page = page + 1
	BriefingExplain[page] = {}
	BriefingExplain[page].title = "Mentor"
	BriefingExplain[page].text = "Außerdem steht euer gesamtes Königreich hinter euch und beliefert euch stetig mit Rohstoffen."
	BriefingExplain[page].position = GetPosition("defend1")
	StartBriefing(BriefingExplain)
end

function SetupDocuments()
	Logic.AddQuest(1,5,SUBQUEST_OPEN, "Dokumente","Dokumente zum Endkampf: @cr @cr Die Türme haben normale Reichweite wie jeder andere Turm. Der Balistaturm dagegen kann sehr schnell schießen. @cr Beide Türme haben je 100.000 Leben gehalten und müssen separat ausgeschaltet werden. @cr Solange diese Türme am Leben sind, ist die Festung unverwundbar. Wenn die Türme außer Gefecht gesetzt sind, könnt ihr die Festung angreifen. @cr @cr Diese hat 500.000 Leben. @cr @cr Die Türme und die Festung sind eventuell nicht im Nahkampf angreifbar, was auf das künstlich erzeugte Blocking zurückzuführen ist. @cr Die Leben der Strukturen werden über einen Bossbalken visuell dargestellt. Die Lebensanzahl der Türme werden dabei addiert abgebildet. @cr Ihr werdet sehr viele Truppen und Rohstoffe brauchen; bereitet euch deshalb sehr gut vor. Es wird größtmöglich alles gegen euch spielen. @cr @cr Hinweis: Erec Buff funktioniert auf die Türme und die Festung bei Kanonen.",1)
end

function ChangeWeatherStuff()
	Display.GfxSetSetRainEffectStatus(1, 0.0, 1.0, 1)
	Display.GfxSetSetRainEffectStatus(2, 0.0, 1.0, 1)
	Display.GfxSetSetRainEffectStatus(3, 0.0, 1.0, 1)
	weatherGFXcounter = 0
	if weathertriggerfuncID == nil then
		weathertriggerfuncID = Trigger.RequestTrigger(Events.LOGIC_EVENT_EVERY_SECOND, "", "weatherfunc", 1)
	end
	StartSimpleJob("WeatherChangerJob")
end
function WeatherChangerJob()
	if weatherGFXcounter == 11 then
		Display.GfxSetSetLightParams(1,  0.0, 1.0, 40, -15, -50,  255,70,70, 128,104,72)
		Display.GfxSetSetLightParams(2,  0.0, 1.0, 40, -15, -50,  255,70,70, 128,104,72)
		Display.GfxSetSetLightParams(3,  0.0, 1.0, 40, -15, -50,  255,70,70, 255,234,202)
		weatherGFXcounter = nil
		return true
	end
	weatherGFXcounter = weatherGFXcounter + 1
	Display.GfxSetSetLightParams(1,  0.0, 1.0, 40, -15, -50,  136+(weatherGFXcounter*11.9),144-(weatherGFXcounter*7.4),144-(weatherGFXcounter*7.4), 128,104,72)
	Display.GfxSetSetLightParams(2,  0.0, 1.0, 40, -15, -50,  136+(weatherGFXcounter*11.9),144-(weatherGFXcounter*7.4),144-(weatherGFXcounter*7.4), 128,104,72)
	Display.GfxSetSetLightParams(3,  0.0, 1.0, 40, -15, -50,  116+(weatherGFXcounter*13.9),144-(weatherGFXcounter*7.4),164-(weatherGFXcounter*9.4), 255,234,202)
	return false
end

function StartLastAttack()
	Stream.Start("Voice\\CM01_11_Norfolk_Txt\\AttackStarted.mp3",127)
	Logic.SetDiplomacyState(1, 6, Diplomacy.Hostile)
	LastFightPart = 1
	
	function
	LocalMusic.CallbackSettlerKilled(_HurterPlayerID, _HurtPlayerID)
	end
	
	function GameCallback_SetWeather(Weather)

	-- These are only in local variables for clarity - they are initialized with the values
	-- used when the weather is normal (i.e. Weather == 1)
	local Duration = 300
	local IsPeriodic = 0    -- This should always be 0 for weather set by the weather machine
	local GfxState = 1      
	local TransitionForerun = 4
	local TransitionDuration = 8
		 
	-- If the passed in weather type is not "Normal", then the parameters sent to 
	-- "Logic.AddWeatherElement" need changing. In this example rain just uses a different
	-- Gfx set, and snow uses a longer duration and transition times
	if Weather == 2 then
		-- "Rain" Set the parameters as they are required for rain
		GfxState = 2
	elseif Weather == 3 then
		-- "Snow" Set the parameters as they are required for snow
		Duration = 400
		GfxState = 3
		TransitionForerun = 5
		TransitionDuration = 10
	end

	-- Call the function that actually sets the weather
	Logic.AddWeatherElement(Weather, Duration, IsPeriodic, GfxState, TransitionForerun, TransitionDuration)
	
	--restart music
	--LocalMusic.SongLength = Logic.GetTime() + TransitionDuration
	end
	
	function
		LocalMusic_UpdateMusic()
			if LocalMusic.BattlesOnTheMap == 0 then
				--Music is playing?
				if  LocalMusic.SongLength  > Logic.GetTime() then	 
					return
				end	
			end
			local SetToUse
			LocalMusic.BattlesOnTheMap = 1
			if LocalMusic.BattlesOnTheMap == 1 then
				SetToUse = LocalMusic.SetBattle
			end
			local SongAmount = table.getn(SetToUse)
			local Random = 1 + XGUIEng.GetRandom(SongAmount-1)
			local SongToPlay = Folders.Music .. SetToUse[Random][1]	
			Sound.StartMusic( SongToPlay, 130)
			LocalMusic.SongLength =  Logic.GetTime() + SetToUse[Random][2]
			LocalMusic.BattlesOnTheMap = 0
	end
	
	LocalMusic.SongLength = 0	
	UAFirstRoomDef:AddCommandDefend(GetPosition("firstdefense"),8000,true)
	UASecondRoomDef:AddCommandDefend(GetPosition("TruppenMassen"),15000,true)
end

function LowerWater()
	if watertimer == 0 then
		weathertime = 60
		watertimer = nil
		return true
	end
	Logic.WaterSetAbsoluteHeight(468, 261, 492, 320, 6)
	watertimer = watertimer - 1
	return false
end

function CreateAllies()
	Logic.SetPlayerRawName(7, "Verbündete")
	AI.Player_EnableAi(7)
	AI.Village_SetSerfLimit(7,2)
	AI.Village_EnableConstructing(7,1)
	AI.Village_EnableExtracting(7,false)
	Logic.SetPlayerPaysLeaderFlag(7,0)
	Logic.SetDiplomacyState(7, 6, 3)
	for i = 1,3,1 do
	Logic.UpgradeSettlerCategory(UpgradeCategories.LeaderPoleArm, 7)
	Logic.UpgradeSettlerCategory(UpgradeCategories.SoldierPoleArm, 7)
	Logic.UpgradeSettlerCategory(UpgradeCategories.LeaderSword, 7)
	Logic.UpgradeSettlerCategory(UpgradeCategories.SoldierSword, 7)
	Logic.UpgradeSettlerCategory(UpgradeCategories.LeaderBow, 7)
	Logic.UpgradeSettlerCategory(UpgradeCategories.SoldierBow, 7)
	end
	local serfpos = GetPosition("SerfSpawner")
	Logic.CreateEntity(Entities.PU_Serf, serfpos.X, serfpos.Y, 225.0, 7)
	Logic.CreateEntity(Entities.PU_Serf, serfpos.X, serfpos.Y, 225.0, 7)
	Logic.CreateEntity(Entities.PU_Serf, serfpos.X, serfpos.Y, 225.0, 7)
	Logic.CreateEntity(Entities.PU_Serf, serfpos.X, serfpos.Y, 225.0, 7)
	
	function
	GameCallback_OnBuildingConstructionComplete(_BuildingID, _PlayerID)
	
	Score.OnBuildingConstructionComplete(_BuildingID, _PlayerID)

	local PlayerID = GUI.GetPlayerID()
	if PlayerID ~= _PlayerID then
		return
	end
	
	--Update all buttons in the visible container
	XGUIEng.DoManualButtonUpdate(gvGUI_WidgetID.InGame)	
	
	--GameCallback_GUI_SelectionChanged()
	if Logic.IsBuilding(GUI.GetSelectedEntity())== 1 then
		GUI.SetSelectedEntity(GUI.GetSelectedEntity())
	end
	if _PlayerID == 7 then
		if Logic.GetEntityTypeName(Logic.GetEntityType(_BuildingID)) == "PB_Archery1" then
			Logic.SetEntityName(_BuildingID, "SupportBarrackRecruiter")
			SupportRecruiter:AddBuilding(_BuildingID)	
		elseif Logic.GetEntityTypeName(Logic.GetEntityType(_BuildingID)) == "PB_Barracks1" then
			Logic.SetEntityName(_BuildingID, "SupportArcheryRecruiter")
			SupportRecruiter:AddBuilding(_BuildingID)	
		end
		
	end
end
	SupportUA = UnlimitedArmy:New({
					Player = 7,
					Area = 4200,
					TransitAttackMove = true,
					Formation = UnlimitedArmy.Formations.Chaotic,
					LeaderFormation = FormationFunktion,
					AIActive = true,
					AutoRotateRange = true,
					DoNotNormalizeSpeed = true
					})
	local pP7Burgpos = 	GetPosition("SupportBurg")
	Logic.CreateConstructionSite(pP7Burgpos.X, pP7Burgpos.Y, 0, Entities.PB_Headquarters1, 7)
	StartSimpleJob("BuildAllyHouses")
end

function BuildAllyHouses()
	local burgentities,burgID = Logic.GetPlayerEntities(7, Entities.PB_Headquarters1, 1)
	if burgentities == 1 then
		if Logic.IsConstructionComplete(burgID) == 1 then
			local barrackentities,barrackID = Logic.GetPlayerEntities(7, Entities.PB_Barracks1, 1)
			if barrackentities == 1 then
				if Logic.IsConstructionComplete(barrackID) == 1 then
					local archeryentities,archeryID = Logic.GetPlayerEntities(7, Entities.PB_Archery1, 1)
					if archeryentities == 1 then
						if Logic.IsConstructionComplete(archeryID) == 1 then
							SupportRecruiter = UnlimitedArmyRecruiter:New(SupportUA, {
							Buildings = {archeryID,barrackID},
							ArmySize = 10,
							UCats = {
									{UCat = UpgradeCategories.LeaderSword, SpawnNum = 1, Looped = true},
									{UCat = UpgradeCategories.LeaderPoleArm, SpawnNum = 1, Looped = true},
									{UCat = UpgradeCategories.LeaderBow, SpawnNum = 1, Looped = true},
									},
							ResCheat = true,
							ReorderAllowed = true,
							RandomizeSpawn = true,
							DoNotRemoveIfDeadOrEmpty = true
									})
							GiveSupportUACommands()
							StartSerfsDestroyStones()
							return true
						end
					else
						local P7ArcheryPos = GetPosition("SupportSchiesplatz")
						Logic.CreateConstructionSite(P7ArcheryPos.X, P7ArcheryPos.Y, 0, Entities.PB_Archery1, 7)
					end
				end
			else
				local P7Bararckpos = GetPosition("SupportBarracks")
				Logic.CreateConstructionSite(P7Bararckpos.X, P7Bararckpos.Y, 0, Entities.PB_Barracks1, 7)
			end
		end
	end
	return false
end

function GiveSupportUACommands()
	SupportUA:AddCommandMove(GetPosition("supportWaypoint1"),true)
	SupportUA:AddCommandWaitForSpawnerFull(true)
	SupportUA:AddCommandSetSpawnerStatus(false, true)
	SupportUA:AddCommandLuaFunc(UASpawnerFullAndStonesGone,true)
	SupportUA:AddCommandLuaFunc(SupportUAMoveCommand,true)
	SupportUA:AddCommandSetSpawnerStatus(true, true)
end

function SupportUAMoveCommand(self)
	local s = self:GetSize(true,false)
	if s == 0 then
		return true
	end
	if self:IsIdle() then
		if LastFightPart == 1 then
			return false,UnlimitedArmy.CreateCommandMove(GetPosition("firstdefense"))
		elseif LastFightPart == 2 then
			return false,UnlimitedArmy.CreateCommandMove(GetPosition("TruppenMassen"))
		elseif LastFightPart == 3 or LastFightPart == 4 then
			return false,UnlimitedArmy.CreateCommandMove(GetPosition("EndBossMiddleSpawn"))
		end
	end
	return false
end

function UASpawnerFullAndStonesGone(self)
	if not IsValid("supportstone4") then
		local s = self:GetSize()
		if not self.Spawner or s >= self.Spawner.ArmySize then
			return true
		end
	end
	return false
end

function StartSerfsDestroyStones()
	local serftable = {Logic.GetPlayerEntities(7, Entities.PU_Serf, 4)}
	Logic.HurtEntity(serftable[4], 1000)
	Logic.HurtEntity(serftable[5], 1000)
	--Logic.DestroyEntity(serftable[4])
	--Logic.DestroyEntity(serftable[5])
	Stonecounter = 0
	StonecounterTimer = 240
	Trigger.RequestTrigger(Events.LOGIC_EVENT_EVERY_SECOND,"","SerfDestroyingStones",1,nil,{serftable[2],serftable[3]})
end

function SerfDestroyingStones(firstSerf,secondSerf)
	if Stonecounter < 3 then
		if Stonecounter < 1 then
			Move(firstSerf,"supportserf11",100)
			Move(secondSerf,"supportserf12",100)
			Stonecounter = 1
		else
			if Stonecounter ~= 2 then 
				if IsNear(firstSerf,"supportserf11",100) and IsNear(secondSerf,"supportserf12",100) then
					LookAt(firstSerf,"supportstone1")
					LookAt(secondSerf,"supportstone1")
					Logic.SetTaskList(firstSerf, TaskLists.TL_SERF_EXTRACT_RESOURCE)
					Logic.SetTaskList(secondSerf, TaskLists.TL_SERF_EXTRACT_RESOURCE)
					Stonecounter = 2
				else
					if not Logic.IsEntityMoving(firstSerf) then
						Move(firstSerf,"supportserf11")
					end
					if not Logic.IsEntityMoving(firstSerf) then
						Move(secondSerf,"supportserf12")
					end
				end
			else
				if StonecounterTimer == 0 then
					DestroyEntity("supportstone1")
					StonecounterTimer = 240
					Stonecounter = 3
					return false
				elseif StonecounterTimer > 0 then
					StonecounterTimer = StonecounterTimer - 1
				end
			end
		end
	elseif Stonecounter < 6 then
		if Stonecounter < 4 then
			Move(firstSerf,"supportserf21",100)
			Move(secondSerf,"supportserf22",100)
			Stonecounter = 4
		else
			if Stonecounter ~= 5 then
				if IsNear(firstSerf,"supportserf21",100) and IsNear(secondSerf,"supportserf22",100) then
					LookAt(firstSerf,"supportstone2")
					LookAt(secondSerf,"supportstone2")
					Logic.SetTaskList(firstSerf, TaskLists.TL_SERF_EXTRACT_RESOURCE)
					Logic.SetTaskList(secondSerf, TaskLists.TL_SERF_EXTRACT_RESOURCE)
					Stonecounter = 5
				else
					if not Logic.IsEntityMoving(firstSerf) then
						Move(firstSerf,"supportserf21")
					end
					if not Logic.IsEntityMoving(firstSerf) then
						Move(secondSerf,"supportserf22")
					end
				end
			else
				if StonecounterTimer == 0 then
					DestroyEntity("supportstone2")
					StonecounterTimer = 240
					Stonecounter = 6
					return false
				elseif StonecounterTimer > 0 then
					StonecounterTimer = StonecounterTimer - 1
				end
			end
		end	
	elseif Stonecounter < 9 then
		if Stonecounter < 7 then
			Move(firstSerf,"supportserf31",100)
			Move(secondSerf,"supportserf32",100)
			Stonecounter = 7
		else
			if Stonecounter ~= 8 then
				if IsNear(firstSerf,"supportserf31",100) and IsNear(secondSerf,"supportserf32",100) then
					LookAt(firstSerf,"supportstone3")
					LookAt(secondSerf,"supportstone3")
					Logic.SetTaskList(firstSerf, TaskLists.TL_SERF_EXTRACT_RESOURCE)
					Logic.SetTaskList(secondSerf, TaskLists.TL_SERF_EXTRACT_RESOURCE)
					Stonecounter = 8
				else
					if not Logic.IsEntityMoving(firstSerf) then
						Move(firstSerf,"supportserf31")
					end
					if not Logic.IsEntityMoving(firstSerf) then
						Move(secondSerf,"supportserf32")
					end
				end
			else
				if StonecounterTimer == 0 then
					DestroyEntity("supportstone3")
					StonecounterTimer = 240
					Stonecounter = 9
					return false
				elseif StonecounterTimer > 0 then
					StonecounterTimer = StonecounterTimer - 1
				end
			end
		end
	elseif Stonecounter < 12 then
		if Stonecounter < 10 then
			Move(firstSerf,"supportserf41",100)
			Move(secondSerf,"supportserf42",100)
			Stonecounter = 10
		else
			if Stonecounter ~= 11 then
				if IsNear(firstSerf,"supportserf41",100) and IsNear(secondSerf,"supportserf42",100) then
					LookAt(firstSerf,"supportstone4")
					LookAt(secondSerf,"supportstone4")
					Logic.SetTaskList(firstSerf, TaskLists.TL_SERF_EXTRACT_RESOURCE)
					Logic.SetTaskList(secondSerf, TaskLists.TL_SERF_EXTRACT_RESOURCE)
					Stonecounter = 11
				else
					if not Logic.IsEntityMoving(firstSerf) then
						Move(firstSerf,"supportserf41")
					end
					if not Logic.IsEntityMoving(firstSerf) then
						Move(secondSerf,"supportserf42")
					end
				end
			else
				if StonecounterTimer == 0 then
					DestroyEntity("supportstone4")
					Logic.HurtEntity(firstSerf, 1000)
					Logic.HurtEntity(secondSerf, 1000)
					--DestroyEntity(firstSerf)
					--DestroyEntity(secondSerf)
					--UA befehle; ist oben schon geschrieben!
					return true
				elseif StonecounterTimer > 0 then
					StonecounterTimer = StonecounterTimer - 1
				end
			end
		end
	end
	return false
end
--Blitzfunc
function RideTheLightning()
	if XGUIEng.IsWidgetShown(gvGUI_WidgetID.MainMenuWindow) == 1 or XGUIEng.IsWidgetShown(XGUIEng.GetWidgetID("MainMenuSaveWindow")) == 1 or XGUIEng.IsWidgetShown(XGUIEng.GetWidgetID("MainMenuBoxOverwriteWindow")) == 1 or Trigger.IsTriggerEnabled(QuickSaveDelayerID) then
		if LightningLastTime == nil then
			LightningLastTime = Logic.GetTime()
		end
		return false
	end
    local WorldX,WorldY = Logic.WorldGetSize()
	local lookatposX,lookatposY = Camera.ScrollGetLookAt()
    local rX, rY, rZ
    local screen
	local Toleranzarea
	local toleranzY
    for i = 1, 5,1 do
		if gvCamera.ZoomFac <= 1 then 
			Toleranzarea = 2043.087*(gvCamera.ZoomFac*gvCamera.ZoomFac*gvCamera.ZoomFac)-1418.939*(gvCamera.ZoomFac*gvCamera.ZoomFac)+1765.852*(gvCamera.ZoomFac)+510
		else
			Toleranzarea = 3416.667*gvCamera.ZoomFac-516.667
		end
        rX = math.random(lookatposX-Toleranzarea,lookatposX+Toleranzarea)
		if rX > WorldX-1000 then
			rX = 69399
		elseif rX < 0 then
			rX = 0
		end
		toleranzY = Toleranzarea - (lookatposX - rX)
		if toleranzY < 0 then
			toleranzY = 0
		end
        rY = math.random(lookatposY-toleranzY,lookatposY+toleranzY)
		if rY > WorldY-1000 then
			rY = 69399
		elseif rY < 0 then
			rY = 0
		end
        rZ = getZ( rX, rY,1000)
        screen = {Camera.GetScreenCoord( rX, rY, rZ)}
        if screen[1] > 0 and screen[2] > 0 and screen[1] < ScreenX and screen[2] < ScreenY then
			Logic.Lightning(rX, rY)
        end
    end
	if Counter.Tick2("LightingSound",lightingsoundtimer) then
		Stream.Start(Folders.Map.."ThunderSound"..(Logic.GetRandom(2)+1)..".mp3",70)
		lightingsoundtimer = math.random(7,17)
	end
	if LightningLastTime ~= nil then
		LightningLastTime = nil
	end
end