Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local objectData = {
- [1] = {txd="1.txd", dff="1.dff"},
- [2] = {txd="2.txd", dff="2.dff"},
- [5] = {txd="5.txd", dff="5.dff"}
- }
- local downloadStatus = {}
- function init()
- --Loop our object data, and intiliaze a download "state"
- for id, data in pairs(objectData) do
- downloadStatus[id] = {}
- downloadStatus[id].txd, downloadStatus[id].dff = false, false
- --Start downloading
- downloadFile(data.txd)
- downloadFile(data.dff)
- end
- end
- addEventHandler("onClientResourceStart", resourceRoot, init) --As an example, start with the resource
- function handleObjectDownloads(file, success)
- --If the file wasn't downloaded, return with an error message
- if not success then
- return outputDebugString("Download failed for "..file)
- end
- --We could make this more efficient, but for simplicity I'll keep it like this
- --Loop through all the object data and check if the object "package" has been downloaded, else, store the download completion state for this file.
- local id, filetype
- for i, data in pairs(objectData) do
- if data.txd == file then
- filetype = "txd"
- elseif data.dff == file then
- filetype = "dff"
- end
- if filetype then
- id = i
- end
- end
- --The file downloaded is not relevant
- if not id then
- return false
- end
- --Set download status for this file to true
- downloadStatus[id][filetype] = true
- --If all the files aren't downloaded yet, then return and wait
- for i, status in ipairs(downloadStatus[id]) do
- if not status then
- return false
- end
- end
- --All files in this "package" are downloaded, so import the txd/dffs
- local txd = engineLoadTXD(objectData[id].txd)
- engineImportTXD(txd, id)
- local dff = engineLoadDFF(objectData[id].dff, id)
- engineReplaceModel(dff, id)
- return true
- end
- addEventHandler("onClientFileDownloadComplete", root, handleObjectDownloads)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement