Zorgman Posted May 26, 2020 Share Posted May 26, 2020 How can I save script generated objects to a .map file? Link to comment
Moderators Patrick Posted May 26, 2020 Moderators Share Posted May 26, 2020 (edited) Loop trough all objects, get details and write it to a file, like any .map editor file. You can check the syntax in an existing .map file. Something like that -- CLIENT SIDE local objects = getElementsByType("object") local file = fileCreate("clonedmap.map") fileWrite(file, "<map>\n") for i = 1, #objects do local obj = objects[i] local x, y, z = getElementPosition(obj) local rx, ry, rz = getElementRotation(obj) row = ('\t<object id="something (%d)" breakable="%s" interior="%d" collisions="%s" alpha="%d" model="%d" doublesided="%s" scale="%d" posX="%f" posY="%f" posZ="%f" rotX="%f" rotY="%f" rotZ="%f"></object>\n'):format( i, tostring(isObjectBreakable(obj)), getElementInterior(obj), tostring(getElementCollisionsEnabled(obj)), getElementAlpha(obj), getElementModel(obj), tostring(isElementDoubleSided(obj)), getObjectScale(obj), x, y, z, rx, ry, rz ) fileWrite(file, row) end fileWrite(file, "</map>") fileClose(file) Save file to mta_folder/mods/deathmatch/resources/YOUR_RESOURCE_NAME/clonedmap.map Edited May 26, 2020 by Patrick 1 1 Link to comment
Moderators IIYAMA Posted May 26, 2020 Moderators Share Posted May 26, 2020 (edited) An alternative is to save an specific part of the element tree. Pick the method that works best for you. local file = xmlCreateFile ("map.xml", "map") local baseElement = createElement("temporary") --[[ ]] local element = -- createObject, createVehicle, etc. etc, setElementParent(element, baseElement) --[[ ]] saveMapData ( file, baseElement ) xmlSaveFile ( file ) xmlUnloadFile ( file ) destroyElement(baseElement) -- destroy every element, parent as well as the children thanks to propagation Pro's Flexibility, you do not have to write specific code for other elements. Cons: Serverside only No custom properties with special characters, for example : notations and code comments on the fly. All properties are copied, you do not have fully control which ones are saved. Edited May 26, 2020 by IIYAMA 1 1 Link to comment
Moderators Patrick Posted May 26, 2020 Moderators Share Posted May 26, 2020 5 minutes ago, IIYAMA said: An alternative is to save an specific part of the element tree. saveMapData... thats new for me 1 Link to comment
Zorgman Posted May 27, 2020 Author Share Posted May 27, 2020 I didn't knew about saveMapData either, this was actually what I was looking for so I tried it first, but it produced an xml file with empty object elements, not sure what i messed up Patrick's solution worked for me, I got my map. Thank you both! 1 Link to comment
Moderators IIYAMA Posted May 27, 2020 Moderators Share Posted May 27, 2020 (edited) 20 hours ago, Zorgman said: not sure what i messed up Patrick's solution worked for me You didn't mess anything up, but it seems the function has been broken somewhere on the versioooon-way. The wiki example didn't work either. local baseElement = createElement("map-dinner") --[[ ]] local element = createObject ( 1337, 5540.6654, 1020.55122, 1240.545, 90, 0, 0 ) setElementParent(element, baseElement) --[[ ]] local file = xmlCreateFile ("map.xml", "map") saveMapData ( file, baseElement, true ) xmlSaveFile ( file ) xmlUnloadFile ( file ) --[[ <map> <object></object> </map> ]] local file = xmlCreateFile("saved.map", "map") if file then saveMapData ( file, getResourceRootElement(getThisResource()), true ) xmlSaveFile ( file ) xmlUnloadFile ( file ) end --[[ <map> <map> <map-dinner> <object></object> </map-dinner> </map> </map> ]] I am going to add a bug report. https://github.com/multitheftauto/mtasa-blue/issues/1473 Edited May 27, 2020 by IIYAMA 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