-- Compiled by Scene2Res, a MTA:SA GTA III engine map importer
local textureCache = {};
local streamedObjects = {};
local pModels = {};

setCloudsEnabled(false);
debug.sethook(nil);

local function getResourceSize(path)
	if not (fileExists(path)) then return 0; end;

	local file = fileOpen(path);
	local size = fileGetSize(file)

	fileClose(file);
	return size;
end

local function requestTexture(model, path)
	local txd = textureCache[path];

	if not (txd) then
		local size = getResourceSize(path);
		if (size == 0) then return false; end

		txd = engineLoadTXD(path, false);

		if not (txd) then
			return false;
		end

		textureCache[path] = txd;
	end
	return txd;
end

local function loadModel(model)
	if (model.loaded) then return true; end

	if (model.super) then
       local superModel = pModels[model.super];
       if (superModel) then
		    if not (loadModel(superModel)) then
			    return false;
		    end
       end
	end

	engineReplaceModel(model.model, model.id);
	engineReplaceCOL(model.col, model.id);

	model.loaded = true;
	return true;
end

local function freeModel(model)
	if not (model.loaded) then return true; end

	engineRestoreModel(model.id);
	engineRestoreCOL(model.id);

	model.loaded = false;
	if (model.super) then
       local superModel = pModels[model.super];
       if (superModel) then
		    freeModel(superModel);
       end
	end
end

local function modelStreamOut ()
	local pModel = pModels[getElementModel(source)];

	if not (pModel) then return end;

	if (pModel.lodID) then return true; end

	if (pModel.isRequesting == 2) then
		pModel.isRequesting = 1;
		return true;
	elseif (pModel.isRequesting == 3) then
		pModel.isRequesting = 4;
		return true;
	elseif (pModel.isRequesting) then return true; end

	pModel.numStream = pModel.numStream - 1;

	if (pModel.numStream == 0) then
		pModel.isRequesting = 3;

		freeModel(pModel);

		pModel.isRequesting = false;
	end
end

local function modelStreamIn ()
	local pModel = pModels[getElementModel(source)];

	if not (pModel) then return end;

	if (pModel.lodID) then return true; end

	if (pModel.isRequesting == 1) then
		pModel.isRequesting = false;
		return true;
	elseif (pModel.isRequesting) then return true; end

	pModel.numStream = pModel.numStream + 1;

	if not (pModel.numStream == 1) then return true; end

	pModel.isRequesting = 2;

	if not (loadModel(pModel)) then
		setElementInterior(source, 123);
		setElementCollisionsEnabled(source, false);
	end

	if (pModel.isRequesting == 2) then
		outputDebugString("invalid model request '"..pModel.name.."'");
		freeModel(pModel);
		pModel.isRequesting = false;

		pModel.numStream = 0;
	end
end

function loadModels ()
	local pModel, pTXD, pColl, pTable;

	pTable={

	};

	for m,n in ipairs(pTable) do
		pModels[n[1]] = {
			id = n[1],
			name = n[2],
			txd = requestTexture(false, "textures/"..n[3]..".txd"),
			numStream = 0,
			lod = n[4] / 5,
			super = n[5]
		};
		pModelEntry = pModels[n[1]];
		engineImportTXD(pModelEntry.txd, n[1]);
		pModelEntry.model = engineLoadDFF("models/"..n[2]..".dff", n[1]);
		engineReplaceModel(pModelEntry.model, n[1]);
		if ( #n == 6 ) then
			pModelEntry.col = engineLoadCOL("coll/"..n[6]..".col");
			engineReplaceCOL(pModelEntry.col, n[1]);
		end
		engineSetModelLODDistance(n[1], n[4] / 5);
	end

	pTable={
		{ model=11595, model_file="polo_0011", txd_file="bollene", coll_file="polo_0011", lod=500 },
		{ model=11596, model_file="othe_0017", txd_file="bollene", coll_file="othe_0017", lod=500 },
		{ model=11597, model_file="road_00128", txd_file="bollene", coll_file="road_00128", lod=500 },
		{ model=11598, model_file="tree_0035", txd_file="bollene", coll_file="tree_0035", lod=500 },
		{ model=11599, model_file="wall_0001", txd_file="bollene", coll_file="wall_0001", lod=500 },
		{ model=11600, model_file="road_00127", txd_file="bollene", coll_file="road_00127", lod=500 },
		{ model=11601, model_file="road_00126", txd_file="bollene", coll_file="road_00126", lod=500 },
		{ model=11602, model_file="road_00125", txd_file="bollene", coll_file="road_00125", lod=500 },
		{ model=11603, model_file="road_00124", txd_file="bollene", coll_file="road_00124", lod=500 },
		{ model=11604, model_file="road_00123", txd_file="bollene", coll_file="road_00123", lod=500 },
		{ model=11605, model_file="road_00122", txd_file="bollene", coll_file="road_00122", lod=500 },
		{ model=11606, model_file="road_00121", txd_file="bollene", coll_file="road_00121", lod=500 },
		{ model=11607, model_file="road_00120", txd_file="bollene", coll_file="road_00120", lod=500 },
		{ model=11611, model_file="road_00119", txd_file="bollene", coll_file="road_00119", lod=500 },
		{ model=11612, model_file="road_00118", txd_file="bollene", coll_file="road_00118", lod=500 },
		{ model=11613, model_file="road_00117", txd_file="bollene", coll_file="road_00117", lod=500 },
		{ model=11614, model_file="road_00116", txd_file="bollene", coll_file="road_00116", lod=500 },
		{ model=11615, model_file="road_00115", txd_file="bollene", coll_file="road_00115", lod=500 },
		{ model=11616, model_file="road_00114", txd_file="bollene", coll_file="road_00114", lod=500 },
		{ model=11617, model_file="road_00113", txd_file="bollene", coll_file="road_00113", lod=500 },
		{ model=11618, model_file="road_00112", txd_file="bollene", coll_file="road_00112", lod=500 },
		{ model=11619, model_file="road_00111", txd_file="bollene", coll_file="road_00111", lod=500 },
		{ model=11620, model_file="road_00110", txd_file="bollene", coll_file="road_00110", lod=500 },
		{ model=11621, model_file="road_00109", txd_file="bollene", coll_file="road_00109", lod=500 },
		{ model=11622, model_file="road_00108", txd_file="bollene", coll_file="road_00108", lod=500 },
		{ model=11623, model_file="road_00107", txd_file="bollene", coll_file="road_00107", lod=500 },
		{ model=11624, model_file="road_00106", txd_file="bollene", coll_file="road_00106", lod=500 },
		{ model=11628, model_file="road_00105", txd_file="bollene", coll_file="road_00105", lod=500 },
		{ model=11629, model_file="road_00104", txd_file="bollene", coll_file="road_00104", lod=500 },
		{ model=11630, model_file="road_00103", txd_file="bollene", coll_file="road_00103", lod=500 },
		{ model=11632, model_file="road_00102", txd_file="bollene", coll_file="road_00102", lod=500 },
		{ model=11633, model_file="road_00101", txd_file="bollene", coll_file="road_00101", lod=500 },
		{ model=11634, model_file="road_00100", txd_file="bollene", coll_file="road_00100", lod=500 },
		{ model=11635, model_file="road_0099", txd_file="bollene", coll_file="road_0099", lod=500 },
		{ model=11636, model_file="road_0098", txd_file="bollene", coll_file="road_0098", lod=500 },
		{ model=11637, model_file="road_0097", txd_file="bollene", coll_file="road_0097", lod=500 },
		{ model=11638, model_file="road_0096", txd_file="bollene", coll_file="road_0096", lod=500 },
		{ model=11639, model_file="road_0095", txd_file="bollene", coll_file="road_0095", lod=500 },
		{ model=11640, model_file="road_0094", txd_file="bollene", coll_file="road_0094", lod=500 },
		{ model=11641, model_file="road_0093", txd_file="bollene", coll_file="road_0093", lod=500 },
		{ model=11642, model_file="road_0092", txd_file="bollene", coll_file="road_0092", lod=500 },
		{ model=11643, model_file="road_0091", txd_file="bollene", coll_file="road_0091", lod=500 },
		{ model=11644, model_file="road_0090", txd_file="bollene", coll_file="road_0090", lod=500 },
		{ model=11645, model_file="road_0089", txd_file="bollene", coll_file="road_0089", lod=500 },
		{ model=11646, model_file="road_0088", txd_file="bollene", coll_file="road_0088", lod=500 },
		{ model=11647, model_file="road_0087", txd_file="bollene", coll_file="road_0087", lod=500 },
		{ model=11648, model_file="road_0086", txd_file="bollene", coll_file="road_0086", lod=500 },
		{ model=11649, model_file="road_0085", txd_file="bollene", coll_file="road_0085", lod=500 },
		{ model=11650, model_file="road_0084", txd_file="bollene", coll_file="road_0084", lod=500 },
		{ model=11651, model_file="road_0083", txd_file="bollene", coll_file="road_0083", lod=500 },
		{ model=11652, model_file="road_0082", txd_file="bollene", coll_file="road_0082", lod=500 },
		{ model=11653, model_file="road_0081", txd_file="bollene", coll_file="road_0081", lod=500 },
		{ model=11654, model_file="road_0080", txd_file="bollene", coll_file="road_0080", lod=500 },
		{ model=11655, model_file="road_0079", txd_file="bollene", coll_file="road_0079", lod=500 },
		{ model=11656, model_file="road_0078", txd_file="bollene", coll_file="road_0078", lod=500 },
		{ model=11657, model_file="road_0077", txd_file="bollene", coll_file="road_0077", lod=500 },
		{ model=11658, model_file="road_0076", txd_file="bollene", coll_file="road_0076", lod=500 },
		{ model=11659, model_file="road_0075", txd_file="bollene", coll_file="road_0075", lod=500 },
		{ model=11660, model_file="road_0074", txd_file="bollene", coll_file="road_0074", lod=500 },
		{ model=11661, model_file="road_0073", txd_file="bollene", coll_file="road_0073", lod=500 },
		{ model=11662, model_file="road_0072", txd_file="bollene", coll_file="road_0072", lod=500 },
		{ model=11664, model_file="road_0071", txd_file="bollene", coll_file="road_0071", lod=500 },
		{ model=11665, model_file="road_0070", txd_file="bollene", coll_file="road_0070", lod=500 },
		{ model=11666, model_file="road_0069", txd_file="bollene", coll_file="road_0069", lod=500 },
		{ model=11667, model_file="road_0068", txd_file="bollene", coll_file="road_0068", lod=500 },
		{ model=11668, model_file="road_0067", txd_file="bollene", coll_file="road_0067", lod=500 },
		{ model=11669, model_file="road_0066", txd_file="bollene", coll_file="road_0066", lod=500 },
		{ model=11670, model_file="road_0065", txd_file="bollene", coll_file="road_0065", lod=500 },
		{ model=11671, model_file="road_0064", txd_file="bollene", coll_file="road_0064", lod=500 },
		{ model=11672, model_file="road_0063", txd_file="bollene", coll_file="road_0063", lod=500 },
		{ model=11673, model_file="road_0062", txd_file="bollene", coll_file="road_0062", lod=500 },
		{ model=11674, model_file="road_0061", txd_file="bollene", coll_file="road_0061", lod=500 },
		{ model=11675, model_file="road_0060", txd_file="bollene", coll_file="road_0060", lod=500 },
		{ model=11676, model_file="road_0059", txd_file="bollene", coll_file="road_0059", lod=500 },
		{ model=17000, model_file="road_0058", txd_file="bollene", coll_file="road_0058", lod=500 },
		{ model=17001, model_file="road_0057", txd_file="bollene", coll_file="road_0057", lod=500 },
		{ model=17002, model_file="road_0056", txd_file="bollene", coll_file="road_0056", lod=500 },
		{ model=17003, model_file="road_0055", txd_file="bollene", coll_file="road_0055", lod=500 },
		{ model=17004, model_file="road_0054", txd_file="bollene", coll_file="road_0054", lod=500 },
		{ model=17005, model_file="road_0053", txd_file="bollene", coll_file="road_0053", lod=500 },
		{ model=17006, model_file="road_0052", txd_file="bollene", coll_file="road_0052", lod=500 },
		{ model=17007, model_file="road_0051", txd_file="bollene", coll_file="road_0051", lod=500 },
		{ model=17008, model_file="road_0050", txd_file="bollene", coll_file="road_0050", lod=500 },
		{ model=17009, model_file="road_0049", txd_file="bollene", coll_file="road_0049", lod=500 },
		{ model=17010, model_file="road_0048", txd_file="bollene", coll_file="road_0048", lod=500 },
		{ model=17011, model_file="road_0047", txd_file="bollene", coll_file="road_0047", lod=500 },
		{ model=17012, model_file="road_0046", txd_file="bollene", coll_file="road_0046", lod=500 },
		{ model=17013, model_file="road_0045", txd_file="bollene", coll_file="road_0045", lod=500 },
		{ model=17014, model_file="road_0044", txd_file="bollene", coll_file="road_0044", lod=500 },
		{ model=17015, model_file="road_0043", txd_file="bollene", coll_file="road_0043", lod=500 },
		{ model=17016, model_file="road_0042", txd_file="bollene", coll_file="road_0042", lod=500 },
		{ model=17017, model_file="road_0041", txd_file="bollene", coll_file="road_0041", lod=500 },
		{ model=17019, model_file="road_0040", txd_file="bollene", coll_file="road_0040", lod=500 },
		{ model=17020, model_file="road_0039", txd_file="bollene", coll_file="road_0039", lod=500 },
		{ model=17021, model_file="road_0038", txd_file="bollene", coll_file="road_0038", lod=500 },
		{ model=17022, model_file="road_0037", txd_file="bollene", coll_file="road_0037", lod=500 },
		{ model=17023, model_file="road_0036", txd_file="bollene", coll_file="road_0036", lod=500 },
		{ model=17024, model_file="road_0035", txd_file="bollene", coll_file="road_0035", lod=500 },
		{ model=17025, model_file="road_0034", txd_file="bollene", coll_file="road_0034", lod=500 },
		{ model=17026, model_file="road_0033", txd_file="bollene", coll_file="road_0033", lod=500 },
		{ model=17027, model_file="road_0032", txd_file="bollene", coll_file="road_0032", lod=500 },
		{ model=17028, model_file="road_0031", txd_file="bollene", coll_file="road_0031", lod=500 },
		{ model=17029, model_file="road_0030", txd_file="bollene", coll_file="road_0030", lod=500 },
		{ model=17030, model_file="road_0029", txd_file="bollene", coll_file="road_0029", lod=500 },
		{ model=17031, model_file="road_0028", txd_file="bollene", coll_file="road_0028", lod=500 },
		{ model=17032, model_file="road_0027", txd_file="bollene", coll_file="road_0027", lod=500 },
		{ model=17033, model_file="road_0026", txd_file="bollene", coll_file="road_0026", lod=500 },
		{ model=17034, model_file="road_0025", txd_file="bollene", coll_file="road_0025", lod=500 },
		{ model=17035, model_file="road_0024", txd_file="bollene", coll_file="road_0024", lod=500 },
		{ model=17036, model_file="road_0023", txd_file="bollene", coll_file="road_0023", lod=500 },
		{ model=17037, model_file="road_0022", txd_file="bollene", coll_file="road_0022", lod=500 },
		{ model=17038, model_file="road_0021", txd_file="bollene", coll_file="road_0021", lod=500 },
		{ model=17039, model_file="road_0020", txd_file="bollene", coll_file="road_0020", lod=500 },
		{ model=17041, model_file="road_0019", txd_file="bollene", coll_file="road_0019", lod=500 },
		{ model=17042, model_file="road_0018", txd_file="bollene", coll_file="road_0018", lod=500 },
		{ model=17043, model_file="road_0017", txd_file="bollene", coll_file="road_0017", lod=500 },
		{ model=17044, model_file="road_0016", txd_file="bollene", coll_file="road_0016", lod=500 },
		{ model=17045, model_file="road_0015", txd_file="bollene", coll_file="road_0015", lod=500 },
		{ model=17049, model_file="road_0014", txd_file="bollene", coll_file="road_0014", lod=500 },
		{ model=17050, model_file="road_0013", txd_file="bollene", coll_file="road_0013", lod=500 },
		{ model=17051, model_file="road_0012", txd_file="bollene", coll_file="road_0012", lod=500 },
		{ model=17052, model_file="road_0011", txd_file="bollene", coll_file="road_0011", lod=500 },
		{ model=17053, model_file="road_0010", txd_file="bollene", coll_file="road_0010", lod=500 },
		{ model=17054, model_file="road_0009", txd_file="bollene", coll_file="road_0009", lod=500 },
		{ model=17055, model_file="road_0008", txd_file="bollene", coll_file="road_0008", lod=500 },
		{ model=17056, model_file="road_0007", txd_file="bollene", coll_file="road_0007", lod=500 },
		{ model=17057, model_file="road_0006", txd_file="bollene", coll_file="road_0006", lod=500 },
		{ model=17058, model_file="road_0005", txd_file="bollene", coll_file="road_0005", lod=500 },
		{ model=17059, model_file="road_0004", txd_file="bollene", coll_file="road_0004", lod=500 },
		{ model=17060, model_file="road_0003", txd_file="bollene", coll_file="road_0003", lod=500 },
		{ model=17061, model_file="road_0002", txd_file="bollene", coll_file="road_0002", lod=500 },
		{ model=17062, model_file="road_0001", txd_file="bollene", coll_file="road_0001", lod=500 },
		{ model=17063, model_file="tree_0001", txd_file="bollene", coll_file="tree_0001", lod=500 },
		{ model=17064, model_file="tree_0002", txd_file="bollene", coll_file="tree_0002", lod=500 },
		{ model=17065, model_file="tree_0003", txd_file="bollene", coll_file="tree_0003", lod=500 },
		{ model=17066, model_file="tree_0004", txd_file="bollene", coll_file="tree_0004", lod=500 },
		{ model=17067, model_file="tree_0005", txd_file="bollene", coll_file="tree_0005", lod=500 },
		{ model=17068, model_file="tree_0006", txd_file="bollene", coll_file="tree_0006", lod=500 },
		{ model=17069, model_file="tree_0007", txd_file="bollene", coll_file="tree_0007", lod=500 },
		{ model=17071, model_file="tree_0008", txd_file="bollene", coll_file="tree_0008", lod=500 },
		{ model=17072, model_file="tree_0009", txd_file="bollene", coll_file="tree_0009", lod=500 },
		{ model=17073, model_file="tree_0010", txd_file="bollene", coll_file="tree_0010", lod=500 },
		{ model=17074, model_file="tree_0011", txd_file="bollene", coll_file="tree_0011", lod=500 },
		{ model=17075, model_file="tree_0012", txd_file="bollene", coll_file="tree_0012", lod=500 },
		{ model=17076, model_file="tree_0013", txd_file="bollene", coll_file="tree_0013", lod=500 },
		{ model=17077, model_file="tree_0014", txd_file="bollene", coll_file="tree_0014", lod=500 },
		{ model=17078, model_file="tree_0015", txd_file="bollene", coll_file="tree_0015", lod=500 },
		{ model=17079, model_file="tree_0016", txd_file="bollene", coll_file="tree_0016", lod=500 },
		{ model=17080, model_file="tree_0017", txd_file="bollene", coll_file="tree_0017", lod=500 },
		{ model=17081, model_file="tree_0018", txd_file="bollene", coll_file="tree_0018", lod=500 },
		{ model=17082, model_file="tree_0019", txd_file="bollene", coll_file="tree_0019", lod=500 },
		{ model=17083, model_file="tree_0020", txd_file="bollene", coll_file="tree_0020", lod=500 },
		{ model=17084, model_file="tree_0021", txd_file="bollene", coll_file="tree_0021", lod=500 },
		{ model=17085, model_file="tree_0022", txd_file="bollene", coll_file="tree_0022", lod=500 },
		{ model=17086, model_file="tree_0023", txd_file="bollene", coll_file="tree_0023", lod=500 },
		{ model=17087, model_file="tree_0024", txd_file="bollene", coll_file="tree_0024", lod=500 },
		{ model=17088, model_file="tree_0025", txd_file="bollene", coll_file="tree_0025", lod=500 },
		{ model=17089, model_file="tree_0026", txd_file="bollene", coll_file="tree_0026", lod=500 },
		{ model=17090, model_file="tree_0027", txd_file="bollene", coll_file="tree_0027", lod=500 },
		{ model=17091, model_file="tree_0028", txd_file="bollene", coll_file="tree_0028", lod=500 },
		{ model=17092, model_file="tree_0029", txd_file="bollene", coll_file="tree_0029", lod=500 },
		{ model=17093, model_file="tree_0030", txd_file="bollene", coll_file="tree_0030", lod=500 },
		{ model=17094, model_file="tree_0031", txd_file="bollene", coll_file="tree_0031", lod=500 },
		{ model=17095, model_file="tree_0032", txd_file="bollene", coll_file="tree_0032", lod=500 },
		{ model=17096, model_file="tree_0033", txd_file="bollene", coll_file="tree_0033", lod=500 },
		{ model=17097, model_file="tree_0034", txd_file="bollene", coll_file="tree_0034", lod=500 },
		{ model=17098, model_file="wall_0002", txd_file="bollene", coll_file="wall_0002", lod=500 },
		{ model=17099, model_file="wall_0003", txd_file="bollene", coll_file="wall_0003", lod=500 },
		{ model=17100, model_file="wall_0004", txd_file="bollene", coll_file="wall_0004", lod=500 },
		{ model=17101, model_file="wall_0005", txd_file="bollene", coll_file="wall_0005", lod=500 },
		{ model=17102, model_file="wall_0006", txd_file="bollene", coll_file="wall_0006", lod=500 },
		{ model=17103, model_file="wall_0007", txd_file="bollene", coll_file="wall_0007", lod=500 },
		{ model=17104, model_file="wall_0008", txd_file="bollene", coll_file="wall_0008", lod=500 },
		{ model=17105, model_file="wall_0009", txd_file="bollene", coll_file="wall_0009", lod=500 },
		{ model=17106, model_file="wall_0010", txd_file="bollene", coll_file="wall_0010", lod=500 },
		{ model=17107, model_file="wall_0011", txd_file="bollene", coll_file="wall_0011", lod=500 },
		{ model=17108, model_file="wall_0012", txd_file="bollene", coll_file="wall_0012", lod=500 },
		{ model=17109, model_file="wall_0013", txd_file="bollene", coll_file="wall_0013", lod=500 },
		{ model=17110, model_file="othe_0016", txd_file="bollene", coll_file="othe_0016", lod=500 },
		{ model=17111, model_file="othe_0015", txd_file="bollene", coll_file="othe_0015", lod=500 },
		{ model=17112, model_file="othe_0014", txd_file="bollene", coll_file="othe_0014", lod=500 },
		{ model=17113, model_file="othe_0013", txd_file="bollene", coll_file="othe_0013", lod=500 },
		{ model=17114, model_file="othe_0012", txd_file="bollene", coll_file="othe_0012", lod=500 },
		{ model=17115, model_file="othe_0011", txd_file="bollene", coll_file="othe_0011", lod=500 },
		{ model=17116, model_file="othe_0010", txd_file="bollene", coll_file="othe_0010", lod=500 },
		{ model=17117, model_file="othe_0009", txd_file="bollene", coll_file="othe_0009", lod=500 },
		{ model=17118, model_file="othe_0008", txd_file="bollene", coll_file="othe_0008", lod=500 },
		{ model=17119, model_file="othe_0007", txd_file="bollene", coll_file="othe_0007", lod=500 },
		{ model=17120, model_file="othe_0006", txd_file="bollene", coll_file="othe_0006", lod=500 },
		{ model=17121, model_file="othe_0005", txd_file="bollene", coll_file="othe_0005", lod=500 },
		{ model=17122, model_file="othe_0004", txd_file="bollene", coll_file="othe_0004", lod=500 },
		{ model=17123, model_file="othe_0003", txd_file="bollene", coll_file="othe_0003", lod=500 },
		{ model=17124, model_file="othe_0002", txd_file="bollene", coll_file="othe_0002", lod=500 },
		{ model=17125, model_file="othe_0001", txd_file="bollene", coll_file="othe_0001", lod=500 },
		{ model=17126, model_file="polo_0001", txd_file="bollene", coll_file="polo_0001", lod=500 },
		{ model=17127, model_file="polo_0002", txd_file="bollene", coll_file="polo_0002", lod=500 },
		{ model=17128, model_file="polo_0003", txd_file="bollene", coll_file="polo_0003", lod=500 },
		{ model=17129, model_file="polo_0004", txd_file="bollene", coll_file="polo_0004", lod=500 },
		{ model=17130, model_file="polo_0005", txd_file="bollene", coll_file="polo_0005", lod=500 },
		{ model=17131, model_file="polo_0006", txd_file="bollene", coll_file="polo_0006", lod=500 },
		{ model=17132, model_file="polo_0007", txd_file="bollene", coll_file="polo_0007", lod=500 },
		{ model=17133, model_file="polo_0008", txd_file="bollene", coll_file="polo_0008", lod=500 },
		{ model=17134, model_file="polo_0009", txd_file="bollene", coll_file="polo_0009", lod=500 },
		{ model=17135, model_file="polo_0010", txd_file="bollene", coll_file="polo_0010", lod=500 },
		{ model=17136, model_file="road_00129", txd_file="bollene", coll_file="road_00129", lod=500 },
		{ model=17137, model_file="road_00130", txd_file="bollene", coll_file="road_00130", lod=500 },
		{ model=17138, model_file="road_00131", txd_file="bollene", coll_file="road_00131", lod=500 },
		{ model=17139, model_file="road_00132", txd_file="bollene", coll_file="road_00132", lod=500 },
		{ model=17140, model_file="road_00133", txd_file="bollene", coll_file="road_00133", lod=500 },
		{ model=17141, model_file="road_00134", txd_file="bollene", coll_file="road_00134", lod=500 },
		{ model=17142, model_file="road_00135", txd_file="bollene", coll_file="road_00135", lod=500 },
		{ model=17143, model_file="road_00136", txd_file="bollene", coll_file="road_00136", lod=500 },
		{ model=17144, model_file="road_00137", txd_file="bollene", coll_file="road_00137", lod=500 },
		{ model=17145, model_file="road_00138", txd_file="bollene", coll_file="road_00138", lod=500 },
		{ model=17146, model_file="road_00139", txd_file="bollene", coll_file="road_00139", lod=500 },
		{ model=17147, model_file="road_00140", txd_file="bollene", coll_file="road_00140", lod=500 },
		{ model=17148, model_file="road_00141", txd_file="bollene", coll_file="road_00141", lod=500 },
		{ model=17149, model_file="road_00150", txd_file="bollene", coll_file="road_00150", lod=500 },
		{ model=17150, model_file="road_00149", txd_file="bollene", coll_file="road_00149", lod=500 },
		{ model=17151, model_file="road_00148", txd_file="bollene", coll_file="road_00148", lod=500 },
		{ model=17152, model_file="road_00147", txd_file="bollene", coll_file="road_00147", lod=500 },
		{ model=17153, model_file="road_00146", txd_file="bollene", coll_file="road_00146", lod=500 },
		{ model=17154, model_file="road_00142", txd_file="bollene", coll_file="road_00142", lod=500 },
		{ model=17155, model_file="road_00143", txd_file="bollene", coll_file="road_00143", lod=500 },
		{ model=17156, model_file="road_00144", txd_file="bollene", coll_file="road_00144", lod=500 },
		{ model=17157, model_file="road_00145", txd_file="bollene", coll_file="road_00145", lod=500 },
		{ model=17158, model_file="wall_0016", txd_file="bollene", coll_file="wall_0016", lod=500 },
		{ model=17159, model_file="wall_0015", txd_file="bollene", coll_file="wall_0015", lod=500 },
		{ model=17160, model_file="wall_0014", txd_file="bollene", coll_file="wall_0014", lod=500 },
		{ model=17161, model_file="othe_0018", txd_file="bollene", coll_file="othe_0018", lod=500 }
	};

	local n,m;

	for n,m in ipairs(pTable) do
		pModels[m.model] = {
			id = m.model,
			name = m.model_file,
			txd = requestTexture(false, "textures/"..m.txd_file..".txd"),
			numStream = 0,
			lod = m.lod,
			lodID = m.lodID
		};
		pModelEntry = pModels[m.model];
       if (pModelEntry.txd) then
		    engineImportTXD(pModelEntry.txd, m.model);
       end
		pModelEntry.model=engineLoadDFF("models/"..m.model_file..".dff", m.model);
		pModelEntry.col=engineLoadCOL("coll/"..m.coll_file..".col");
		engineSetModelLODDistance(m.model, m.lod);

		if (m.lodID) then
			for j,k in ipairs(getElementsByType("object", resourceRoot)) do
				if (getElementModel(k) == m.model) then
					local x, y, z = getElementPosition(k);
					local rx, ry, rz = getElementRotation(k);
					setLowLODElement(k, createObject(m.lodID, x, y, z, rx, ry, rz, true));
				end
			end
		end
	end

	for m,n in pairs(pModels) do
		if (n.super) and not (n.col) then
           local superModel = pModels[n.super];
           if (superModel) then
			    n.col = superModel.col;
           end
		end
	end
end
loadModels();

for m,n in ipairs(getElementsByType("object", resourceRoot)) do
	if (isElementStreamedIn(n)) then
		source = n;
		modelStreamIn();
	end
end

addEventHandler("onClientElementStreamIn", resourceRoot, function()
		modelStreamIn();
	end
);
addEventHandler("onClientElementStreamOut", resourceRoot, function()
		modelStreamOut();
	end
);

addEventHandler("onClientResourceStop", resourceRoot, function()
		for m,n in pairs(pModels) do
			if (isElement(n.col)) then destroyElement(n.col); end
			if (isElement(n.model)) then destroyElement(n.model); end
			engineRestoreCOL(m);
			engineRestoreModel(m);
		end
       for m,n in pairs(textureCache) do
           destroyElement(n);
       end
	end
);

collectgarbage("collect");

local objects = getElementsByType ( "object", resourceRoot )
for theKey,object in ipairs(objects) do
local id = getElementModel(object)
local x,y,z = getElementPosition(object)
local rx,ry,rz = getElementRotation(object)
local scale = getObjectScale(object)
objLowLOD = createObject ( id, x,y,z,rx,ry,rz,true )
setObjectScale(objLowLOD, scale)
setLowLODElement ( object, objLowLOD )
engineSetModelLODDistance ( id, 3000 )
setElementStreamable ( object , false)
end