TheIceman1 Posted April 12, 2013 Share Posted April 12, 2013 When i make clan "Military" then in clans.xml said this: <clans> <clans name="Military"></clans> </clans> But when other player make new clan then in clans.xml said this and remove my clan: <clans> <clans name="SWAT"></clans> </clans> But i want this: <clans> <clans name="Military"></clans> <clans name="SWAT"></clans> </clans> Code local root = xmlLoadFile ("clans.xml") local clroot = xmlFindChild (root,"clans",0) if (clroot) then xmlNodeSetAttribute (clroot,"name", clan) else clroot = xmlCreateChild(root, "clans") xmlNodeSetAttribute (clroot,"name", clan) end xmlSaveFile( root ) xmlUnloadFile ( root ) Understand what i want? Link to comment
DiSaMe Posted April 12, 2013 Share Posted April 12, 2013 Nothing is removed. Your script searches for existing clan node and changes its name instead of creating another node. Link to comment
TheIceman1 Posted April 12, 2013 Author Share Posted April 12, 2013 (edited) You mean this?But this dont work local root = xmlLoadFile ("clans.xml") clroot = xmlCreateChild(root, "clans") xmlNodeSetAttribute (clroot,"name", clan) end xmlSaveFile( root ) xmlUnloadFile ( root ) Edited April 13, 2013 by Guest Link to comment
DiSaMe Posted April 12, 2013 Share Posted April 12, 2013 Probably because you have a syntax error clearly visible in the middle of this script. Link to comment
TheIceman1 Posted April 13, 2013 Author Share Posted April 13, 2013 I see no problems... Link to comment
TheIceman1 Posted April 13, 2013 Author Share Posted April 13, 2013 I have new problem. Players make clans then in clans.xml said this : <clans> <clans name="Military"></clans> <clans name="SWAT"></clans> <clans name="FBI"></clans> </clans> But when i delete "Military" then in clans.xml said this(all clans are deleted): <clans> </clans> But i want this,when i delete "Military" then in clans.xml said this: <clans> <clans name="SWAT"></clans> <clans name="FBI"></clans> </clans> Code: local clansroot = xmlLoadFile ("clans.xml") if ( clansroot ) then for i,v in ipairs (xmlNodeGetChildren(clansroot)) do local clanname = xmlNodeGetAttribute (v,"name") xmlDestroyNode ( v ) xmlSaveFile ( clansroot ) xmlUnloadFile ( clansroot ) Link to comment
codeluaeveryday Posted April 13, 2013 Share Posted April 13, 2013 The reason it is deleting them all is because you are 'for' looping all the children of the xml file then using xmlDestroyNode, if you cannot figure it out, can you please post the full function handler. Link to comment
TheIceman1 Posted April 13, 2013 Author Share Posted April 13, 2013 function destroyclan () local clan = getElementData ( source, "clan" ) local acc = getPlayerAccount ( source ) local clansroot = xmlLoadFile ("clans.xml") if ( clansroot ) then for i,v in ipairs (xmlNodeGetChildren(clansroot)) do local xmlnumber = xmlNodeGetAttribute (v,"name") xmlDestroyNode ( v ) xmlSaveFile ( clansroot ) xmlUnloadFile ( clansroot ) exports ["guimessages"] : outputServer ( source, "You destroy your clan!", 255, 255, 0 ) setAccountData ( acc, "Clan", false ) removeElementData ( source, "clan" ) end end end addEvent ( "destroyclan", true ) addEventHandler ( "destroyclan", root, destroyclan ) Link to comment
codeluaeveryday Posted April 13, 2013 Share Posted April 13, 2013 function destroyclan () local clan = getElementData ( source, "clan" ) local acc = getPlayerAccount ( source ) local clansroot = xmlLoadFile ("clans.xml") if ( clansroot ) then for i,v in ipairs (xmlNodeGetChildren(clansroot)) do local clanName = xmlNodeGetAttribute (v,"name") if clanName:lower() == clan:lower() then xmlDestroyNode ( v ) xmlSaveFile ( clansroot ) xmlUnloadFile ( clansroot ) exports ["guimessages"] : outputServer ( source, "You destroy your clan!", 255, 255, 0 ) setAccountData ( acc, "Clan", false ) removeElementData ( source, "clan" ) end end end end addEvent ( "destroyclan", true ) addEventHandler ( "destroyclan", root, destroyclan ) Link to comment
codeluaeveryday Posted April 13, 2013 Share Posted April 13, 2013 No problem Never stop coding brother Link to comment
Castillo Posted April 14, 2013 Share Posted April 14, 2013 function destroyclan () local clan = getElementData ( source, "clan" ) local acc = getPlayerAccount ( source ) local clansroot = xmlLoadFile ("clans.xml") if ( clansroot ) then for i,v in ipairs (xmlNodeGetChildren(clansroot)) do local clanName = xmlNodeGetAttribute (v,"name") if clanName:lower() == clan:lower() then xmlDestroyNode ( v ) xmlSaveFile ( clansroot ) xmlUnloadFile ( clansroot ) exports ["guimessages"] : outputServer ( source, "You destroy your clan!", 255, 255, 0 ) setAccountData ( acc, "Clan", false ) removeElementData ( source, "clan" ) end end end end addEvent ( "destroyclan", true ) addEventHandler ( "destroyclan", root, destroyclan ) You should break the loop after the data was found. Link to comment
codeluaeveryday Posted April 14, 2013 Share Posted April 14, 2013 Yeah, add break to the loop, it was 1am when I wrote this one, I was tired. People miss things, I've seen Castillo miss many things in his codes, then 1 month later he fixes them, he still hasn't fixed his gang system bug I commented with. 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