Gravestone Posted September 16, 2016 Share Posted September 16, 2016 I'm trying to make a option for players to download mods. The files are downloaded but if I restart the resource or the player joins then it spams the debug with 'attempt to load '..file name..' before 'onClientFileDownloadComplete' event. Is there anyway I can prevent my debug from getting spammed? weapons= { { file = "335" }, { file = "346" }, { file = "347" }, { file = "348" }, { file = "349" }, { file = "350" }, { file = "351" }, { file = "352" }, { file = "353" }, { file = "355" }, { file = "356" }, { file = "357" }, { file = "358" }, { file = "359" }, { file = "360" }, { file = "362" }, { file = "363" }, { file = "372" }} function downloadComplete(file, success) if (source == getResourceRootElement(getThisResource())) then for index, weapon in pairs(weapons) do if file == "weapons/"..weapon.file..".txd" or file == "weapons/"..weapon.file..".dff" then setTimer(replaceModels, 1000, 1) end end end end addEventHandler("onClientFileDownloadComplete", root, downloadComplete) function replaceModels() for index, weapon in pairs(weapons) do if fileExists("weapons/"..weapon.file..".txd") and fileExists("weapons/"..weapon.file..".dff") then txd = engineLoadTXD("weapons/"..weapon.file..".txd") engineImportTXD(txd, weapon.file) dff = engineLoadDFF("weapons/"..weapon.file..".dff") engineReplaceModel(dff, weapon.file) else outputDebugString("Weapon file do not not exist for client "..getPlayerName(localPlayer)) end end end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), replaceModels) Link to comment
Gravestone Posted September 17, 2016 Author Share Posted September 17, 2016 Help pls ? Link to comment
Rataj Posted September 17, 2016 Share Posted September 17, 2016 Use downloadFile everytime and remove addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), replaceModels). I think MTA can handle it automatically like that. By the way, outputDebugString with user's name is useless there, since it's client-side, so you'll always get only your own name. Link to comment
Gravestone Posted September 17, 2016 Author Share Posted September 17, 2016 The function will not work if it is not triggered. I need to replace models when the resource starts for the clients. Link to comment
Simple0x47 Posted September 17, 2016 Share Posted September 17, 2016 Try this: addEvent("onClientReplaceStuff", true ) weapons= { { file = "335" }, { file = "346" }, { file = "347" }, { file = "348" }, { file = "349" }, { file = "350" }, { file = "351" }, { file = "352" }, { file = "353" }, { file = "355" }, { file = "356" }, { file = "357" }, { file = "358" }, { file = "359" }, { file = "360" }, { file = "362" }, { file = "363" }, { file = "372" }} function downloadComplete(file, success) if (source == getResourceRootElement(getThisResource())) then for index, weapon in pairs(weapons) do if file == "weapons/"..weapon.file..".txd" or file == "weapons/"..weapon.file..".dff" then setTimer(replaceModels, 1000, 1) if ( index == #weapons ) then triggerEvent("onClientReplaceStuff", root, true ) break end end end end end addEventHandler("onClientFileDownloadComplete", root, downloadComplete) function replaceModels( b ) if ( b ) then for index, weapon in pairs(weapons) do if fileExists("weapons/"..weapon.file..".txd") and fileExists("weapons/"..weapon.file..".dff") then txd = engineLoadTXD("weapons/"..weapon.file..".txd") engineImportTXD(txd, weapon.file) dff = engineLoadDFF("weapons/"..weapon.file..".dff") engineReplaceModel(dff, weapon.file) else outputDebugString("Weapon file do not not exist for client "..getPlayerName(localPlayer)) end end end end addEventHandler("onClientReplaceStuff", root, replaceModels) Link to comment
Walid Posted September 17, 2016 Share Posted September 17, 2016 The solution is: 1) Always call downloadFile for files with download="false". 2) Only use the file after onClientFileDownloadComplete is triggered. 3) You are using fileExists to skip downloadFile, but fileExists does not check the file content. downloadFile automatcially checks the existing file first, and will immediately trigger onClientFileDownloadComplete if download is not required. Just remove fileExists(). Link to comment
Gravestone Posted September 18, 2016 Author Share Posted September 18, 2016 The first point is obvious, I'm doing that. Second point, it replaces models successfully when the client downloads the files via a command. The weapon models are download so they have to be replace when the client re joins. Or the resource restarts. That's what I'm tried to do. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now