Jump to content

downloader


Recommended Posts

شباب هذا المود بيسوي لاق اول ما ادخل السيرفر يصير يحمل في المودات من جديد
بدي تحميل ملفاته بس اذا كان اللاعب غير محمل ملفات سيرفري 
client

---
addEvent("onDownloadFinish",true)
---
local modQueue = {}					-- mod queue
local progress = 0					-- Progress (%)
local done = false					-- Done downloading?
local downloadSize = 0				-- Current download size	(updated after onClientFileDownloadComplete)
local totalDownloadSize = 0			-- Total size of the modQueue
local fileDownloadComplete = false	-- This flag sets true when onClientFileDownloadComplete triggers => onClientRender then downloads the next file
--
local sWidth,sHeight = guiGetScreenSize()
local x,y = guiGetScreenSize()local screenW,screenH = guiGetScreenSize()
local oX,oY = 1280,1024

function download()
	downloadFile(modQueue[#modQueue][1])
end

--[[
	start downloadin'
	- table tbl - The a table of mods { {file, model, size, name}, {file, model, size, name}, ...}
	- int size - the total size of these mods (fileGetSize)
]]
function doDownload(tbl,size)
	if done then
		triggerEvent("onDownloadFinish",localPlayer)
		return
	end
	-- Begin drawing and scheduling (download file after file in succesion)
	addEventHandler("onClientRender", root, drawAndSchedule)
	
	-- setup total download size / current download size before we start
	modQueue = tbl
	totalDownloadSize = size
	downloadSize = totalDownloadSize
	
	-- Begin downloading the first file
	download()
end
addEvent("Downloader:StartDownload",true)
addEventHandler("Downloader:StartDownload",root, doDownload)

--[[
	Show the user the status and schedule downloads one after the other.
]]
function drawAndSchedule()
	if #modQueue > 0 then
		local progress = 100 - (downloadSize*100/totalDownloadSize)
		if getElementData(localPlayer,"state.hud") == "disabled" then
			return
		end		
	dxDrawRectangle((520/1360)*sWidth, (5/768)*sHeight, (350/1360)*sWidth, (30/768)*sHeight, tocolor(0, 0, 0, 100), false)
    dxDrawRectangle((530/1360)*sWidth, (10/768)*sHeight, (330/1360)*sWidth*math.floor(progress)/100, (20/768)*sHeight, tocolor(255, 0, 0, 150),false)
	dxDrawText("Downloading... (now:"..(modQueue[#modQueue][4])..") ["..sizeFormat(modQueue[#modQueue][3]).."] finished: "..math.floor(progress).."%", (715/1360)*sWidth, (12/768)*sHeight, (680/1360)*sWidth, (130/768)*sHeight, tocolor (255, 255, 255, 255), (0.35/1366)*sWidth,(0.35/768)*sHeight,"bankgothic","center","top",false,false,false,true)

		-- download completed?
		-- download the next file
		if fileDownloadComplete then
			fileDownloadComplete = false
			download()
		end
	else
		triggerEvent("onDownloadFinish",localPlayer)
		removeEventHandler("onClientRender", root, drawAndSchedule)
	end
end

--[[
	update variables after download is complete
]]
addEventHandler("onClientFileDownloadComplete", root,
function(n,s)
	if s then
		local ftxd = n:find(".txd")
		local fdff = n:find(".dff")
		local model = modQueue[#modQueue][2]
		if ftxd then
			local txd = engineLoadTXD(n)
			engineImportTXD(txd,model)
		elseif fdff then
			local dff = engineLoadDFF(n)
			engineReplaceModel(dff,model)
		end
		-- update downloadSize 
		downloadSize = downloadSize - modQueue[#modQueue][3]
		table.remove(modQueue)
		fileDownloadComplete = true
	else
		outputChatBox("[#ffffffDOWNLOADER#ff0000] "..n.." has just failed to download!",255,255,255,true)
	end
end
)

--[[
	show that downloading has finished
]]
function onDownloadFinish()
	setElementData(localPlayer,"Activity","Playing")
	progress = 0
	done = true
end
addEventHandler("onDownloadFinish",root,onDownloadFinish)
local modsSize = 0

local queue = {}



addEventHandler("onResourceStart", resourceRoot,

function()

  local xml = xmlLoadFile("files.xml")

  for i, node in ipairs(xmlNodeGetChildren(xml)) do

      local file = xmlNodeGetAttribute(node, "path")

	  local model = xmlNodeGetAttribute(node, "model") or false

	  local name = xmlNodeGetAttribute(node, "name")

      local openedFile = fileOpen(file)

      local size = fileGetSize(openedFile)

      modsSize = modsSize + size

      table.insert(queue, {file, model, size, name})

      fileClose(openedFile)

  end

  xmlUnloadFile(xml)

	for i,v in ipairs(getElementsByType("player")) do

		triggerLatentClientEvent(v,"Downloader:StartDownload",v,queue,modsSize)

		setElementData(v,"Activity","Downloading")

	end

end

)



function download()

	triggerLatentClientEvent(source,"Downloader:StartDownload",source,queue,modsSize)

	setElementData(source,"Activity","Downloading")

end

addEventHandler("onPlayerLogin",root,download)

 

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