Jump to content

how to make http file downloader?


Fist

Recommended Posts

as the title says, how can i make http file downloader that downloads file when they are needed in game not one after one but in exact moment when that model/file is going to be used and if client doesn't have it then downloader will download it for him?

Link to comment
Just now, NeXuS™ said:

You'll have to set up each model which has to be downloaded, and check for every object/car/item if he moved from his old position, or just by passed time. 

That sounds kinda wrong to me, isn't there easier way to do this? Also can this 'downlodFile' function download through http site?

Link to comment

Client side, dont even try this on server side.

setTimer(function()
	for i, k in ipairs(getElementsByType("vehicle", getRootElement(), true)) do
		if downloadFile(getElementModel(k) .. ".txd") then
			outputChatBox("Updated a file. (MODEL ID: " .. getElementModel(k) .. ")")
		end
	end
	for i, k in ipairs(getElementsByType("object", getRootElement(), true)) do
		if downloadFile(getElementModel(k) .. ".txd") then
			outputChatBox("Updated a file. (MODEL ID: " .. getElementModel(k) .. ")")
		end
	end
end, 5000, 0)

Should work, not tested tho.

  • Like 1
Link to comment
11 minutes ago, Fist said:

Ok this is what i needed, ty. But i still don't know how to check if vehicle/model is near client then only start downloading file. 

setTimer(
function()
	local x, y, z = getElementPosition(localPlayer)
	local models = getElementsByType("vehicle")
		if #models ~= 0 then
			for i, v in pairs(models) do
    		    if getElementModel(v) == 525 then --525 is just a random number, you can just add whatever you want, later i will make this into a table
					local ex, ey, ez = getElementPosition(v)
					local elementdistance = getDistanceBetweenPoints2D ( x, y, ex, ey )
						if elementdistance <= 350 then
							outputDebugString("Download File")
						end
				end
			end
      	end
end, 500, 0)

This will make the Client side check for any elements within this area and if the model id is the same.If both are true then it will trigger the download

  • Like 1
Link to comment
10 minutes ago, NeXuS™ said:

Client side, dont even try this on server side.


setTimer(function()
	for i, k in ipairs(getElementsByType("vehicle", getRootElement(), true)) do
		if downloadFile(getElementModel(k) .. ".txd") then
			outputChatBox("Updated a file. (MODEL ID: " .. getElementModel(k) .. ")")
		end
	end
	for i, k in ipairs(getElementsByType("object", getRootElement(), true)) do
		if downloadFile(getElementModel(k) .. ".txd") then
			outputChatBox("Updated a file. (MODEL ID: " .. getElementModel(k) .. ")")
		end
	end
end, 5000, 0)

Should work, not tested tho.

lol i didn't know there is such variable as streamedin' for getlementsbytype, that will solve this problem. Thank you !

7 minutes ago, Syntrax# said:

setTimer(
function()
	local x, y, z = getElementPosition(localPlayer)
	local models = getElementsByType("vehicle")
		if #models ~= 0 then
			for i, v in pairs(models) do
    		    if getElementModel(v) == 525 then --525 is just a random number, you can just add whatever you want, later i will make this into a table
					local ex, ey, ez = getElementPosition(v)
					local elementdistance = getDistanceBetweenPoints2D ( x, y, ex, ey )
						if elementdistance <= 350 then
							outputDebugString("Download File")
						end
				end
			end
      	end
end, 500, 0)

This will make the Client side check for any elements within this area and if the model id is the same.If both are true then it will trigger the download

this is even better :D Thank you both!

Link to comment
6 minutes ago, Syntrax# said:

lol :P

But didn't test it so yeah, if there is a problem with it contact me i'll have a look on it.

It does work, but how can i make that it doesn't download files from meta ? I tried deleting those meta files so they wouldn't download them but then it can't find file with downloadFile.

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