codeluaeveryday Posted February 27, 2012 Share Posted February 27, 2012 Hi all, requiring help for this small script. No debug errors, all maps are UNZIPPED and why won't this work? function fixRespawnMaps() count = 0 for i, v in ipairs(exports.mapmanager:getMapsCompatibleWithGamemode(exports.mapmanager:getRunningGamemode())) do main = xmlLoadFile(":"..getResourceName(v).."/meta.xml") settings = xmlFindChild(main,"settings",0) for b,ad in ipairs(xmlNodeGetChildren(settings)) do if xmlNodeGetAttribute(ad,"value") ~= "none" then xmlNodeSetAttribute(ad,"value","none") count = count + 1 end end end return count end addCommandHandler("fixAllMaps", function(player) if hasObjectPermissionTo(player,"function.setServerPassword",true) then lol = fixRespawnMaps() outputChatBox("(MAPFIX) You have fixed #FFFFFF"..lol.."#FF6464 maps!",player,255,100,100,true) else outputChatBox("(MAPFIX) You don't have the required rights to perform this action!",player,255,100,100) end end ) It will output the count correctly. I just think its a permission problem? Its in the ACL... Whats wrong with it? Link to comment
Kenix Posted February 27, 2012 Share Posted February 27, 2012 Try debug it. function fixRespawnMaps( ) outputChatBox 'called' local count = 0 for _, v in pairs( exports.mapmanager:getMapsCompatibleWithGamemode( exports.mapmanager:getRunningGamemode( ) ) ) do outputChatBox 'loop' local main = xmlLoadFile( ":"..getResourceName( v ).."/meta.xml" ) if main then outputChatBox( 'open meta.xml '..getResourceName( v ) ) settings = xmlFindChild( main,"settings",0 ) for _,value in pairs( xmlNodeGetChildren( settings ) ) do outputChatBox 'loop settings' if xmlNodeGetAttribute( value,"value") ~= "none" then outputChatBox 'value ~= none' xmlNodeSetAttribute( value,"value","none" ) count = count + 1 end end else outputChatBox 'cant open meta.xml' end end return count end addCommandHandler( "fixAllMaps", function( player ) if hasObjectPermissionTo( player,"function.setServerPassword",true ) then outputChatBox( "(MAPFIX) You have fixed #FFFFFF"..tostring( fixRespawnMaps( ) ).."#FF6464 maps!",player,255,100,100,true ) else outputChatBox( "(MAPFIX) You don't have the required rights to perform this action!",player,255,100,100 ) end end ) Updated. Link to comment
codeluaeveryday Posted February 27, 2012 Author Share Posted February 27, 2012 It says this over and over with different map names. open meta.xml race-wuzimu loop settings value ~= none loop settings value ~= none (MAPFIX) You have fixed 188 maps! Maps arnt fixing Link to comment
Kenix Posted February 27, 2012 Share Posted February 27, 2012 Try function fixRespawnMaps( ) local count = 0 for _, v in pairs( exports.mapmanager:getMapsCompatibleWithGamemode( exports.mapmanager:getRunningGamemode( ) ) ) do local main = xmlLoadFile( ":"..getResourceName( v ).."/meta.xml" ) if main then settings = xmlFindChild( main,"settings",0 ) for i = 0,#xmlNodeGetChildren( settings ) do local node = xmlFindChild( v, "setting", i ) if xmlNodeGetAttribute( node,"value" ) ~= "none" then xmlNodeSetAttribute( node,"value","none" ) count = count + 1 end end end end return count end addCommandHandler( "fixAllMaps", function( player ) if hasObjectPermissionTo( player,"function.setServerPassword",true ) then outputChatBox( "(MAPFIX) You have fixed #FFFFFF"..tostring( fixRespawnMaps( ) ).."#FF6464 maps!",player,255,100,100,true ) else outputChatBox( "(MAPFIX) You don't have the required rights to perform this action!",player,255,100,100 ) end end ) Link to comment
BinSlayer1 Posted February 27, 2012 Share Posted February 27, 2012 looking at the debug you posted it looks like everything gets called including the if xmlNodeGetAttribute so just check if it fails here xmlNodeSetAttribute( node,"value","none" ) do this instead of your code: local check = xmlNodeSetAttribute( node,"value","none" ) outputChatBox(tostring(check)) False/True? Link to comment
codeluaeveryday Posted February 27, 2012 Author Share Posted February 27, 2012 Yes its returning false. Link to comment
BinSlayer1 Posted February 27, 2012 Share Posted February 27, 2012 "Returns true if the attribute was set successfully, false if the node and/or attribute do not exist, or if they're faulty. " Your .xml file is not configured correctly I think even "if xmlNodeGetAttribute( node,"value" ) ~= "none" then" actually fails. Because for all I know you could be comparing false with 'none' so the if clause will always be executed Do this: if xmlNodeGetAttribute( node,"value" ) and xmlNodeGetAttribute( node,"value" ) ~= "none" then After you do this, you will most likely see that it won't execute the IF anymore So the problem is within the loaded xml file and not the lua script. Link to comment
bandi94 Posted February 27, 2012 Share Posted February 27, 2012 You use only " xmlNodeSetAttribute( value,"value","none" )" this edit the meta.xml file only in the memory after you edited the xml file you need to save the change's whit "xmlSaveFile" and after you saved it unload it from the memory whit xmlUnloadFile try this function fixRespawnMaps( ) local count = 0 for _, v in pairs( exports.mapmanager:getMapsCompatibleWithGamemode( exports.mapmanager:getRunningGamemode( ) ) ) do local main = xmlLoadFile( ":"..getResourceName( v ).."/meta.xml" ) if main then settings = xmlFindChild( main,"settings",0 ) for i = 0,#xmlNodeGetChildren( settings ) do local node = xmlFindChild( v, "setting", i ) if xmlNodeGetAttribute( node,"value" ) ~= "none" then xmlNodeSetAttribute( node,"value","none" ) xmlSaveFile(main) count = count + 1 end end end if main then xmlUnloadFile(main) end end return count end addCommandHandler( "fixAllMaps", function( player ) if hasObjectPermissionTo( player,"function.setServerPassword",true ) then outputChatBox( "(MAPFIX) You have fixed #FFFFFF"..tostring( fixRespawnMaps( ) ).."#FF6464 maps!",player,255,100,100,true ) else outputChatBox( "(MAPFIX) You don't have the required rights to perform this action!",player,255,100,100 ) end end ) Link to comment
BinSlayer1 Posted February 27, 2012 Share Posted February 27, 2012 Bandi94, that doesn't explain why xmlNodeSetAttribute returns false in his code.. While what you're pointing out is indeed -another- bug, there must be something wrong with the xmlNodeSetAttribute too Link to comment
codeluaeveryday Posted February 27, 2012 Author Share Posted February 27, 2012 it is this function for sure. The xmlNodeSetAttribute must be bugged? Link to comment
Castillo Posted February 27, 2012 Share Posted February 27, 2012 function fixRespawnMaps( ) local count = 0 for _, v in pairs( exports.mapmanager:getMapsCompatibleWithGamemode( exports.mapmanager:getRunningGamemode( ) ) ) do local main = xmlLoadFile( ":"..getResourceName( v ).."/meta.xml" ) if main then settings = xmlFindChild( main,"settings",0 ) local node = xmlFindChild( settings, "setting", 0 ) local i = 1 while node do if (xmlNodeGetAttribute( node, "value" ) ~= "none") then xmlNodeSetAttribute( node,"value","none" ) xmlSaveFile(main) end node = xmlFindChild( v, "setting", i ) i = i + 1 end count = count + 1 xmlUnloadFile(main) end end return count end addCommandHandler( "fixAllMaps", function( player ) if hasObjectPermissionTo( player,"function.setServerPassword",true ) then outputChatBox( "(MAPFIX) You have fixed #FFFFFF"..tostring( fixRespawnMaps( ) ).."#FF6464 maps!",player,255,100,100,true ) else outputChatBox( "(MAPFIX) You don't have the required rights to perform this action!",player,255,100,100 ) end end ) I've tested it with one map and it worked, it set the setting value from X to "none". 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