Jump to content

[Help] ModLoader


MrDante

Recommended Posts

I'm Brazillian, Sorry my bad english

Hi Guys, I need help! 

I am creating a modloader, however I did it with a form where it is giving error when executing the event "onClientFileDownloadComplete", because when I am going to the event, I need to find the data inside a table, but the error in The nil value debug, For some reason I do not know, if they want, they can test on their servers, and I ask you to help me, I'll be very grateful

OBS: OOP Syntax

The server-side table is the directory where the txd's / dff's are located

Server-Side: [will be re-added later]

Client-Side: [will be re-added later]

Edited by Dutchman101
stripped out full code on TS request
Link to comment
1 hour ago, MrDante said:

I'm Brazillian, Sorry my bad english

Hi Guys, I need help! 

I am creating a modloader, however I did it with a form where it is giving error when executing the event "onClientFileDownloadComplete", because when I am going to the event, I need to find the data inside a table, but the error in The nil value debug, For some reason I do not know, if they want, they can test on their servers, and I ask you to help me, I'll be very grateful

OBS: OOP Syntax

The server-side table is the directory where the txd's / dff's are located

Server-Side:


Boxs = {
	Models = {
		CR = {
			{411, "415", "Veiculos", "Arquivos"}
		},
		LV = {
			{411, "415", "Veiculos", "Arquivos"}
		},

		LS = {
			{411, "415", "Veiculos", "Arquivos"}
		},
		SF = {
			{411, "415", "Veiculos", "Arquivos"}
		}
	},
	Mods = {}
}

addEventHandler("onResourceStart", resourceRoot,
	function ()
		local meta = XML.load("meta.xml");
		print(getThisResource().name..": Script Loaded");
		for k, v in ipairs (meta:getChildren()) do
			if (v.name == "file") then
				Boxs.Mods[v:getAttribute("src"):sub(10, 11)]= {v:getAttribute("src"):sub(13, v:getAttribute("src"):len()),  0};
			end
		end

		function checkMod (file, type, model, arc)
			local dffFile = model.."/"..file..".dff";
			local txdFile = model.."/"..file..".txd";
			local colFile = model.."/"..file..".col";
			if (File.exists(arc.."/"..type.."/"..dffFile)) then
				if (not Boxs.Mods[type] or not Boxs.Mods[type][1] == dffFile) then
					addMod(arc.."/"..type.."/"..dffFile);
				end
			end
			if (File.exists(arc.."/"..type.."/"..txdFile)) then
				if (not Boxs.Mods[type] or not Boxs.Mods[type][1] == txdFile) then
					addMod(arc.."/"..type.."/"..txdFile);
				end
			end
			if (File.exists(arc.."/"..type.."/"..colFile)) then
				if (not Boxs.Mods[type] or not Boxs.Mods[type][1] == colFile) then
					addMod(arc.."/"..type.."/"..colFile);
				end
			end
		end
		
		function addMod (file)
			Boxs.load = true;
			local newChild = meta:createChild("file");
			newChild:setAttribute ("src", file);
			print(getThisResource().name..":"..file.." Loaded");
		end

		for k, v in ipairs (Boxs.Models.CR) do
			checkMod(v[2], "CR", v[3], v[4]);
		end 

		for k, v in ipairs (Boxs.Models.LV) do
			checkMod(v[2], "LV", v[3], v[4]);
		end 
		
		for k, v in ipairs (Boxs.Models.LS) do
			checkMod(v[2], "LS", v[3], v[4]);
		end 

		for k, v in ipairs (Boxs.Models.SF) do
			checkMod(v[2], "SF", v[3], v[4]);
		end

		if (Boxs.load) then
			meta:saveFile();
			meta:unload();

			print(getThisResource().name..": New Resources Loaded");

			resource:restart();
			return true;
		end
	end
)


addEvent(getThisResource().name..": onServerSystem", true);
addEventHandler(getThisResource().name..": onServerSystem", root,
	function (args)
		if (args[1] == "files-load") then
			onRequestLoadingFiles(source, args[2]);
		end
	end
)

function onRequestLoadingFiles (player, city)
	triggerClientEvent(player, getThisResource().name..": onClientSystem", root, {"files-load", city, Boxs.Models[city]});
end

Client-Side:


Boxs = {
	screenSize = {guiGetScreenSize()},
	width = 300,
	height = 200,
	download = {}
}


addEventHandler("onClientResourceStart", resourceRoot,
	function ()
		Boxs.x, Boxs.y = (Boxs.screenSize[1] / 2 - Boxs.width / 2), (Boxs.screenSize[2] / 2 - Boxs.height / 2);

		local sx, sy, sz = localPlayer:getPosition();
		if (getZoneName(sx, sy, sz, true) == "Las Venturas") then
			triggerServerEvent(getThisResource().name..": onServerSystem", localPlayer, {"files-load", "LV", "LV"});
		elseif (getZoneName(sx, sy, sz, true) == "San Fierro") then
			triggerServerEvent(getThisResource().name..": onServerSystem", localPlayer, {"files-load", "SF", "SF"});
		elseif (getZoneName(sx, sy, sz, true) == "Los Santos") then
			triggerServerEvent(getThisResource().name..": onServerSystem", localPlayer, {"files-load", "LS", "LS"});
		else
			triggerServerEvent(getThisResource().name..": onServerSystem", localPlayer, {"files-load", "CR", "CR"});
		end
	end
)

function LoadingFileForCity (args)
	if (type(args[1]) == "string") then
		if (args[1] == "Las Venturas") then
			triggerServerEvent(getThisResource().name..": onServerSystem", localPlayer, {"files-load", "LV", "LV"});
		elseif (args[1] == "San Fierro") then
			triggerServerEvent(getThisResource().name..": onServerSystem", localPlayer, {"files-load", "SF", "SF"});
		elseif (args[1] == "Los Santos") then
			triggerServerEvent(getThisResource().name..": onServerSystem", localPlayer, {"files-load", "LS", "LS"});
		elseif (args[1] == "Cidades Rurais") then
			triggerServerEvent(getThisResource().name..": onServerSystem", localPlayer, {"files-load", "CR", "CR"});
		end
	elseif (type(args[1]) == "number") then
		if (getZoneName(args[1], args[2], args[3], true) == "Las Venturas") then
			triggerServerEvent(getThisResource().name..": onServerSystem", localPlayer, {"files-load", "LV", "LV"});
		elseif (getZoneName(args[1], args[2], args[3], true) == "San Fierro") then
			triggerServerEvent(getThisResource().name..": onServerSystem", localPlayer, {"files-load", "SF", "SF"});
		elseif (getZoneName(args[1], args[2], args[3], true) == "Los Santos") then
			triggerServerEvent(getThisResource().name..": onServerSystem", localPlayer, {"files-load", "LS", "LS"});
		else
			triggerServerEvent(getThisResource().name..": onServerSystem", localPlayer, {"files-load", "CR", "CR"});
		end
	end
end

addEvent(getThisResource().name..": onClientSystem", true);
addEventHandler(getThisResource().name..": onClientSystem", root, 
	function (args) 
		if (args[1] == "files-load") then
			for k, v in ipairs (args[3]) do
				local txd = v[4].."/"..args[2].."/"..v[3].."/"..v[2]..".txd";
				local dff = v[4].."/"..args[2].."/"..v[3].."/"..v[2]..".dff";
				local col = v[4].."/"..args[2].."/"..v[3].."/"..v[2]..".col";

				if (File.exists(txd)) then
					local txdFile = File(txd);
					Boxs.size = txdFile:getSize();
					txdFile:close();
					downloadFile(v[4].."/"..args[2].."/"..v[3].."/"..v[2]..".txd");
				end

				if (File.exists(dff)) then
					local dffFile = File(dff);
					Boxs.size = dffFile:getSize();
					dffFile:close();
					downloadFile(v[4].."/"..args[2].."/"..v[3].."/"..v[2]..".dff");
				end

				if (File.exists(col)) then
					local colFile = File(col);
					Boxs.size = colFile:getSize();
					colFile:close();
					downloadFile(v[4].."/"..args[2].."/"..v[3].."/"..v[2]..".col");									
				end
				
				if (File.exists(txd) and File.exists(dff)) then
					local txdFile = File(txd);
					local dffFile = File(dff);
					Boxs.size = txdFile:getSize() + dffFile:getSize();
					downloadFile(v[4].."/"..args[2].."/"..v[3].."/"..v[2]..".txd");
					downloadFile(v[4].."/"..args[2].."/"..v[3].."/"..v[2]..".dff");
				elseif (File.exists(txd) and File.exists(dff) and File.exists(col)) then
					local txdFile = File(txd);
					local dffFile = File(dff);
					local colFile = File(col);		
					Boxs.size = txdFile:getSize() + dffFile:getSize() + colFile:getSize();
					downloadFile(v[4].."/"..args[2].."/"..v[3].."/"..v[2]..".txd");
					downloadFile(v[4].."/"..args[2].."/"..v[3].."/"..v[2]..".dff");
					downloadFile(v[4].."/"..args[2].."/"..v[3].."/"..v[2]..".col");
				end

				Boxs.download[v[4].."/"..args[2].."/"..v[3].."/"..v[2]] = {v[2], args[2], v[3], size, v[1]};		
			end
		end
	end
)


addEventHandler("onClientFileDownloadComplete", root,
	function (filename, success)
		if (success) then
			if (filename:find(".txd")) then
				local file = filename:gsub(".txd", "")
				loadMod(Boxs.download[file][1]..".txd", Boxs.download[file][2], Boxs.download[file][3], Boxs.download[file][5]);
			elseif (filename:find(".dff")) then
				local file = filename:gsub(".dff", "")
				loadMod(Boxs.download[file][1]..".dff", Boxs.download[file][2], Boxs.download[file][3], Boxs.download[file][5]);
			elseif (filename:find(".col")) then
				local file = filename:gsub(".col", "")
				loadMod(Boxs.download[file][1]..".col", Boxs.download[file][2], Boxs.download[file][3], Boxs.download[file][5]);
			end
		end
	end
)

addEventHandler("onClientRender", root,
	function ()
		if (Boxs.size) then
			local downloadSize = 0;
			for k, v in ipairs (Boxs.download) do
				downloadSize = downloadSize + Boxs.download[k][4] / 2;
			end

			if (downloadSize >= 1) then 
				dxDrawRectangle(Boxs.x, Boxs.screenSize[2] / 2 - 90, Boxs.width, 35, tocolor(0, 0, 0, 180));
				dxDrawRectangle(Boxs.x, Boxs.screenSize[2] / 2 - 90, Boxs.width / 100 * Boxs.size - downloadSize, tocolor(0, 179, 255, 255));
				dxDrawText(math.floor(Boxs.width / 100 * Boxs.size - downloadSize).."%", Boxs.x, Boxs.y, Boxs.x + Boxs.width, Boxs.screenSize[2] / 2 - 90 + 35, tocolor(255, 255, 255, 255), 1, "default-bold", "center", "center");
			end
		end
	end
)

function loadMod (file, city, type, id)
	local engineFile = "Arquivos/"..city.."/"..type.."/"..file;

	if (file:find(".txd")) then
		local dff = EngineDFF(engineFile);
		dff:replace(id);
	elseif (file:find(".dff")) then
		local txd = EngineTXD(engineFile);
		txd:import(id);
	elseif (file:find(".col")) then
		local col = EngineCOL(engineFile);
		col:import(id);
	end
end

You just gave us a full code :(

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...