xXMADEXx Posted January 9, 2013 Share Posted January 9, 2013 I have made this script, the xml file will create fine, but when i type /create it will not insert the data. Please help. function createFileHandler (player) myfile = xmlCreateFile("spawners.xml","spawners") NewNode = xmlCreateChild(myfile, "spawner") xmlSaveFile(myfile) outputChatBox("spawners.xml has successfuly been created!", player, 0,255,0) end addCommandHandler ( "file", createFileHandler ) function createspawners (player) if isObjectInACLGroup ( "user." .. getAccountName ( getPlayerAccount ( player ) ), aclGetGroup ( "lvl 5" ) ) then local x, y, z = getElementPosition ( player ) -- local rot = getPedRotation ( player ) local int = getElementInterior ( player ) local dim = getElementDimension ( player ) local file = xmlLoadFile("spawners.xml") if (file) then local newChild = xmlFindChild ( file, "spawners", 0 ) xmlNodeSetAttribute ( newChild, "x", x ) xmlNodeSetAttribute ( newChild, "y", y ) xmlNodeSetAttribute ( newChild, "z", z ) xmlNodeSetAttribute ( newChild, "int", int ) xmlNodeSetAttribute ( newChild, "dim", dim ) created = createMarker (x, y, z-1, "cylinder", 2, 255, 0, 0, 200) setElementInterior ( created, int ) outputChatBox ( "Marker has successfully been created!", player, 0, 255, 0 ) else outputChatBox ( "Spawners: spawners.xml has failed to load! Fixing problem now.", player, 255, 0, 0 ) xmlCreateChild(myfile, "spawner") end else outputChatBox ( "Spawners: This command is only for admins!", player, 255, 0, 0 ) end end addCommandHandler ( "create", createspawners ) Link to comment
Vision Posted January 9, 2013 Share Posted January 9, 2013 Try this function createFileHandler (player) myfile = xmlCreateFile("spawners.xml","spawners") NewNode = xmlCreateChild(myfile, "spawner") xmlSaveFile(myfile) outputChatBox("spawners.xml has successfuly been created!", player, 0,255,0) end addCommandHandler ( "file", createFileHandler ) function createspawners (player) if isObjectInACLGroup ( "user." .. getAccountName ( getPlayerAccount ( player ) ), aclGetGroup ( "lvl 5" ) ) then local x, y, z = getElementPosition ( player ) -- local rot = getPedRotation ( player ) local int = getElementInterior ( player ) local dim = getElementDimension ( player ) local file = xmlLoadFile("spawners.xml") if (file) then local newChild = xmlFindChild ( file, "spawner", 0 ) xmlNodeSetAttribute ( newChild, "x", x ) xmlNodeSetAttribute ( newChild, "y", y ) xmlNodeSetAttribute ( newChild, "z", z ) xmlNodeSetAttribute ( newChild, "int", int ) xmlNodeSetAttribute ( newChild, "dim", dim ) created = createMarker (x, y, z-1, "cylinder", 2, 255, 0, 0, 200) setElementInterior ( created, int ) outputChatBox ( "Marker has successfully been created!", player, 0, 255, 0 ) xmlSaveFile ( file ) else outputChatBox ( "Spawners: spawners.xml has failed to load! Fixing problem now.", player, 255, 0, 0 ) xmlCreateChild(myfile, "spawner") end else outputChatBox ( "Spawners: This command is only for admins!", player, 255, 0, 0 ) end end addCommandHandler ( "create", createspawners ) Link to comment
xXMADEXx Posted January 9, 2013 Author Share Posted January 9, 2013 Thanks, if fixed that old problem, But how can i make the xml file load correctly when i start the resource? function createFileHandler (player) myfile = xmlCreateFile("spawners.xml","spawners") --NewNode = xmlCreateChild(myfile, "spawner") xmlSaveFile(myfile) outputChatBox("spawners.xml has successfuly been created!", player, 0,255,0) end addCommandHandler ( "file", createFileHandler ) function onstart() xmlLoadFile ( "spawners.xml" ) end addEventHandler("onResourceStart", onstart) function createspawners (player) if isObjectInACLGroup ( "user." .. getAccountName ( getPlayerAccount ( player ) ), aclGetGroup ( "lvl 5" ) ) then local x, y, z = getElementPosition ( player ) -- local rot = getPedRotation ( player ) local int = getElementInterior ( player ) local dim = getElementDimension ( player ) local file = xmlLoadFile("spawners.xml") if (file) then local newChild = xmlCreateChild ( file, "spawners", 0 ) xmlNodeSetAttribute ( newChild, "x", x ) xmlNodeSetAttribute ( newChild, "y", y ) xmlNodeSetAttribute ( newChild, "z", z ) xmlNodeSetAttribute ( newChild, "int", int ) xmlNodeSetAttribute ( newChild, "dim", dim ) created = createMarker (x, y, z-1, "cylinder", 2, 255, 0, 0, 200) setElementInterior ( created, int ) outputChatBox ( "Marker has successfully been created!", player, 0, 255, 0 ) addEventHandler("onMarkerHit",created,showGUI) xmlSaveFile(file) else outputChatBox ( "Spawners: spawners.xml has failed to load! Fixing problem now.", player, 255, 0, 0 ) xmlCreateChild(file, "spawner") end else outputChatBox ( "Spawners: This command is only for admins!", player, 255, 0, 0 ) end end addCommandHandler ( "create", createspawners ) Link to comment
Vision Posted January 9, 2013 Share Posted January 9, 2013 (edited) addEventHandler("onResourceStart", resourceRoot, function ( ) local file = xmlLoadFile ( "spawners.xml" ) if ( file ) then local newChild = xmlFindChild ( file, 'spawner', 0 ) local x = xmlNodeGetAttribute ( newChild, "x" ) local y = xmlNodeGetAttribute ( newChild, "y" ) local z = xmlNodeGetAttribute ( newChild, "z" ) createMarker ( tonumber(x), tonumber(y), tonumber(z-1), "cylinder", 2, 255, 0, 0, 200 ) end end ) Edited January 9, 2013 by Guest Link to comment
GhostXoP Posted January 9, 2013 Share Posted January 9, 2013 addEventHandler("onResourceStart", resourceRoot, onstart) Please note that this line is also very important in the long run, you will have un-explainable errors popping out of nowhere because when you went to start another resource, this function was ran again. Link to comment
Vision Posted January 9, 2013 Share Posted January 9, 2013 addEventHandler("onResourceStart", resourceRoot, onstart) Please note that this line is also very important in the long run, you will have un-explainable errors popping out of nowhere because when you went to start another resource, this function was ran again. I will remember that next time, 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