function createDoorQuest()
	InitDoorHandler()
	StartSimpleJob("DoorHandler")
end

function DoorHandler()
	local doorentity = "auseresTor"
	local towerentity = "ausererTurm"
	for i = 1,3,1 do
		if IsAlive(towerentity..i) then
			local doorpos = GetPosition(doorentity..i)
			local anzahlAnEntities,_ = Logic.GetPlayerEntitiesInArea(GetHumanPlayer(),0,doorpos.X,doorpos.Y,1000,1)
			if anzahlAnEntities > 0 then
				if Logic.GetEntityType(Logic.GetEntityIDByName(doorentity..i)) == Entities.XD_DarkWallStraightGate then
					ReplaceEntity(doorentity..i, Entities.XD_DarkWallStraightGate_Closed)
				end
			else
				if Logic.GetEntityType(Logic.GetEntityIDByName(doorentity..i)) == Entities.XD_DarkWallStraightGate_Closed then
					ReplaceEntity(doorentity..i,Entities.XD_DarkWallStraightGate)
				end
			end
		else
			if Logic.GetEntityType(Logic.GetEntityIDByName(doorentity..i)) == Entities.XD_DarkWallStraightGate_Closed then
				ReplaceEntity(doorentity..i, Entities.XD_DarkWallStraightGate)
			end
			local wallnumbers,wallentID = Logic.GetPlayerEntitiesInArea(3,0,doorhandlertable[1][i].X,doorhandlertable[1][i].Y,3000,1)
			while wallnumbers > 0 do
				Logic.ChangeEntityPlayerID(wallentID, 4)
				wallnumbers,wallentID = Logic.GetPlayerEntitiesInArea(3,0,doorhandlertable[1][i].X,doorhandlertable[1][i].Y,3000,1)
			end
		end
	end
	local doorentity = "inneresTor"
	local towerentity = "innererTurm"
	for i = 1,5,1 do
		if IsAlive(towerentity..i) then
			local doorpos = GetPosition(doorentity..i)
			local anzahlAnEntities,_ = Logic.GetPlayerEntitiesInArea(GetHumanPlayer(),0,doorpos.X,doorpos.Y,1000,1)
			if anzahlAnEntities > 0 then
				if Logic.GetEntityType(Logic.GetEntityIDByName(doorentity..i)) == Entities.XD_DarkWallStraightGate then
					ReplaceEntity(doorentity..i, Entities.XD_DarkWallStraightGate_Closed)
				end
			else
				if Logic.GetEntityType(Logic.GetEntityIDByName(doorentity..i)) == Entities.XD_DarkWallStraightGate_Closed then
					ReplaceEntity(doorentity..i,Entities.XD_DarkWallStraightGate)
				end
			end
		else
			if Logic.GetEntityType(Logic.GetEntityIDByName(doorentity..i)) == Entities.XD_DarkWallStraightGate_Closed then
				ReplaceEntity(doorentity..i, Entities.XD_DarkWallStraightGate)
			end
			local wallnumbers,wallentID = Logic.GetPlayerEntitiesInArea(3,0,doorhandlertable[2][i].X,doorhandlertable[2][i].Y,3000,1)
			while wallnumbers > 0 do
				Logic.ChangeEntityPlayerID(wallentID, 4)
				wallnumbers,wallentID = Logic.GetPlayerEntitiesInArea(3,0,doorhandlertable[2][i].X,doorhandlertable[2][i].Y,3000,1)
			end
		end
	end
	
end

function InitDoorHandler()
	doorhandlertable = {{},{}}
	for i = 1,3,1 do
		doorhandlertable[1][i] = GetPosition("auseresTor"..i)
	end
	for i = 1,5,1 do
		doorhandlertable[2][i] = GetPosition("inneresTor"..i)
		local TorTowerID = Logic.GetEntityIDByName("innererTurm"..i)
		Logic.SetEntityInvulnerabilityFlag(TorTowerID, 1)
		for j = 1,2,1 do
			local  towerID = Logic.GetEntityIDByName("invisTower"..i..j)
			Logic.SetEntityInvulnerabilityFlag(towerID, 1)
			if HistoryFlag == 1 then
				Logic.SetEntityScriptingValue(towerID, -26, 513)
			elseif HistoryFlag == 0 then
				Logic.SetEntityScriptingValue(towerID, -30, 513)
			end
		end
	end
end