WiBox Posted June 4, 2019 Share Posted June 4, 2019 I need to reload a xml file without restarting the resource is there a way to do that? Link to comment
SycroX Posted June 5, 2019 Share Posted June 5, 2019 (edited) xmlLoadFile Edited June 5, 2019 by #x1AhMeD-09 Link to comment
WiBox Posted June 5, 2019 Author Share Posted June 5, 2019 Nvm worked, I used that function, but I've forgotten to add the client script to meta.xml, silly right? Thanks anyway Link to comment
WiBox Posted June 6, 2019 Author Share Posted June 6, 2019 Okay I'm not sure why but it's not working anymore, so I'm trying to download a picture using fetchRemote(Worked), then it will edit the (xmlLoadFile, xmlSaveFile, xmlUnloadFile) meta.xml(worked), and the file gets downloaded in the server script, BUT when I use downloadFile by triggering it from the client side(triggerClientEvent), the file doesn't get downloaded... So what should I do? Note: I need the file to be download globally, not for the client only... Link to comment
WiBox Posted June 6, 2019 Author Share Posted June 6, 2019 So my only choice is to reload the XML file, means my only choice is the restart the script? Link to comment
salh Posted June 6, 2019 Share Posted June 6, 2019 you need update the xml file with out restart the script? you can use https://wiki.multitheftauto.com/wiki/XmlSaveFile and https://wiki.multitheftauto.com/wiki/XmlLoadFile Link to comment
WiBox Posted June 6, 2019 Author Share Posted June 6, 2019 (edited) function addToXML( player, GlobalID, folder, folder1 ) local xml = xmlLoadFile("meta.xml") if ( xml ) then huh = xmlCreateChild( xml, "file" ) xmlNodeSetAttribute( huh, "src", folder.."/"..folder1.."/"..GlobalID) xmlSaveFile(xml) xmlUnloadFile(xml) else print("Unable to open meta.xml") end end Already did that, unfortunate it didn't work, I've tried to reconnect thought maybe when I join the server that picture will be downloaded, but it didn't, only when I restarted the script, the picture gets downloaded Edited June 6, 2019 by R.I.P Logic Link to comment
salh Posted June 6, 2019 Share Posted June 6, 2019 (edited) try this -- Client function addToXML( player, GlobalID, folder, folder1 ) local xml = xmlLoadFile("meta.xml") if ( xml ) then huh = xmlCreateChild( xml, "file" ) xmlNodeSetAttribute( huh, "src", folder.."/"..folder1.."/"..GlobalID) xmlSaveFile(xml) xmlUnloadFile(xml) else print("Unable to open meta.xml") end end addCommandHandler("Reload", addToXML) Edited June 6, 2019 by salh Link to comment
WiBox Posted June 6, 2019 Author Share Posted June 6, 2019 Dude, I trigger it every time a player tries to add a picture, you can't add a command handler for it... It starts as a panel write the link and stuff, then press the button, then it triggers the FetchRemote to download it, then it goes to fileCreate write and close, then it triggers addToXML then it triggers a client event downloadFile, that's it. But the thing is, it doesn't say like file doesn't exist, I go to MTA > Mods > Deathmatch ... > to the script, but the picture wasn't there. I've reconnected, like maybe it will load the XML file, didn't. As I said only when I restart the script, that picture gets downloaded. Link to comment
DNL291 Posted June 6, 2019 Share Posted June 6, 2019 The resource is not automatically updated when you modify the meta.xml file, the change only takes effect by restarting the resource. I wonder what exactly do you want to do, I mean, will it really be necessary adding each file in meta.xml? I suggest you using triggerLatentClientEvent instead, since it will transfer a large amount of data thus generating a high network traffic. Since you're already sending the file raw data to the client, you can do this in another way, and not having to worry about add each file to the meta.xml. You can use fileCreate/write/close client-side instead of downloadFile. You'll also need to check if the file already exists in the client's cache folder. Link to comment
WiBox Posted June 7, 2019 Author Share Posted June 7, 2019 So you want that onPlayerLogin check if players have the files? If they don't have it I'll use fileCreate/write/close? You're idea works, I can let them play while those files are downloading and add a note that they download some stuff, so I won't need to add them in a meta.xml, I thought of it, but I've read at Avoid using fileExists before calling downloadFile. Always call downloadFile and handle the result in onClientFileDownloadComplete at https://wiki.multitheftauto.com/wiki/DownloadFile, but I don't have a choice anyway, thanks. Link to comment
DNL291 Posted June 8, 2019 Share Posted June 8, 2019 Yes, basically you will keep stored on server-side the fetchRemote files (a reference to the name/directory, not the file itself), and determine which files should be transferred by triggering server >> client and vice versa, then send it (triggerLatentClientEvent > fileCreate/etc ...). 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