TimJ Posted February 13, 2009 Share Posted February 13, 2009 Im playing with xml at the moment, but what im trying to do is get the players name as the name of the subnode and the content to be their current vehicle but its not working... Heres the code: function xml ( source ) local name = getPlayerNametagText ( source ) local content = getPlayerOccupiedVehicle ( source ) local xmlFile=xmlLoadFile("xmlfile.xml") local node=xmlCreateSubNode(xmlfile, name) local success=xmlNodeSetValue(node, content) if success then xmlSaveFile(xmlFile) end end addCommandHandler("test", xml) i had a previous version that worked and made a subnode of their player name but put the content as "content" but after changing it to try and work how i wanted to it doesnt work Link to comment
50p Posted February 13, 2009 Share Posted February 13, 2009 In your case "content" is vehicle element, it's not a number, string or something that you can save in a file. You can't save vehicle that way. You'd have to save the ID of the car not the "vehicle" element. Link to comment
TimJ Posted February 13, 2009 Author Share Posted February 13, 2009 K ive changed that: function xml ( source ) local name = getPlayerNametagText(source) local vehicle = getPlayerOccupiedVehicle(source) local content = getVehicleName(vehicle) local xmlFile=xmlLoadFile("xmlfile.xml") local node=xmlCreateSubNode(xmlfile, name) local success=xmlNodeSetValue(node, content) if success then xmlSaveFile(xmlFile) end end addCommandHandler("test", xml) but i get these errors: Bad argument @ 'xmlCreateSubNode' - Line: 7 Bad argument @ 'xmlNodeSetValue' -Line: 8 Link to comment
Gamesnert Posted February 13, 2009 Share Posted February 13, 2009 function xml ( player ) local name = getPlayerNametagText(player) local vehicle = getPlayerOccupiedVehicle(player) local content = getVehicleName(vehicle) local xmlFile=xmlLoadFile("xmlfile.xml") local node=xmlCreateSubNode(xmlfile, name) local success=xmlNodeSetValue(node, content) if success then xmlSaveFile(xmlFile) end end addCommandHandler("test", xml) Try replacing source with player. (like I did above) Should help. And if it didn't, it would still be a good reminder to NOT define source yourself. It'll only get you in trouble... =/ Link to comment
TimJ Posted February 13, 2009 Author Share Posted February 13, 2009 Still not working Link to comment
Ace_Gambit Posted February 13, 2009 Share Posted February 13, 2009 What about the typo "xmlfile" instead of "xmlFile"? Link to comment
TimJ Posted February 14, 2009 Author Share Posted February 14, 2009 Still screwed... Its saying its having probs making the node and editting the content, i dont understand whats wrong there at the moment... Link to comment
Lordy Posted February 14, 2009 Share Posted February 14, 2009 Is the source or the player variable actually a player element too? You can test it with outputChatBox(tostring(player)) inside the xml function. If it's player, it outputs some userdata value to chatbox Link to comment
TimJ Posted February 14, 2009 Author Share Posted February 14, 2009 Thanks all, ive got it working. Now im on the next bit of the script, which "co-incidently" im having trouble with too lol: function getcar ( source ) local name = getPlayerNametagText(source) local xmlFile=xmlLoadFile("xmlfile.xml") if xmlFile then --If it's indeed opened: local node=xmlFindSubNode(xmlFile,"somesubnode",0) local success=xmlNodeGetValue(node) if success then outputChatBox(tostring(success)) end end outputChatBox( "done", source ) warpPlayerIntoVehicle ( playerSource, success ) end addCommandHandler("getcar", getcar) i get this error: Bad Argument @ 'warpPlayerIntoVehicle' - Line: 31 Whats wrong with it ? Link to comment
Vivalavido Posted February 14, 2009 Share Posted February 14, 2009 Thanks all, ive got it working. Now im on the next bit of the script, which "co-incidently" im having trouble with too lol: function getcar ( source ) local name = getPlayerNametagText(source) local xmlFile=xmlLoadFile("xmlfile.xml") if xmlFile then --If it's indeed opened: local node=xmlFindSubNode(xmlFile,"somesubnode",0) local success=xmlNodeGetValue(node) if success then outputChatBox(tostring(success)) end end outputChatBox( "done", source ) warpPlayerIntoVehicle ( playerSource, success ) end addCommandHandler("getcar", getcar) i get this error: Bad Argument @ 'warpPlayerIntoVehicle' - Line: 31 Whats wrong with it ? Try: function getcar ( source ) local name = getPlayerNametagText(source) local xmlFile=xmlLoadFile("xmlfile.xml") if xmlFile then --If it's indeed opened: local node=xmlFindSubNode(xmlFile,"somesubnode",0) local success=xmlNodeGetValue(node) if success then outputChatBox(tostring(success)) end end outputChatBox( "done", source ) warpPlayerIntoVehicle ( source, success ) end addCommandHandler("getcar", getcar) Link to comment
Lordy Posted February 15, 2009 Share Posted February 15, 2009 Have no idea what vivalavido tried, but TimJ, you are trying to warp a player into a string... local success=xmlNodeGetValue(node) and later on warpPlayerIntoVehicle ( playerSource, success ) Wiki gives this syntax: bool warpPlayerIntoVehicle ( player thePlayer, vehicle theVehicle, [ int seat=0 ] ) Which means that you need to put a variable pointing at vehicle element to the second place not a string. And to be honest, you don't have playerSource variable defined anywhere either, so basically you are doing warpPlayerIntoVehicle(nil, "somestring") No wonder it doesn't work.. And on another look you actually do warpPlayerIntoVehicle(nil, nil) since you defined local success = blah inside an if statement.. Which means that it doesn't exist outside it EDIT: If you can say what you want to achieve with the script, we might help a bit more than only find errors in your script. Link to comment
TimJ Posted February 15, 2009 Author Share Posted February 15, 2009 Well basicly the first part gets the car your in and saves it in a meta file like this: car name e.g <{TJT}Tim>Police{TJT}Tim> I've done that and it works fine, but what i want it to do now is retrieve the information so that it will give you the car saved with your name. And i didnt really understand this: Wiki gives this syntax:Line number On/Off | Expand/Contract | Select all bool warpPlayerIntoVehicle ( player thePlayer, vehicle theVehicle, [ int seat=0 ] ) Which means that you need to put a variable pointing at vehicle element to the second place not a string. Link to comment
50p Posted February 15, 2009 Share Posted February 15, 2009 You shouldn't make tags which are the name of player. Your example of: <{TJT}Tim>Police{TJT}Tim> is wrong format of XML. You can't use { or } in XML tags or attributes. Use different way, like: Police or something else. 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