Jump to content

[Help] Modloader - Loading File


MrDante

Recommended Posts

I'm Brazilian, Sorry my bad english

Hi Guys, I need help! 

I made a modloader, it is totally correct, however I did the following, on the server side, send a table to the client, with the correct files, and also is in the meta, however, for testing, when typing /loadMod, the client side can not verify that the file exists, that it exists and is in the meta. I had made it work, but before using the attribute in the meta download="false", now using, can not verify ... Can anyone help?

 

Client-side:

Boxs = {
	download = {},
  	size = 0
}

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 (fileExists(txd)) then
					local txdFile = fileOpen(txd);
					Boxs.size = Boxs.size + txdFile:getSize();
					downloadFile(v[4].."/"..args[2].."/"..v[3].."/"..v[2]..".txd");
					txdFile:close();			
				end

				if (fileExists(dff)) then
					local dffFile = fileOpen(dff);
					Boxs.size = Boxs.size + dffFile:getSize();
					downloadFile(v[4].."/"..args[2].."/"..v[3].."/"..v[2]..".dff");
					fileClose(dffFile);
					
				end

				if (fileExists(col)) then
					local colFile = fileOpen(col);
					Boxs.size = Boxs.size + colFile:getSize();
					downloadFile(v[4].."/"..args[2].."/"..v[3].."/"..v[2]..".col");		
					fileClose(colFile);						
				end

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


addEventHandler("onClientFileDownloadComplete", root,
	function (filename, success)
		if (success) then
			setTimer(function ()
				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, 500, 1)
		end
	end
)

function loadMod (file, city, type, id)
	local engineFile = "Arquivos/"..city.."/"..type.."/"..file;
	
	if (fileExists(engineFile)) then
		if (file:find(".dff")) then
			local dff = engineLoadDFF(dff, engineFile, id);
			engineReplaceModel(dff, id);
		elseif (file:find(".txd")) then
			local txd = engineLoadTXD(engineFile);
			engineImportTXD(txd, id);
		elseif (file:find(".col")) then
			local col = engineLoadCOL(engineFile);
			engineImportCOL(col, id);
		end

		--[[[
		for k, v in ipairs (Boxs.download) do
			if (k == engineFile and v) then
				Boxs.download[k] = false; 
			end
		end
		--]]
	end
end

addCommandHandler("loadMod",
	function ()
		--if (event) then
			triggerServerEvent(getThisResource().name..": onServerSystem", localPlayer, {"files-load", "CR", "CR"});
		--end
	end
);

Server-side:

 

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

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

Meta: 

 

<meta>
    <info author="MrDante" name="[All] ModLoader" version="1.0" description="ModLoader Script"></info>
    <script src="Server-side.lua" type="server"></script>
    <script src="Client-side.lua" type="client" cache="false" validate="true"></script>
    <oop>true</oop>
    <file src="Arquivos/CR/Veiculos/415.dff" download="false"></file>
    <file src="Arquivos/CR/Veiculos/415.txd" download="false"></file>
</meta>

 

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...