robhol Posted June 15, 2008 Share Posted June 15, 2008 Okay, i have an XML config file that looks like this: <gpconf> <locations> <gploc x="0" y="0" z="0" clue="This is clue 1" /> <gploc x="1" y="1" z="1" clue="This is clue 2" /> </locations> <gptime beforestart="2" duration="5" beforenext="5" /> <gpcash minimumcash = "50000" maximumcash = "99999" /> </gpconf> The meaning is that all the attrbs in the gptime and gpcash nodes should end up in their own var, and that I should be able to choose ONE gploc at random. Can anybody help me with this? Is there a way to know how many subnodes of a specific type there is inside a node? How would i "get amount" of gplocs in ? Can anybody help me with this? Link to comment
norby89 Posted June 15, 2008 Share Posted June 15, 2008 you keep reading the subnodes until you get to the end ( 0, 1, 2, 3, ... ) PS) there are functions that will make this easier in dp3 Link to comment
tma Posted June 15, 2008 Share Posted June 15, 2008 To count child nodes use xmlFindSubNode() with an increasing index. Once this function returns false, you've found all your subnodes i.e. start with index 0 and keep calling this function with 0,1,2,3 ... etc. until it fails. Link to comment
Mr.Hankey Posted June 15, 2008 Share Posted June 15, 2008 (edited) hm... i just recognized that tma and norby already answered while writing this post but anyway here's an example: node = true index = 0 function count () while node ~= false do node = xmlFindSubNode (xml, "gploc", index) index = index + 1 end outputChatBox ("There are "..tostring(index).." subnodes") end --note that you'll have to set node = true and index = 0 if you want to call the function again Maybe there are easier ways to do this but thats how i got it working Edited June 15, 2008 by Guest Link to comment
norby89 Posted June 15, 2008 Share Posted June 15, 2008 I think it should be: while node ~= false do Link to comment
eAi Posted June 15, 2008 Share Posted June 15, 2008 Spatial data (i.e. locations) should be stored in .map files so that they can be edited using a map editor. Link to comment
robhol Posted June 15, 2008 Author Share Posted June 15, 2008 EAI; that wouldn't really suit this script since it's designed to run independent of gamemodes and maps. Link to comment
DutchCaffeine Posted July 13, 2008 Share Posted July 13, 2008 Spatial data (i.e. locations) should be stored in .map files so that they can be edited using a map editor. Maybe you have forgeted it, the map editor is not availible. So why specially in .map files, i store all my positions in an table. Tables are faster then loading from a xml files (inclusive .map files) And i don't use the map editor for example spawn positions, vehicle's, moving objects, objects hell eveything. Why not: You can't use the objects and can't do something with them, you can't set in a map file in what dimision the object will be or the pickup. You CAN'T do that. (for my knows) So you can better store it in a costum xml file, and you can load it and put them directly in the dimision you want! Or just build them in to an table (tables are faster then loading from xml, put the xml data into an array). Even loading from an xml uses much memory usage! Link to comment
Gamesnert Posted July 14, 2008 Share Posted July 14, 2008 XML is versatile, all the things you told actually ARE possible... Read this topic: http://development.mtasa.com/index.php? ... lementByID Dimension can be set with normal scripting functions and the help of the link above. About the custom XML, I quite agree because you can put in any argument you want. But it actually also is possible with a normal .map file. And what's the problem with that? In the resourcestart you just load all of the XML data and store it in tables. Link to comment
DutchCaffeine Posted July 14, 2008 Share Posted July 14, 2008 It is a nice function getElementByID but if i need a police vehicle i need to count every tag. Link to comment
Gamesnert Posted July 14, 2008 Share Posted July 14, 2008 The while loop above should help with it. Then you make the police vehicle ID's like "police1","police2" etc and then you use the while loop to read them all at a time. Link to comment
DutchCaffeine Posted July 14, 2008 Share Posted July 14, 2008 jep that is the solution for it 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