Jump to content

Is there a way I can reload a xml file?


WiBox

Recommended Posts

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
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 by R.I.P Logic
Link to comment

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 by salh
Link to comment

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
  • Moderators

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

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
  • Moderators

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...