John Smith Posted August 7, 2014 Share Posted August 7, 2014 hello i found one code on forum not sure where but i have been using it and i tried editing it but theres a problem local screenWidth,screenHeight = guiGetScreenSize() local downloadFiles = { { "mods/alpha.txd" }, { "mods/alpha.dff" }, } function downloadState() dxDrawText("Downloading... (0/2)",screenWidth,screenHeight,screenWidth,screenHeight,tocolor(255,255,255,255),1,"bankgothic") end addEventHandler("onClientRender",root,downloadState) for _, downFile in pairs( downloadFiles ) do downloadFile ( downFile[1] ) downloadState() end addEventHandler ( "onClientFileDownloadComplete", resourceRoot, function ( file, success ) if ( success ) then -- alpha if ( file == "mods/alpha.txd" and fileExists("mods/alpha.dff") ) or ( file == "mods/alpha.dff" and fileExists("mods/alpha.txd") ) then local txdalp = engineLoadTXD ( "mods/alpha.txd" ) local dffalp = engineLoadDFF ( "mods/alpha.dff", 602 ) engineImportTXD ( txdalp, 602 ) engineReplaceModel ( dffalp, 602 ) removeEventHandler("onClientRender",root,downloadState) end end end ) function checkIfPlayerAlreadyHasDownloaded() if ( fileExists("mods/alpha.dff") and fileExists("mods/alpha.txd")) then outputChatBox("Loading carmods...") local txdalp = engineLoadTXD ( "mods/alpha.txd" ) local dffalp = engineLoadDFF ( "mods/alpha.dff", 602 ) engineImportTXD ( txdalp, 602 ) engineReplaceModel ( dffalp, 602 ) else outputChatBox("client has no carmods, and has triggered the download!") for _, downFile in pairs( downloadFiles ) do downloadFile ( downFile[1] ) downloadState() end end end addEventHandler("onClientPlayerSpawn",root,checkIfPlayerAlreadyHasDownloaded) i have already previously downloaded files but when i spawn i need to wait 20 seconds of mta loading gif image and it spams chat with loading carmods...i cant even count how much there were,its whole chat like 10 times i am not sure what is causing this freeze please help Link to comment
TAPL Posted August 7, 2014 Share Posted August 7, 2014 Attach the event onClientPlayerSpawn to localPlayer maybe? And check your code if there any other than event onClientPlayerSpawn attached to the function checkIfPlayerAlreadyHasDownloade. Link to comment
John Smith Posted August 7, 2014 Author Share Posted August 7, 2014 there was no difference, when i spawned i had mta loading gif for 1 minute untill i timed out, and while i had loading gif, it was extremely fast spamming my chat with Loading carmods... Link to comment
John Smith Posted August 7, 2014 Author Share Posted August 7, 2014 if someone could help me, that'd be great Link to comment
Bonsai Posted August 7, 2014 Share Posted August 7, 2014 You don't need to call downloadState(). Its bound to onClientRender, so it will be called on every frame automatically. Instead, you could add the Handler there. But not inside the loop. Also, whats with that for loop in line 12? Its not needed and wrong placed anyway. Link to comment
John Smith Posted August 7, 2014 Author Share Posted August 7, 2014 so like this? local screenWidth,screenHeight = guiGetScreenSize() local downloadFiles = { { "mods/alpha.txd" }, { "mods/alpha.dff" }, } function downloadState() dxDrawText("Downloading... (0/2)",screenWidth,screenHeight,screenWidth,screenHeight,tocolor(255,255,255,255),1,"bankgothic") end addEventHandler ( "onClientFileDownloadComplete", resourceRoot, function ( file, success ) if ( success ) then -- alpha if ( file == "mods/alpha.txd" and fileExists("mods/alpha.dff") ) or ( file == "mods/alpha.dff" and fileExists("mods/alpha.txd") ) then local txdalp = engineLoadTXD ( "mods/alpha.txd" ) local dffalp = engineLoadDFF ( "mods/alpha.dff", 602 ) engineImportTXD ( txdalp, 602 ) engineReplaceModel ( dffalp, 602 ) removeEventHandler("onClientRender",root,downloadState) end end end ) function checkIfPlayerAlreadyHasDownloaded() if ( fileExists("mods/alpha.dff") and fileExists("mods/alpha.txd")) then outputChatBox("Loading carmods...") local txdalp = engineLoadTXD ( "mods/alpha.txd" ) local dffalp = engineLoadDFF ( "mods/alpha.dff", 602 ) engineImportTXD ( txdalp, 602 ) engineReplaceModel ( dffalp, 602 ) else outputChatBox("client has no carmods, and has triggered the download!") for _, downFile in pairs( downloadFiles ) do downloadFile ( downFile[1] ) addEventHandler("onClientRender",root,downloadState) end end end addEventHandler("onClientPlayerSpawn",root,checkIfPlayerAlreadyHasDownloaded) edit: im still getting huge freeze as explained in my previous post Link to comment
TAPL Posted August 7, 2014 Share Posted August 7, 2014 Why you don't just delete this? outputChatBox("Loading carmods...") Link to comment
John Smith Posted August 7, 2014 Author Share Posted August 7, 2014 Why you don't just delete this? outputChatBox("Loading carmods...") that was used for debugging purposes, and as i expected, deleting it didn't fix anything, i still had the freeze Link to comment
Bonsai Posted August 7, 2014 Share Posted August 7, 2014 Not sure why that would help, but also some mistake in that for loop. for _, downFile in pairs( downloadFiles ) do downloadFile ( downFile[1] ) end for _, downFile in pairs( downloadFiles ) do downloadFile ( downFile ) end Also, don't add the handler inside of that loop. Link to comment
John Smith Posted August 7, 2014 Author Share Posted August 7, 2014 i still have that freeze local screenWidth,screenHeight = guiGetScreenSize() local downloadFiles = { { "mods/alpha.txd" }, { "mods/alpha.dff" }, } function downloadState() dxDrawText("Downloading... (0/2)",screenWidth,screenHeight,screenWidth,screenHeight,tocolor(255,255,255,255),1,"bankgothic") end addEventHandler ( "onClientFileDownloadComplete", resourceRoot, function ( file, success ) if ( success ) then -- alpha if ( file == "mods/alpha.txd" and fileExists("mods/alpha.dff") ) or ( file == "mods/alpha.dff" and fileExists("mods/alpha.txd") ) then local txdalp = engineLoadTXD ( "mods/alpha.txd" ) local dffalp = engineLoadDFF ( "mods/alpha.dff", 602 ) engineImportTXD ( txdalp, 602 ) engineReplaceModel ( dffalp, 602 ) removeEventHandler("onClientRender",root,downloadState) end end end ) function checkIfPlayerAlreadyHasDownloaded() if ( fileExists("mods/alpha.dff") and fileExists("mods/alpha.txd")) then local txdalp = engineLoadTXD ( "mods/alpha.txd" ) local dffalp = engineLoadDFF ( "mods/alpha.dff", 602 ) engineImportTXD ( txdalp, 602 ) engineReplaceModel ( dffalp, 602 ) else outputChatBox("client has no carmods, and has triggered the download!") for _, downFile in pairs( downloadFiles ) do downloadFile ( downFile ) end end end addEventHandler("onClientPlayerSpawn",root,checkIfPlayerAlreadyHasDownloaded) addEventHandler("onClientRender",root,downloadState) i used your fix bonsai but i dont understand the handler part,onClientRender is attached to total another function and im having freeze Link to comment
Bonsai Posted August 7, 2014 Share Posted August 7, 2014 I'm just thinking the handler to draw the download message isn't needed before it actually starts. Also, its not needed anymore after the download is finished. But its fine, since you remove it there. But if you add the handler inside of a loop, you add it multiple times. Even though this outputs some error in the debuglog and won't work anyway, its just more "clean" this way. EDIT: Did you try /debugscript 3? It should show some more information, about some infinite running stuff or something. Link to comment
John Smith Posted August 7, 2014 Author Share Posted August 7, 2014 my whole pc is lagging i couldnt even see anything in debugscript 3 because it wasnt possible because of loading and on console it says nothing, only thing which is getting infinite or overflow is my spawn script in which idk why i get c stack overflow but its attached to onPlayerSpawn but it never caused that 1 minute til crash freeze Link to comment
TAPL Posted August 8, 2014 Share Posted August 8, 2014 Did you used spawnPlayer inside event onPlayerSpawn? Link to comment
John Smith Posted August 8, 2014 Author Share Posted August 8, 2014 yeah, and i have replaced those both with setElementPosition onPlayerWasted with a timer, thanks but theres a problem when i didn't download yet the carmod, it outputs that i have triggered the download in chat, but it isnt really downloading i believe, no debugscript 3 errors and my code is same as above posted Link to comment
Et-win Posted August 8, 2014 Share Posted August 8, 2014 Are you also sure you have this in meta.xml: <file src="filename.filetype" download="false" /> ? Also, even if the file has been downloaded, then 'onClientFileDownloadComplete' will still run. Check in your files or the file was downloaded. (In the folder where you have installed MTA. e.g.: E:\Program Files (x86)\Rockstar Games\MTA San Andreas 1.4\mods\deathmatch\resources ) I'm sure you already did, but just to be sure. Link to comment
John Smith Posted August 8, 2014 Author Share Posted August 8, 2014 umm yeah i already have it in meta, and i have already checked before, its not in my resource folder ,so its not downloaded and i dont know why Link to comment
Bonsai Posted August 8, 2014 Share Posted August 8, 2014 As far as I know you don't even have to check if its existing already, since it won't download but still trigger that finish function in that case. Try this with one file only, maybe without importing, also put an "else" to that if (sucess) then thing. Link to comment
John Smith Posted August 8, 2014 Author Share Posted August 8, 2014 fileExists is used because onClientFileDownloadComplete is triggered when ONE by ONE file is downloaded, so if i remove the checks there is possibility of launching carmod without a texture or its shape so it would be fucked and i believe cars wouldn't even be modded if there wasn't import txd and dff function in my script Link to comment
Bonsai Posted August 8, 2014 Share Posted August 8, 2014 Yeah, I know that. I was talking about checkIfPlayerAlreadyHasDownloaded(), sorry. This downloadFile function seems to cause a lot of problems. I never used it so I don't know if its caused by people being unable to use it or general problems. Link to comment
John Smith Posted August 8, 2014 Author Share Posted August 8, 2014 i still dont understand how to make this work maybe i am dumb but i really dont understand what is the problem in the code, and why is it not downloading Link to comment
Et-win Posted August 11, 2014 Share Posted August 11, 2014 Mmm, I will test it this morning for you, since no one knows it lol. Link to comment
xXMADEXx Posted August 11, 2014 Share Posted August 11, 2014 Try running this, not sure if it's going to make a difference though: local screenWidth,screenHeight = guiGetScreenSize() local downloadFiles = { "mods/alpha.txd", "mods/alpha.dff" } function downloadState() dxDrawText("Downloading... (0/2)",screenWidth,screenHeight,screenWidth,screenHeight,tocolor(255,255,255,255),1,"bankgothic") end --[[ This is handled in onClientPlayerSpawn for _, downFile in pairs( downloadFiles ) do downloadFile ( downFile ) downloadState() end ]] addEventHandler ( "onClientFileDownloadComplete", root, function ( file, success ) if ( success and fileExists ( "mods/alpha.dff" ) and fileExists ( "mods/alpha.txd" ) ) then local txdalp = engineLoadTXD ( "mods/alpha.txd" ) local dffalp = engineLoadDFF ( "mods/alpha.dff", 602 ) engineImportTXD ( txdalp, 602 ) engineReplaceModel ( dffalp, 602 ) removeEventHandler("onClientRender",root,downloadState) end end ) function checkIfPlayerAlreadyHasDownloaded() if ( fileExists("mods/alpha.dff") and fileExists("mods/alpha.txd")) then outputChatBox("Loading carmods...") local txdalp = engineLoadTXD ( "mods/alpha.txd" ) local dffalp = engineLoadDFF ( "mods/alpha.dff", 602 ) engineImportTXD ( txdalp, 602 ) engineReplaceModel ( dffalp, 602 ) else outputChatBox("client has no carmods, and has triggered the download!") for _, downFile in pairs( downloadFiles ) do downloadFile ( downFile ) addEventHandler ( "onClientRender", root, downloadState ) end end end addEventHandler("onClientPlayerSpawn", localPlayer, checkIfPlayerAlreadyHasDownloaded ) Link to comment
Et-win Posted August 11, 2014 Share Posted August 11, 2014 Here is your problem: for _, downFile in pairs(downloadFiles) do outputChatBox(tostring(downFile)) lol = downloadFile(downFile) outputChatBox(tostring(lol)) end 'downFile' is a table. Which means, you have to fill this in by 'downloadFile': downloadFile(downFile[1]) EDIT: Damn xXMADEXx, you are earlier than me. Link to comment
Bonsai Posted August 11, 2014 Share Posted August 11, 2014 Maybe you guys should have read the whole topic 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