Controlled Posted December 31, 2013 Share Posted December 31, 2013 Is it possible to have something download via command? or event? Like have the resource start then typing /download and getting certain files i specify? Link to comment
Renkon Posted December 31, 2013 Share Posted December 31, 2013 Yes, you can do it. The easiest way to do that is to fileRead and pass the file as a string. Once client-side you create the file with that string. The other way (in 1.4) is to use fileDownload. Link to comment
Controlled Posted December 31, 2013 Author Share Posted December 31, 2013 Hmm. Can you give me a example for file read? I want a Mod for a vehicle download when a command is used. When I looked at the wiki it was talking about bytes.. Once the file is downloaded I need it to apply the txd.. Link to comment
Renkon Posted December 31, 2013 Share Posted December 31, 2013 You can use fileRead to read the content of the .txd file. Once that is done, you can use triggerClientEvent and pass the content so that you use fileCreate and then you save the file with txd and you finally use engineImportTXD Link to comment
Controlled Posted December 31, 2013 Author Share Posted December 31, 2013 You can use fileRead to read the content of the .txd file.Once that is done, you can use triggerClientEvent and pass the content so that you use fileCreate and then you save the file with txd and you finally use engineImportTXD I am having trouble following. fileRead("mod.txd") triggerClientEvent(source, "runmod", source) For server? Then what were you saying about client Link to comment
Jusonex Posted December 31, 2013 Share Posted December 31, 2013 You should not use triggerClientEvent since it almost blocks network activity. If you want to transfer a lot of data, you should use triggerLatentClientEvent instead. Example: local content = fileRead(file, fileGetSize(file)) -- if you wanna open huge files, use a smaller buffer instead to save memory triggerLatentClientEvent(source, "runmod", root, content) Link to comment
Controlled Posted December 31, 2013 Author Share Posted December 31, 2013 You should not use triggerClientEvent since it almost blocks network activity.If you want to transfer a lot of data, you should use triggerLatentClientEvent instead. Example: local content = fileRead(file, fileGetSize(file)) -- if you wanna open huge files, use a smaller buffer instead to save memory triggerLatentClientEvent(source, "runmod", root, content) Thanks! Is there any way to have a progress bar of some sorts? so it tells you what your progress is? and I'm not sure what you mean about opening huge files? Link to comment
Controlled Posted December 31, 2013 Author Share Posted December 31, 2013 This is how I had it written.. Server: function download() local open = fileOpen("BUyJfGFCMAEe5BI.jpg") local content = fileRead("BUyJfGFCMAEe5BI.jpg", fileGetSize("BUyJfGFCMAEe5BI.jpg")) -- if you wanna open huge files, use a smaller buffer instead to save memory triggerLatentClientEvent(source, "runMod", resourceRoot, content) end addCommandHandler("dicks", download) Client addEvent("runMod", true) function runMod() local hfile = fileOpen("BUyJfGFCMAEe5BI.jpg", false) if hfile then outputDebugString("You have it") else fileCreate("BUyJfGFCMAEe5BI.jpg") fileWrite(hfile, content) outputDebugString("Done") end end addEventHandler("runMod", resourceRoot, runMod) I am getting errors from Server Side saying bad file pointer. Also Expected String at Argument 1 got nil. For triggerLatentEvent Thats simply to download it, not to apply anything Link to comment
Renkon Posted December 31, 2013 Share Posted December 31, 2013 First element should be root rather than source I guess, if it's for everybody Link to comment
Dealman Posted December 31, 2013 Share Posted December 31, 2013 You could use this resource. Link to comment
Controlled Posted December 31, 2013 Author Share Posted December 31, 2013 I went to using fetchRemote.. Just a question about it. Can I get it to show a percent progress? So they know how the download is going? Link to comment
xXMADEXx Posted December 31, 2013 Share Posted December 31, 2013 I went to using fetchRemote.. Just a question about it. Can I get it to show a percent progress? So they know how the download is going? You can't... Link to comment
ixjf Posted January 1, 2014 Share Posted January 1, 2014 This is how I had it written..[...] I am getting errors from Server Side saying bad file pointer. Also Expected String at Argument 1 got nil. For triggerLatentEvent Thats simply to download it, not to apply anything There you have your code, fixed: Server: function _downloadFile ( player ) local file = fileOpen ( "BUyJfGFCMAEe5BI.jpg", true ) if ( file ) then local content = fileRead ( file, fileGetSize ( file ) ) triggerLatentClientEvent ( player, "runMod", resourceRoot, content ) -- You can now use 'getLatentEventHandles' and 'getLatentEventStatus' -- to get the status of the latent event -- You may as well mess with triggerLatentClientEvent's bandwidth parameter -- if the download speed is too slow else outputChatBox ( "Couldn't find file to download", player ) end end addCommandHandler ( "dicks", _downloadFile ) Your mistake here was the use of the file name in file functions where they expected a file element, which was returned in the fileOpen call. Client: function runMod ( content ) local file = fileOpen ( "BUyJfGFCMAE5BI.jpg" ) if ( file ) then outputDebugString ( "You already have the file" ) fileClose ( file ) else file = fileCreate ( "BUyJfGFCMAE5BI.jpg" ) fileWrite ( file, content ) fileClose ( file ) outputDebugString ( "Done" ) end end addEvent ( "runMod", true ) addEventHandler ( "runMod", root, runMod ) Here, you forgot to close the file handles and you messed up everything in the part where you write the content to the file. I would suggest you to check whether the files the client has are not modified, by the way. 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