Jump to content

Cache files


rapgod1

Recommended Posts

When player enters to the server, he can remove cache files and can walk through objects. How I can fix it?

enablesd:  14,22

meta.xml:

<file src="cmodels/object.dff" type="client" download="false" />

client.lua:

local replace = {

	{"object.txd","object.dff","object.col",2242},

}



addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()),function()

	for _, data in ipairs(replace) do

		local name_txd = md5(data[1])

		local name_dff = md5(data[2])

		local name_col = md5(data[3])

		if not fileExists("cmodels/"..name_txd) then

			downloadFile("cmodels/"..data[1])

		end

		if not fileExists("cmodels/"..name_dff) then

			downloadFile("cmodels/"..data[2])

		end

		if not fileExists("cmodels/"..name_col) then

			downloadFile("cmodels/"..data[3])

		end

		if fileExists("cmodels/"..name_txd) then

			engineImportTXD(engineLoadTXD("cmodels/"..name_txd),data[4])

		end

		if fileExists("cmodels/"..name_dff) then

			engineReplaceModel(engineLoadDFF("cmodels/"..name_dff,0),data[4])

		end

		if fileExists("cmodels/"..name_col) then

			engineReplaceCOL(engineLoadCOL("cmodels/"..name_col,0),data[4])

		end

		engineSetModelLODDistance(data[4],500)		

	end

end)



addEventHandler("onClientFileDownloadComplete", getResourceRootElement(getThisResource()),function(file)

	for _, data in ipairs(replace) do

		if file == "cmodels/"..data[1] then

			local name_txd = md5(data[1])

			if not fileExists("cmodels/"..data[1]) then return end

			fileRename("cmodels/"..data[1],"cmodels/"..name_txd)

			engineImportTXD(engineLoadTXD("cmodels/"..name_txd),data[4])

		end

		if file == "cmodels/"..data[2] then

			local name_dff = md5(data[2])

			if not fileExists("cmodels/"..data[2]) then return end

			fileRename("cmodels/"..data[2],"cmodels/"..name_dff)

			engineReplaceModel(engineLoadDFF("cmodels/"..name_dff,0),data[4])

		end

		if file == "cmodels/"..data[3] then

			local name_col = md5(data[3])

			if not fileExists("cmodels/"..data[3]) then return end

			fileRename("cmodels/"..data[3],"cmodels/"..name_col)

			engineReplaceCOL(engineLoadCOL("cmodels/"..name_col,0),data[4])

		end

	end	

end)

 

Link to comment

I can give you easyer loader.

 

Try with this:

function loadSkin (filename,id)
    if id and filename then
        if fileExists(filename..".txd") then
            txd = engineLoadTXD( filename..".txd" )
            engineImportTXD( txd, id )
        end            
        if fileExists(filename..".dff") then
            dff = engineLoadDFF( filename..".dff", 0 )
            engineReplaceModel( dff, id )
        end        
        if fileExists(filename..".col") then
            col = engineLoadCOL( filename..".col" )
            engineReplaceCOL( col, id )
        end    
    end
end


addEventHandler("onClientResourceStart", resourceRoot, function()
    
    loadSkin("cmodels/object",2242)
 -- Just add here your stuffs like: loadSkin("folder/name",ID) 
end)

 

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