roaddog Posted March 22, 2015 Share Posted March 22, 2015 Here's the script: addEventHandler ( "onClientResourceStop", resourceRoot, function ( ) local file = xmlLoadFile("@Chat.xml", "Chats") or xmlCreateFile('@Chat.xml', 'Chats') if not file then xmlCreateFile('@Chat.xml', 'Chats') end for i, v in pairs ( Chats ) do local child = xmlFindChild ( file, 'chat', 0 ) if child then xmlDestroyNode(file) child = xmlCreateChild(file, 'chat') xmlNodeSetAttribute(child, 'name', v) xmlNodeSetAttribute(child, 'enabled', tostring(isset(eTable[v]))) end if not child then child = xmlCreateChild(file, 'chat') xmlNodeSetAttribute(child, 'name', v) xmlNodeSetAttribute(child, 'enabled', tostring(isset(eTable[v]))) end end xmlSaveFile(file) xmlUnloadFile(file) end ) and the result: <chat name="Support" enabled="false"></chat> <chat name="Main" enabled="false"></chat> <chat name="Team" enabled="false"></chat> <chat name="Local" enabled="false"></chat> <chat name="Group" enabled="false"></chat> <chat name="Advert" enabled="false"></chat> <chat name="Kills" enabled="false"></chat> <chat name="Joinquit" enabled="false"></chat> <chat name="Support" enabled="false"></chat> <chat name="Main" enabled="false"></chat> <chat name="Team" enabled="false"></chat> <chat name="Local" enabled="false"></chat> <chat name="Group" enabled="false"></chat> <chat name="Advert" enabled="false"></chat> <chat name="Kills" enabled="false"></chat> <chat name="Joinquit" enabled="false"></chat> The childs keep getting duplicated everytime I restart the resource. How to fix this? Thanks Link to comment
Addlibs Posted March 22, 2015 Share Posted March 22, 2015 Line 6 through to 19 is in a pairs loop of the table "Chats", I assume the table has 2 values inside it. 2 value stacks are inserted as childs of just 1 XML nodes. I assume you were aiming to have a specific node for Chats[1] and another one for Chats[2], and within each, their respective childs, right? Link to comment
JR10 Posted March 22, 2015 Share Posted March 22, 2015 First of all, you don't need to check if file is nil, it will either load or create. It's getting duplicated because, if found, you're destroying the xml file's node, which won't work, you need to destroy the child node. This is not needed as you can just update the node if it is found. But you keep finding the same child over and over again, destroy it and then recreate it. You can do something like this: addEventHandler ( "onClientResourceStop", resourceRoot, function ( ) local file = xmlCreateFile('@Chat.xml', 'Chats') if not file then return end for i, v in pairs ( Chats ) do local child = xmlCreateChild(file, 'chat') xmlNodeSetAttribute(child, 'name', v) xmlNodeSetAttribute(child, 'enabled', tostring(isset(eTable[v]))) end xmlSaveFile(file) xmlUnloadFile(file) end ) Link to comment
roaddog Posted March 22, 2015 Author Share Posted March 22, 2015 Line 6 through to 19 is in a pairs loop of the table "Chats", I assume the table has 2 values inside it. 2 value stacks are inserted as childs of just 1 XML nodes.I assume you were aiming to have a specific node for Chats[1] and another one for Chats[2], and within each, their respective childs, right? Eh, no... the table is like this; local Chats = { "Support", "Main", "Team", "Local", "Group", "Advert", "Kills","Joinquit" } Update: With your code, now the file only has one child. <Chats> <chat name="Joinquit" enabled="false"></chat> </Chats> Update2: NVM, JR10's worked till I deleted the xml. and recreated it Thanks 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